ValueError: in user code: File "D:\ANACONDA3\lib\site-packages\keras\engine\training.py", line 1160, in train_function * return step_function(self, iterator) File "D:\ANACONDA3\lib\site-packages\keras\engine\training.py", line 1146, in step_function ** outputs = model.distribute_strategy.run(run_step, args=(data,)) File "D:\ANACONDA3\lib\site-packages\keras\engine\training.py", line 1135, in run_step ** outputs = model.train_step(data) File "D:\ANACONDA3\lib\site-packages\keras\engine\training.py", line 994, in train_step loss = self.compute_loss(x, y, y_pred, sample_weight) File "D:\ANACONDA3\lib\site-packages\keras\engine\training.py", line 1052, in compute_loss return self.compiled_loss( File "D:\ANACONDA3\lib\site-packages\keras\engine\compile_utils.py", line 265, in __call__ loss_value = loss_obj(y_t, y_p, sample_weight=sw) File "D:\ANACONDA3\lib\site-packages\keras\losses.py", line 152, in __call__ losses = call_fn(y_true, y_pred) File "D:\ANACONDA3\lib\site-packages\keras\losses.py", line 272, in call ** return ag_fn(y_true, y_pred, **self._fn_kwargs) File "D:\ANACONDA3\lib\site-packages\keras\losses.py", line 1990, in categorical_crossentropy return backend.categorical_crossentropy( File "D:\ANACONDA3\lib\site-packages\keras\backend.py", line 5529, in categorical_crossentropy target.shape.assert_is_compatible_with(output.shape) ValueError: Shapes (None, 1) and (None, 62) are incompatible
时间: 2023-07-21 21:00:57 浏览: 311
keras报错:ValueError: Cannot create group in read only mode
5星 · 资源好评率100%
这个错误是由于模型的输出形状与目标数据的形状不匹配导致的。
根据错误信息,模型的输出形状是(None, 1),而目标数据的形状是(None, 62)。这表示模型输出的每个样本都是一个形状为(None, 1)的张量,而目标数据的每个样本都是一个形状为(None, 62)的张量。
你可以尝试调整模型的输出层,使其输出与目标数据的形状匹配。或者,你可以修改目标数据的形状,使其与模型的输出形状匹配。这取决于你的具体需求和数据。
如果你需要进一步的帮助,请提供更多关于你的模型和数据的信息,我将尽力提供更准确的解决方案。
阅读全文