Input 0 of layer "dense" is incompatible with the layer: expected min_ndim=2, found ndim=1. Full shape received: (None,)

85 Views Asked by At
/tmp/ipykernel_28/859774433.py:11: UserWarning: `Model.fit_generator` is deprecated and will be removed in a future version. Please use `Model.fit`, which supports generators.
  history = model.fit_generator(generator, epochs =1, steps_per_epoch= steps, verbose=1)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[45], line 11
      9 for i in range(epochs):
     10     generator = data_generator(captions_train,feat_train, tokenizer, max_length,batch_size)
---> 11     history = model.fit_generator(generator, epochs =1, steps_per_epoch= steps, verbose=1)
     12     #j = j+1
     13     #model.save("model21/model_" + str(j) + ".h5")

File /opt/conda/lib/python3.10/site-packages/keras/engine/training.py:2636, in Model.fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
   2624 """Fits the model on data yielded batch-by-batch by a Python generator.
   2625 
   2626 DEPRECATED:
   2627   `Model.fit` now supports generators, so there is no longer any need to
   2628   use this endpoint.
   2629 """
   2630 warnings.warn(
   2631     "`Model.fit_generator` is deprecated and "
   2632     "will be removed in a future version. "
   2633     "Please use `Model.fit`, which supports generators.",
   2634     stacklevel=2,
   2635 )
-> 2636 return self.fit(
   2637     generator,
   2638     steps_per_epoch=steps_per_epoch,
   2639     epochs=epochs,
   2640     verbose=verbose,
   2641     callbacks=callbacks,
   2642     validation_data=validation_data,
   2643     validation_steps=validation_steps,
   2644     validation_freq=validation_freq,
   2645     class_weight=class_weight,
   2646     max_queue_size=max_queue_size,
   2647     workers=workers,
   2648     use_multiprocessing=use_multiprocessing,
   2649     shuffle=shuffle,
   2650     initial_epoch=initial_epoch,
   2651 )

File /opt/conda/lib/python3.10/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
     67     filtered_tb = _process_traceback_frames(e.__traceback__)
     68     # To get the full stack trace, call:
     69     # `tf.debugging.disable_traceback_filtering()`
---> 70     raise e.with_traceback(filtered_tb) from None
     71 finally:
     72     del filtered_tb

File /tmp/__autograph_generated_filera9gpu8a.py:15, in outer_factory.<locals>.inner_factory.<locals>.tf__train_function(iterator)
     13 try:
     14     do_return = True
---> 15     retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
     16 except:
     17     do_return = False

ValueError: in user code:

    File "/opt/conda/lib/python3.10/site-packages/keras/engine/training.py", line 1284, in train_function  *
        return step_function(self, iterator)
    File "/opt/conda/lib/python3.10/site-packages/keras/engine/training.py", line 1268, in step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "/opt/conda/lib/python3.10/site-packages/keras/engine/training.py", line 1249, in run_step  **
        outputs = model.train_step(data)
    File "/opt/conda/lib/python3.10/site-packages/keras/engine/training.py", line 1050, in train_step
        y_pred = self(x, training=True)
    File "/opt/conda/lib/python3.10/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler
        raise e.with_traceback(filtered_tb) from None
    File "/opt/conda/lib/python3.10/site-packages/keras/engine/input_spec.py", line 253, in assert_input_compatibility
        raise ValueError(

    ValueError: Exception encountered when calling layer 'model_9' (type Functional).
    
    Input 0 of layer "dense_27" is incompatible with the layer: expected min_ndim=2, found ndim=1. Full shape received: (None,)
    
    Call arguments received by layer 'model_9' (type Functional):
      • inputs=('tf.Tensor(shape=(None,), dtype=float32)', 'tf.Tensor(shape=(None,), dtype=float32)')
      • training=True
      • mask=None

# encoder model

# image feature layers

inputs1 = Input(shape=(1000,))

fe1 = Dropout(0.4)(inputs1)

fe2 = Dense(256, activation='relu')(fe1)

# sequence feature layers

inputs2 = Input(shape=(max_length,))

se1 = Embedding(vocab_size, 256, mask_zero=True)(inputs2)

se2 = Dropout(0.4)(se1)

se3 = LSTM(256)(se2)

# decoder model

decoder1 = add([fe2, se3])

decoder2 = Dense(256, activation='relu')(decoder1)

outputs = Dense(vocab_size, activation='softmax')(decoder2)

model1 = Model(inputs=[inputs1, inputs2], outputs=outputs)

model1.compile(loss='categorical_crossentropy', optimizer='adam')

# plot the model

plot_model(model1, show_shapes=True)

0

There are 0 best solutions below