DeeperCS / fcn

2 stars 0 forks source link

Is it possible to modify create_lmdb with image folder and txt path? #1

Open John1231983 opened 7 years ago

John1231983 commented 7 years ago

Hello. thank you for sharing script to generate the lmdb file. I want to use it to generate VOC2012 dataset which contains the folder

Annotations  JPEGImages  SegmentationClass     SegmentationObject
ImageSets    SegmentationClassAug train.txt val.txt

where SegmentationClassAug is ground-truth label of both training and testing images, the JPEGImages includes the original images and train.txt, test.txt are image path

In your script, it requires copy training and testing image to separate folders as

inputs_data_train = sorted(glob.glob("/pascal/VOCdevkit/VOC2012/JPEGImages/Train/*.jpg"))
inputs_data_valid = sorted(glob.glob("/pascal/VOCdevkit/VOC2012/JPEGImages/Test/*.jpg"))
inputs_label = sorted(glob.glob("/pascal/VOCdevkit/VOC2012/SegmentationClassAug/*.png"))

Is it possible to changing the python code to work with txt input path file as the /caffe/examples/imagenet/create_imagenet.sh

DeeperCS commented 7 years ago

@John1231983 Thank you for your interests with these scripts. To work with txt input path file, there need some small changes. I wrote some codes as an example and hope it will help you.

"""
Assuming the contents of 'train.txt ' are something like the follows:

2   JPEGImages/2009_003636.jpg  SegmentationClass/2009_003636.png
8   JPEGImages/2009_000080.jpg  SegmentationClass/2009_000080.png
16  JPEGImages/2008_001028.jpg  SegmentationClass/2008_001028.png

The code below could be an alternative way to read the file names:
"""

# Path of your train.txt
trainLst = 'pascal/VOCdevkit/VOC2012/train.txt'
with open(trainLst, 'rb') as f:
    lst_file = f.readlines()

inputs_data_train = []
inputs_label_train = []
for item in lst_file:
    item_splited = item.split('\t')
    inputs_data_train.append(item_splited[1])
    inputs_label_train.append(item_splited[2])
John1231983 commented 7 years ago

Thanks DeeperCS.