keras-rcnn icon indicating copy to clipboard operation
keras-rcnn copied to clipboard

Loading external Data to train the model

Open fenilsuchak opened this issue 7 years ago • 3 comments

There is no information regarding how to load external data apart from the available keras_rcnn.datasets. Suppose I have input_images , target_images , and np.array of bounding boxes for each image. How would I load it into the model? Probably should be added to the readme file too.

fenilsuchak avatar Feb 17 '18 17:02 fenilsuchak

Yes, sorry we are behind on that. Take a look below and let me know if that helps.

External Data

The data is made up of a list of dictionaries corresponding to images.

  • For each image, add a dictionary with keys 'image', 'objects'
    • 'image' is a dictionary, which contains keys 'checksum', 'pathname', and 'shape'
      • 'checksum' is the md5 checksum of the image
      • 'pathname' is the pathname of the image, put in full pathname
      • 'shape' is a dictionary with keys 'r', 'c', and 'channels'
        • 'r': number of rows
        • 'c': number of columns
        • 'channels': number of channels
    • 'objects' is a list of dictionaries, where each dictionary has keys 'bounding_box', 'category'
      • 'bounding_box' is a dictionary with keys 'minimum' and 'maximum'
        • 'minimum': dictionary with keys 'r' and 'c'
          • 'r': smallest bounding box row
          • 'c': smallest bounding box column
        • 'maximum': dictionary with keys 'r' and 'c'
          • 'r': largest bounding box row
          • 'c': largest bounding box column
      • 'category' is a string denoting the class name

Suppose this data is save in a file called training.json. To load data,

import json

with open('training.json') as f:
    d = json.load(f)

jhung0 avatar Mar 01 '18 15:03 jhung0

I developed this code so you can load DSB 2018 data. https://github.com/mravendi/keras-rcnn/blob/master/keras_rcnn/datasets/dsb2018.py

simply use dicts=load_data(path2data,data_group)

where path2data is the location of DSB 2018 data on your computer data_group can be either "stage1_train" or "stage1_test"

it will return a list of dictionaries in the format that this repo likes.

mave5 avatar Mar 04 '18 06:03 mave5

Thanks @mravendi ! Your code works with the dsb 2018 dataset on my local machine.

Just a warning for others working with this dataset, you'll most likely receive an error when running this because the generator queries the image file itself (e.g. asdlfkj129.png) and you'll need to modify the _get_batches_of_transformed_samples method within the DictionaryIterator class to ignore the alpha channel. Something like: image=image[:,:,:3] before all the transformations.

There's probably a better way of doing this, such as linking the color_mode argument with the number of channels that _get_batches_of_transformed_samples number of channels OR using the number of channels specified in the dictionary. However, I'm not a CV expert and thus not sure about the best design choice.

vz415 avatar Mar 06 '18 23:03 vz415