win10下利用caffe製作LMDB數據集(ubuntu同理)

這篇博客默認你已經安裝了caffe,因爲製作lmdb數據集時需要用到caffe生成的函數。

參考博文是:https://blog.csdn.net/Rayue_/article/details/81080359 後面製作數據集的部分。

 

0、準備階段

和博文一樣,從micro/caffe中複製data文件夾和scripts文件夾到你的目錄下,然後將你準備好的數據文件夾VOCdevkit放進data目錄下,再將data/VOCdevkit/VOC2018文件夾更名爲VOC0712(因爲我之前習慣用VOC2018這個名字,這裏爲了後面方便),現在你的data和data/VOCdevkit目錄如下:

 

1、LMDB第一步

修改data/VOC0712/create_list.sh,代碼中的1,2,3,...,6是我所修改的六個位置,瞭解含義對照修改就行

#!/bin/bash

#1
HOME=D:/2020software/Dnn/detection/caffe-ssd-win10/caffe_ssd_gpu/caffe-ssd-windows

root_dir=$HOME/data/VOCdevkit/

sub_dir=ImageSets/Main
#2   bash_dir is pwd of (.sh)
bash_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

for dataset in trainval test
do
  dst_file=$bash_dir/$dataset.txt
  if [ -f $dst_file ]
  then
    rm -f $dst_file
  fi
  
  #3
  for name in VOC0712
  do
    if [[ $dataset == "test" && $name == "VOC2012" ]]
    then
      continue
    fi
    echo "Create list for $name $dataset..."
    dataset_file=$root_dir/$name/$sub_dir/$dataset.txt

    img_file=$bash_dir/$dataset"_img.txt"
    cp $dataset_file $img_file
	
	#4   JPEGImages, don not change
    sed -i "s/^/$name\/JPEGImages\//g" $img_file
    sed -i "s/$/.jpg/g" $img_file

    label_file=$bash_dir/$dataset"_label.txt"
    cp $dataset_file $label_file
    sed -i "s/^/$name\/Annotations\//g" $label_file
    sed -i "s/$/.xml/g" $label_file

    paste -d' ' $img_file $label_file >> $dst_file

    rm -f $label_file
    rm -f $img_file
  done

  # Generate image name and size infomation.
  if [ $dataset == "test" ]
  then
    #5   your path of get_image_size.exe
    $bash_dir/../../build/install/bin/get_image_size $root_dir $dst_file $bash_dir/$dataset"_name_size.txt"
  fi

  # Shuffle trainval file.
  if [ $dataset == "trainval" ]
  then
    rand_file=$dst_file.random
    cat $dst_file | perl -MList::Util=shuffle -e 'print shuffle(<STDIN>);' > $rand_file
    mv $rand_file $dst_file
  fi
done

#6
read -p "Press any key to continue." var

然後雙擊create_list.sh(win10要求安裝git才能直接雙擊),會在./data/VOC2018/下生成這樣三個文件,說明成功了,如下:

 

2、LMDB第二步

(1)修改\data\VOC0712\labelmap_voc.prototxt標籤文件內容,保留0號背景標籤,其餘的按照其格式根據樣本分類數目或修改或添加刪除

 

(2)修改data/VOC0712/create_data.sh,代碼中的1,2,3是我所修改的四個位置,瞭解含義對照修改就行

#!/bin/bash

cur_dir=$(cd $( dirname ${BASH_SOURCE[0]} ) && pwd )
root_dir=$cur_dir/../..

cd $root_dir

redo=1

#1
data_root_dir="$root_dir/data/VOCdevkit"
dataset_name="VOC0712"
mapfile="$root_dir/data/$dataset_name/labelmap_voc.prototxt"
anno_type="detection"
db="lmdb"
min_dim=0
max_dim=0
width=0
height=0

extra_cmd="--encode-type=jpg --encoded"
if [ $redo ]
then
  extra_cmd="$extra_cmd --redo"
fi
for subset in test trainval
do
  #2 delete something, and the python must be python2
  python $root_dir/scripts/create_annoset.py --anno-type=$anno_type --label-map-file=$mapfile --min-dim=$min_dim --max-dim=$max_dim --resize-width=$width --resize-height=$height --check-label $extra_cmd $data_root_dir $root_dir/data/$dataset_name/$subset.txt $data_root_dir/$dataset_name/$db/$dataset_name"_"$subset"_"$db
done

#3
read -p "Press any key to continue." Var

 

(3)修改scripts下的create_annoset.py文件,找到2處{}/Build/x64/Release/convert_annoset,修改爲{}/build/install/bin/convert_annoset(改成你自己的執行文件convert_annoset的位置)

 

最後雙擊create_data.sh,會在data\VOCdevkit\VOC0712\下生成lmdb文件夾,裏面有VOC0712_trainval_lmdb和VOC0712_test_lmdb,並且兩個文件夾下都有data.mdb和lock.mdb,說明成功了,簡略圖如下:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章