warmspringwinds / tf-image-segmentation

Image Segmentation framework based on Tensorflow and TF-Slim library
MIT License
549 stars 186 forks source link

convert_pascal_voc_to_tfrecords error #29

Open fmthoker opened 7 years ago

fmthoker commented 7 years ago

While running the notebook i get the following error.

IOError Traceback (most recent call last)

in () 24 25 write_image_annotation_pairs_to_tfrecord(filename_pairs=overall_train_image_annotation_filename_pairs, ---> 26 tfrecords_filename='pascal_augmented_train.tfrecords') /home/fmthoker/bonn/lab_vision_systems/slim/models/tf-image-segmentation/tf_image_segmentation/utils/tf_records.py in write_image_annotation_pairs_to_tfrecord(filename_pairs, tfrecords_filename) 36 37 img = np.array(Image.open(img_path)) ---> 38 annotation = np.array(Image.open(annotation_path)) 39 # Unomment this one when working with surgical data 40 # annotation = annotation[:, :, 0] /home/fmthoker/bonn/lab_vision_systems/tensorflow/local/lib/python2.7/site-packages/PIL/Image.pyc in open(fp, mode) 2408 2409 if filename: -> 2410 fp = builtins.open(filename, "rb") 2411 exclusive_fp = True 2412 IOError: [Errno 2] No such file or directory: './benchmark_RELEASE/dataset/cls_png/2008_007573.png Note: i have downloaded both pascal dataset and benchmark.
hanskrupakar commented 6 years ago

Hey, I got a similar error. I didn't know what the problem was so I simply circumvented it by ensuring all image and annotation filenames exist by adding this condition at Line 36 in utils/tf_records.py

for img_path, annotation_path in filename_pairs:
        if os.path.exists(img_path) and os.path.exists(annotation_path):
                img = np.array(Image.open(img_path))
                annotation = np.array(Image.open(annotation_path))
                # Unomment this one when working with surgical data
                # annotation = annotation[:, :, 0]

                # The reason to store image sizes was demonstrated
                # in the previous example -- we have to know sizes
                # of images to later read raw serialized string,
                # convert to 1d array and convert to respective
                # shape that image used to have.
                height = img.shape[0]
                width = img.shape[1]

                img_raw = img.tostring()
                annotation_raw = annotation.tostring()

                example = tf.train.Example(features=tf.train.Features(feature={
                    'height': _int64_feature(height),
                    'width': _int64_feature(width),
                    'image_raw': _bytes_feature(img_raw),
                    'mask_raw': _bytes_feature(annotation_raw)}))

                writer.write(example.SerializeToString())

    writer.close()

`

JosephKJ commented 6 years ago

You need to convert the .mat annotations into images, before converting to tf_records

You can do this by:

from tf_image_segmentation.utils.pascal_voc import convert_pascal_berkeley_augmented_mat_annotations_to_png

pascal_berkeley_root = '/home/joseph/Dataset/BerkleySegmentationData/benchmark_RELEASE'
convert_pascal_berkeley_augmented_mat_annotations_to_png(pascal_berkeley_root)