简体   繁体   中英

How do I solve deep learning errors?

An attempt was made to learn the model using preprocessed data, but an error occurred. I can't find the error because I'm still a high school student. What part should I modify to make the model learn?

code:

print(final_train_x.shape, final_train_y.shape)
((894, 1089), (894, 120))

import tensorflow as tf 

adam = tf.optimizers.Adam(lr=0.1)


model.compile(loss = 'categorical_crossentropy', optimizer = adam,
              metrics =['accuracy'])
from keras.callbacks import EarlyStopping

es = EarlyStopping(monitor = 'val_loss',
                  min_delta = 0.001, 
                  patience = 10, 
                  verbose = 1
                  )
history = model.fit(final_train_x, final_train_y, epochs=10, batch_size = 16,
                   validation_split = 0.2,
                   verbose = 1,
                   callbacks = [es])

ERROR:

Epoch 1/10
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-322-b1827eb5e265> in <module>
     18                    validation_split = 0.2,
     19                    verbose = 1,
---> 20                    callbacks = [es])

ValueError: in user code:

    File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1021, in train_function  *
        return step_function(self, iterator)
    File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1010, in step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 1000, in run_step  **
        outputs = model.train_step(data)
    File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 860, in train_step
        loss = self.compute_loss(x, y, y_pred, sample_weight)
    File "/usr/local/lib/python3.7/dist-packages/keras/engine/training.py", line 919, in compute_loss
        y, y_pred, sample_weight, regularization_losses=self.losses)
    File "/usr/local/lib/python3.7/dist-packages/keras/engine/compile_utils.py", line 201, in __call__
        loss_value = loss_obj(y_t, y_p, sample_weight=sw)
    File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 141, in __call__
        losses = call_fn(y_true, y_pred)
    File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 245, in call  **
        return ag_fn(y_true, y_pred, **self._fn_kwargs)
    File "/usr/local/lib/python3.7/dist-packages/keras/losses.py", line 1790, in categorical_crossentropy
        y_true, y_pred, from_logits=from_logits, axis=axis)
    File "/usr/local/lib/python3.7/dist-packages/keras/backend.py", line 5083, in categorical_crossentropy
        target.shape.assert_is_compatible_with(output.shape)

    ValueError: Shapes (None, 120) and (None, 895) are incompatible

How can I learn a model without errors?

Make sure that your model output is 120 , for example the final layer is Dense(120, activation = "softmax") . try to share the model.summary()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM