有栖川奈 2023-02-19 16:41 采纳率: 66.7%
浏览 24
已结题

PYTHON笑脸检测模型训练失败

模型无法训练


history = model.fit(
      train_generator,
      steps_per_epoch=100,
      epochs=30,
      validation_data=validation_generator,
      validation_steps=50)

报错结果如下:

Traceback (most recent call last):
  File "C:\Users\529\2022\demo2022.9.1\Utils\Algorithm\process.py", line 38, in <module>
    history = model.fit(
  File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\tensorflow\python\eager\execute.py", line 54, in quick_execute
    tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.InvalidArgumentError: Graph execution error:

Detected at node 'binary_crossentropy/mul_1' defined at (most recent call last):
    File "C:\Users\529\2022\demo2022.9.1\Utils\Algorithm\process.py", line 38, in <module>
      history = model.fit(
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\utils\traceback_utils.py", line 65, in error_handler
      return fn(*args, **kwargs)
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\engine\training.py", line 1564, in fit
      tmp_logs = self.train_function(iterator)
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\engine\training.py", line 1160, in train_function
      return step_function(self, iterator)
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\engine\training.py", line 1146, in step_function
      outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\engine\training.py", line 1135, in run_step
      outputs = model.train_step(data)
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\engine\training.py", line 994, in train_step
      loss = self.compute_loss(x, y, y_pred, sample_weight)
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\engine\training.py", line 1052, in compute_loss
      return self.compiled_loss(
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\engine\compile_utils.py", line 265, in __call__
      loss_value = loss_obj(y_t, y_p, sample_weight=sw)
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\losses.py", line 152, in __call__
      losses = call_fn(y_true, y_pred)
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\losses.py", line 272, in call
      return ag_fn(y_true, y_pred, **self._fn_kwargs)
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\losses.py", line 2162, in binary_crossentropy
      backend.binary_crossentropy(y_true, y_pred, from_logits=from_logits),
    File "C:\Users\529\anaconda3\envs\camera\lib\site-packages\keras\backend.py", line 5686, in binary_crossentropy
      bce += (1 - target) * tf.math.log(1 - output + epsilon())
Node: 'binary_crossentropy/mul_1'
Incompatible shapes: [20,150,150,3] vs. [20]
     [[{{node binary_crossentropy/mul_1}}]] [Op:__inference_train_function_258]
2023-02-19 16:32:31.817841: W tensorflow/core/kernels/data/generator_dataset_op.cc:108] Error occurred when finalizing GeneratorDataset iterator: FAILED_PRECONDITION: Python interpreter state is not initialized. The process may be terminated.
     [[{{node PyFunc}}]]

Process finished with exit code 1


  • 写回答

1条回答 默认 最新

  • CodeBytes 2023-02-19 16:51
    关注

    该回答引用ChatGPT

    根据错误信息显示,错误出现在 binary_crossentropy/mul_1 这个节点上,可能是因为输出的张量和期望的张量形状不匹配。

    错误信息中还提到了张量的形状信息,输出的张量形状是 [20, 150, 150, 3],而期望的张量形状是 [20]。根据这个信息,可能是因为你的输出张量和期望的张量形状不匹配,导致出现了这个错误。

    可能的原因包括:

    模型定义中的输出层和标签形状不匹配。
    数据集中的标签形状不正确。
    可以检查一下模型的定义,看一下模型输出层的形状是否正确,并确保数据集中标签的形状与模型输出层的形状一致。另外,还可以检查一下数据集是否正确地生成,数据是否预处理正确等问题。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 2月28日
  • 已采纳回答 2月20日
  • 创建了问题 2月19日

悬赏问题

  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的