模型无法训练
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