Skip to content

Error when checking target: expected dense_1 to have 4 dimensions, but got array with shape (128, 10) #3

@trittsv

Description

@trittsv

[Required] Your device (RaspberryPi3, LaptopPC, or other device name):
Laptop (MacBook Pro 15" Early 2013
[Required] Your device's CPU architecture (armv7l, x86_64, or other architecture name):
x86_64
[Required] Your OS (Raspbian, Ubuntu1604, or other os name):
MacOS 10.14.6
[Required] Details of the work you did before the problem occurred:
Clone repository, and execute from_preprocessing_to_training.ipynb in jupiter-notebook
[Required] Error message:

Total params: 719,034
Trainable params: 549,098
Non-trainable params: 169,936
__________________________________________________________________________________________________
x_target is 6000 samples
x_ref is 6000 samples
training...
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-bdce5d7b4ebd> in <module>
    117     return model_t
    118 
--> 119 model = train(X_train_s, X_ref, y_ref, 5)

<ipython-input-3-bdce5d7b4ebd> in train(x_target, x_ref, y_ref, epoch_num)
     94             #reference data
     95             #Get loss while learning
---> 96             ld.append(model_r.train_on_batch(batch_ref, batch_y))
     97 
     98         loss.append(np.mean(ld))

/usr/local/lib/python3.6/site-packages/keras/engine/training.py in train_on_batch(self, x, y, sample_weight, class_weight)
   1209             x, y,
   1210             sample_weight=sample_weight,
-> 1211             class_weight=class_weight)
   1212         if self._uses_dynamic_learning_phase():
   1213             ins = x + y + sample_weights + [1.]

/usr/local/lib/python3.6/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)
    787                 feed_output_shapes,
    788                 check_batch_axis=False,  # Don't enforce the batch size.
--> 789                 exception_prefix='target')
    790 
    791             # Generate sample-wise weight values given the `sample_weight` and

/usr/local/lib/python3.6/site-packages/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
    126                         ': expected ' + names[i] + ' to have ' +
    127                         str(len(shape)) + ' dimensions, but got array '
--> 128                         'with shape ' + str(data_shape))
    129                 if not check_batch_axis:
    130                     data_shape = data_shape[1:]

ValueError: Error when checking target: expected dense_1 to have 4 dimensions, but got array with shape (128, 10)

[Required] Overview of problems and questions:
How to solve this error? I didn't changed anything in the code, i just ran the example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions