Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
trittsv opened this issue Sep 4, 2019 · 2 comments

Comments

@trittsv
Copy link

trittsv commented Sep 4, 2019

[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.

@PINTO0309
Copy link
Owner

@trittsv
Can you tell me the version of Keras?

@shinmura0
Copy link
Collaborator

shinmura0 commented Sep 10, 2019

@trittsv

Modifications are required for MobileNet V2.

include_top=True

After all, MobileNet V2 is as follows.

mobile = MobileNetV2(include_top=True, input_shape=input_shape, alpha=alpha,  weights='imagenet')

Commit content a96658e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants