Multi output network generator
See original GitHub issuemodel.fit support multi input/output network, but if data-set is large enough and one have to use model.fit_generator, its complicated to generate tuple for such case, is there any plan to make it more simpler like model.fit.
I have network that take one input and produce two outputs, i created separate
generator for each, but i am not able to run network on this. my input should be of form x, [y1, y2].
i think i need to extend generator for such case ?
image_datagen = ImageDataGenerator(
rotation_range=15.,
width_shift_range=0.2,
height_shift_range=0.2,
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
vertical_flip = True,
fill_mode='nearest')
mask_datagen = ImageDataGenerator(
rotation_range=15.,
width_shift_range=0.2,
height_shift_range=0.2,
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
vertical_flip = True,
fill_mode='nearest')
shading_datagen = ImageDataGenerator(
rotation_range=15.,
width_shift_range=0.2,
height_shift_range=0.2,
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
vertical_flip = True,
fill_mode='nearest')
test_datagen = ImageDataGenerator(rescale=1./255)
seed_validation = 1
validation_image_generator = test_datagen.flow_from_directory(
os.path.join(gen_path,'clean/test'),
target_size=(128, 256),class_mode=None,classes=None,
batch_size=20,seed=seed_validation)
validation_mask_generator = test_datagen.flow_from_directory(
os.path.join(gen_path,'albedo/test'),
target_size=(128, 256),class_mode=None,classes=None,
batch_size=20,seed=seed_validation)
validation_shading_generator = test_datagen.flow_from_directory(
os.path.join(gen_path,'gray_shading/test'),
target_size=(128, 256),class_mode=None,classes=None,
batch_size=20,seed=seed_validation)
#testDataGen = ImageDataGenerator(rescale=1./255)
seed = 5
#image_datagen.fit(image_datagen, augment=True, seed=seed)
#mask_datagen.fit(mask_datagen, augment=True, seed=seed)
image_generator = image_datagen.flow_from_directory(
os.path.join(gen_path,'clean/train'),
class_mode=None,target_size=(128,256),batch_size=20,classes=None,
seed=seed)
mask_generator = mask_datagen.flow_from_directory(
os.path.join(gen_path,'albedo/train'),
class_mode=None,target_size=(128,256),batch_size=20,classes = None,
seed=seed)
shading_generator = shading_datagen.flow_from_directory(
os.path.join(gen_path,'gray_shading/train'),
class_mode=None,target_size=(128,256),batch_size=20,classes = None,
seed=seed)
train_generator = itertools.izip(image_generator, mask_generator, shading_generator)
Please make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on StackOverflow or join the Keras Slack channel and ask there instead of filing a GitHub issue.
Thank you!
-
Check that you are up-to-date with the master branch of Keras. You can update with: pip install git+git://github.com/fchollet/keras.git --upgrade --no-deps
-
If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.
-
If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with: pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps
-
Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (3 by maintainers)
Don’t worry, I didn’t include a doc string. It’s just a list of the generators. Each generator must return
(x, y)
. Therefore if you have:This was just a skeleton of a possible implementation. For example, if your generators only return one element you could just:
Or vary the code accordingly.
I like that trick. In my experience, writing a custom generator that yields both inputs is easier to manage than zipping two generators. It is especially evident when managing complex augmentation and sampling methods.