1

I am training a Neural Network (U-net) in Keras with two inputs and one output. The first input is an Array (image) and the second one a single value.

input_img = Input(input_size, name='input_image')
input_depth = Input((1,), name='input_depth')
...
depth1 = RepeatVector(64)(input_depth)
depth1 = Reshape((8,8, 1))(depth1)
pool4 = concatenate([pool4, depth1], -1)
....
Model([input_img, input_depth], conv10)

I have built the following Data Generator to feed the model:

def get_image_depth_generator_on_memory_v2(images, masks, depths, batch_size, data_gen_args):
    seed = 123
    image_datagen = ImageDataGenerator(**data_gen_args)
    mask_datagen = ImageDataGenerator(**data_gen_args)  

    image_f = image_datagen.flow(images, depths, batch_size=batch_size, shuffle=True, seed=seed)
    mask_f = mask_datagen.flow(masks, batch_size=batch_size, shuffle=True, seed=seed)

    while True:
        image_n = image_f.next()
        mask_n = mask_f.next()

        yield [image_n[0], image_n[1]], mask_n

The training works when I feed the model without the generator:

model.fit([train_images, train_depths], train_masks)

But it doesn't work when I use the generator to feed the model:

model.fit_generator(generator = get_image_depth_generator_on_memory_v2(
            train_images, train_masks, train_depths,
            batch_size=512, data_gen_args={}), 
            steps_per_epoch=500)

I get the next error:

ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), but instead got the following list of 1 arrays: ...

Any idea about what is going on?

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
asabater
  • 94
  • 1
  • 9
  • 1
    Finally I solved it by updating tensorflow-gpu to the last version, and cuda to the 9.0 version. But I am still not sure that this was the problem – asabater Oct 03 '18 at 11:22

1 Answers1

1

The error is your model.fit line generates 1 output while your model.generate requires 2 outputs so either provide 2 utputs or try concatenating the output to fit in using np.concatenate

Amrit Das
  • 474
  • 1
  • 6
  • 13