matterport / Mask_RCNN

Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow
Other
24.67k stars 11.71k forks source link

ValueError: Could not find a format to read the specified file in single-image mode #2124

Open SomayeKarimpour opened 4 years ago

SomayeKarimpour commented 4 years ago

Hello when I ran the Training I got this error; ValueError: Could not find a format to read the specified file in single-image mode the full error message is :

`ERROR:root:Error processing image {'id': 0, 'source': 'shapes', 'path': '../newdata/valid/jpg\\C10000_0001_Band_10.jpg', 'mask_path': '../newdata/valid/jpg_mask\\C10000_0001_Band_10.jpg', 'width': 224, 'height': 224}
Traceback (most recent call last):
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1604, in data_generator
    use_mini_mask=config.USE_MINI_MASK)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1163, in load_image_gt
    mask, class_ids = dataset.load_mask(image_id)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\mrcnn_dataset.py", line 51, in load_mask
    _mask = skimage.io.imread(_mask_path, 0)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_plugins\imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 265, in imread
    reader = read(uri, format, "i", **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 182, in get_reader
    "Could not find a format to read the specified file in %s mode" % modename
ValueError: Could not find a format to read the specified file in single-image mode
ERROR:root:Error processing image {'id': 3, 'source': 'shapes', 'path': '../newdata/valid/jpg\\C20001_0001_Band_9.jpg', 'mask_path': '../newdata/valid/jpg_mask\\C20001_0001_Band_9.jpg', 'width': 224, 'height': 224}
Traceback (most recent call last):
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1604, in data_generator
    use_mini_mask=config.USE_MINI_MASK)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1163, in load_image_gt
    mask, class_ids = dataset.load_mask(image_id)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\mrcnn_dataset.py", line 51, in load_mask
    _mask = skimage.io.imread(_mask_path, 0)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_plugins\imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 265, in imread
    reader = read(uri, format, "i", **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 182, in get_reader
    "Could not find a format to read the specified file in %s mode" % modename
ValueError: Could not find a format to read the specified file in single-image mode
ERROR:root:Error processing image {'id': 2, 'source': 'shapes', 'path': '../newdata/valid/jpg\\C20001_0001_Band_10.jpg', 'mask_path': '../newdata/valid/jpg_mask\\C20001_0001_Band_10.jpg', 'width': 224, 'height': 224}
Traceback (most recent call last):
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1604, in data_generator
    use_mini_mask=config.USE_MINI_MASK)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1163, in load_image_gt
    mask, class_ids = dataset.load_mask(image_id)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\mrcnn_dataset.py", line 51, in load_mask
    _mask = skimage.io.imread(_mask_path, 0)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_plugins\imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 265, in imread
    reader = read(uri, format, "i", **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 182, in get_reader
    "Could not find a format to read the specified file in %s mode" % modename
ValueError: Could not find a format to read the specified file in single-image mode
ERROR:root:Error processing image {'id': 1, 'source': 'shapes', 'path': '../newdata/valid/jpg\\C10000_0001_Band_9.jpg', 'mask_path': '../newdata/valid/jpg_mask\\C10000_0001_Band_9.jpg', 'width': 224, 'height': 224}
Traceback (most recent call last):
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1604, in data_generator
    use_mini_mask=config.USE_MINI_MASK)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1163, in load_image_gt
    mask, class_ids = dataset.load_mask(image_id)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\mrcnn_dataset.py", line 51, in load_mask
    _mask = skimage.io.imread(_mask_path, 0)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_plugins\imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 265, in imread
    reader = read(uri, format, "i", **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 182, in get_reader
    "Could not find a format to read the specified file in %s mode" % modename
ValueError: Could not find a format to read the specified file in single-image mode
ERROR:root:Error processing image {'id': 1, 'source': 'shapes', 'path': '../newdata/valid/jpg\\C10000_0001_Band_9.jpg', 'mask_path': '../newdata/valid/jpg_mask\\C10000_0001_Band_9.jpg', 'width': 224, 'height': 224}
Traceback (most recent call last):
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1604, in data_generator
    use_mini_mask=config.USE_MINI_MASK)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1163, in load_image_gt
    mask, class_ids = dataset.load_mask(image_id)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\mrcnn_dataset.py", line 51, in load_mask
    _mask = skimage.io.imread(_mask_path, 0)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_plugins\imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 265, in imread
    reader = read(uri, format, "i", **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 182, in get_reader
    "Could not find a format to read the specified file in %s mode" % modename
ValueError: Could not find a format to read the specified file in single-image mode
ERROR:root:Error processing image {'id': 0, 'source': 'shapes', 'path': '../newdata/valid/jpg\\C10000_0001_Band_10.jpg', 'mask_path': '../newdata/valid/jpg_mask\\C10000_0001_Band_10.jpg', 'width': 224, 'height': 224}
Traceback (most recent call last):
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1604, in data_generator
    use_mini_mask=config.USE_MINI_MASK)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1163, in load_image_gt
    mask, class_ids = dataset.load_mask(image_id)
  File "D:\segmentation-unet-maskrcnn\maskRCNN\mrcnn_dataset.py", line 51, in load_mask
    _mask = skimage.io.imread(_mask_path, 0)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_plugins\imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 265, in imread
    reader = read(uri, format, "i", **kwargs)
  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 182, in get_reader
    "Could not find a format to read the specified file in %s mode" % modename
ValueError: Could not find a format to read the specified file in single-image mode
Traceback (most recent call last):

  File "D:\segmentation-unet-maskrcnn\maskRCNN\test_train.py", line 68, in <module>
    layers='all')

  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 2198, in train
    validation_data=next(val_generator),

  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1604, in data_generator
    use_mini_mask=config.USE_MINI_MASK)

  File "D:\segmentation-unet-maskrcnn\maskRCNN\model.py", line 1163, in load_image_gt
    mask, class_ids = dataset.load_mask(image_id)

  File "D:\segmentation-unet-maskrcnn\maskRCNN\mrcnn_dataset.py", line 51, in load_mask
    _mask = skimage.io.imread(_mask_path, 0)

  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)

  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)

  File "C:\Users\S\Anaconda3\lib\site-packages\skimage\io\_plugins\imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))

  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 265, in imread
    reader = read(uri, format, "i", **kwargs)

  File "C:\Users\S\Anaconda3\lib\site-packages\imageio\core\functions.py", line 182, in get_reader
    "Could not find a format to read the specified file in %s mode" % modename
ValueError: Could not find a format to read the specified file in single-image mode`

my dataset include 2 folders. one satellite image chips and another mask images as label , both in jpg format.

my dataset class is:

`class LolDataset(utils.Dataset):

    def load_LOL(self, datasetdir):

        for i in range(inputConfig.NUM_CLASSES):
            self.add_class("shapes", i, inputConfig.CLASS_DICT[i+1] )
        else:
            image_dir = os.path.join(datasetdir, 'jpg')
        print ('image_dir is', image_dir)
        mask_dir = os.path.join(datasetdir, 'jpg_mask')

        image_names = next(os.walk(image_dir))[2]
        for i in range(len(image_names)):
            self.add_image("shapes", image_id = i,
                    path=os.path.join(image_dir, image_names[i]),
                    mask_path=os.path.join(mask_dir, image_names[i]),
                    width = inputConfig.IMAGE_WIDTH,
                    height = inputConfig.IMAGE_HEIGHT)

    def load_image(self, image_id):
        info = self.image_info[image_id]
        image_path = info['path']
        image = cv2.imread(image_path)
        if image.ndim != 3:
            image = skimage.color.gray2rgb(image)
        return image

    def load_mask(self, image_id):
        info = self.image_info[image_id]
        mask_path = info['mask_path']
        valid_mask = []
        for _mask_path in mask_path:
            _mask = skimage.io.imread(_mask_path, 0)
            if _mask.max() == _mask.min():
               pass
            else:
                valid_mask.append(_mask_path)

        count = len(valid_mask)
        mask = np.zeros([info['height'], info['width'], count], 'uint8')
        shapes = []
        for i in range(count):
            img_array = skimage.io.imread(valid_mask[i], 0)
            mask[:, :, i:i+1] = np.expand_dims(img_array, axis=2)

            valid_mask_name=[]
            count_m = len(valid_mask_name)
            fn_img, ext = os.path.splitext(valid_mask[i])
            if fn_img[-18:-17] == 1:
                valid_name = fn_img +"_jo.jpg"
                valid_mask_name.append(valid_name)
            else:
                valid_name = fn_img +"_yonje.jpg"
                valid_mask_name.append(valid_name) 

        for i in range(count_m):    
            if fn_img.split('_')[-1] == 'merged':
                shapes.append(fn_img.split('/')[-1].split('_')[0])
            else:
                shapes.append(fn_img.split('_')[-1])
        # Map class names to class IDs.
        class_ids = np.array([self.class_names.index(s) for s in shapes])

        return mask, class_ids`
Yunus0or1 commented 4 years ago

Did you get any solution ?

naveendev13 commented 4 years ago

My code was : train(model=model) Full error message: Loading Dataset image_0001.jpg image_0002.jpg image_0003.jpg image_0004.jpg image_0005.jpg image_0006.jpg image_0007.jpg image_0008.jpg image_0009.jpg image_0010.jpg image_0011.jpg image_0012.jpg image_0013.jpg image_0014.jpg image_0021.jpg image_0022.jpg

ValueError Traceback (most recent call last)

in ----> 1 train(model=model) in train(model) 3 4 dataset_train = ClothingDataset() ----> 5 dataset_train.load_dataset(DATASET_DIR, "train") 6 dataset_train.prepare() 7 in load_dataset(self, dataset_dir, subset) 31 class_ids.append(c_ids) 32 image_path = os.path.join(dataset_dir, a['filename']) ---> 33 image = skimage.io.imread(image_path) 34 height, width = image.shape[:2] 35 ~\Downloads\New folder (2)\lib\site-packages\skimage\io\_io.py in imread(fname, as_gray, plugin, **plugin_args) 46 47 with file_or_url_context(fname) as fname: ---> 48 img = call_plugin('imread', fname, plugin=plugin, **plugin_args) 49 50 if not hasattr(img, 'ndim'): ~\Downloads\New folder (2)\lib\site-packages\skimage\io\manage_plugins.py in call_plugin(kind, *args, **kwargs) 208 (plugin, kind)) 209 --> 210 return func(*args, **kwargs) 211 212 ~\Downloads\New folder (2)\lib\site-packages\skimage\io\_plugins\imageio_plugin.py in imread(*args, **kwargs) 8 @wraps(imageio_imread) 9 def imread(*args, **kwargs): ---> 10 return np.asarray(imageio_imread(*args, **kwargs)) ~\Downloads\New folder (2)\lib\site-packages\imageio\core\functions.py in imread(uri, format, **kwargs) 263 264 # Get reader and read first --> 265 reader = read(uri, format, "i", **kwargs) 266 with reader: 267 return reader.get_data(0) ~\Downloads\New folder (2)\lib\site-packages\imageio\core\functions.py in get_reader(uri, format, mode, **kwargs) 180 modename = MODENAMES.get(mode, mode) 181 raise ValueError( --> 182 "Could not find a format to read the specified file in %s mode" % modename 183 ) 184 ValueError: Could not find a format to read the specified file in single-image mode