Python 错误 - 在节点“mean_squared_error/Cast”处检测到

Python Error - Detected at node 'mean_squared_error/Cast'

提问人:Sazzad Hissain Khan 提问时间:10/16/2023 最后编辑:Sazzad Hissain Khan 更新时间:10/17/2023 访问量:31

问:

我正在尝试为以下数据帧拟合模型。

ssdf.columns = 数组(['类别', '年龄', '性别', '身高', '重量', '态度.滚动', '姿态.pitch', '姿态.偏航', '重力.x', '重力.y', 'gravity.z', 'rotationRate.x', 'rotationRate.y', 'rotationRate.z', 'userAcceleration.x', 'userAcceleration.y', 'userAcceleration.z'], dtype=对象)

enter image description here

Python 代码:

from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.preprocessing.sequence import TimeseriesGenerator
from sklearn.model_selection import train_test_split

X = ssdf.loc[:, columns]
y = ssdf.loc[:,['category']]
#y = ssdf.loc[:,['gravity.x']]

xn, xt, yn, yt = train_test_split(X, y, test_size=0.20, random_state=101)

n_features = 1
#series = series.reshape((len(X), n_features))
# define generator
n_input = 20
generator = TimeseriesGenerator(xn.values, yn.values, length=n_input, batch_size=1)
# print each sample
#for i in range(len(generator)):
#    x, y = generator[i]
#    print('%s => %s' % (x, y))
    
# define model
model = Sequential()
model.add(LSTM(100, activation='relu', input_shape=(n_input, n_features)))
model.add(Dense(2))
model.compile(optimizer='adam', loss='mse')

model.fit(generator, steps_per_epoch=1, epochs=500, verbose=0)

我在 Kaggle Notebook 中收到以下错误

UnimplementedError 回溯(最近一次调用 last) 单元格 In[28],第 29 行 26 model.add(密集(2)) 27 model.compile(optimizer='adam', loss='mse') ---> 29 model.fit(生成器, steps_per_epoch=1, epochs=500, verbose=0)

文件 /opt/conda/lib/python3.10/site-packages/keras/utils/traceback_utils.py:70, 在filter_traceback..error_handler(*args, **kwargs) 67 filtered_tb = _process_traceback_frames(e.回溯) 68 # 要获取完整的堆栈跟踪,请调用: 69 # ---> 70 从无提高 e.with_traceback(filtered_tb) 71 最后: 72 del filtered_tbtf.debugging.disable_traceback_filtering()

文件 /opt/conda/lib/python3.10/site-packages/tensorflow/python/eager/execute.py:52, 在 quick_execute(op_name、num_outputs、输入、attrs、ctx、name) 50 尝试: 51 ctx.ensure_initialized() ---> 52 个张量 = pywrap_tfe。TFE_Py_Execute(ctx._handle、device_name、op_name、 53 个输入、属性num_outputs) 54 除 core._NotOkStatusException 外,如 e: 如果名称不是 None,则为 55:

UnimplementedError:图形执行错误:

在节点“mean_squared_error/Cast”上检测到(最近 通话最后一次): 文件“/opt/conda/lib/python3.10/runpy.py”,第 196 行,_run_module_as_main 返回_run_code(code, main_globals, None, 文件“/opt/conda/lib/python3.10/runpy.py”,第 86 行,_run_code exec(代码,run_globals) 文件“/opt/conda/lib/python3.10/site-packages/ipykernel_launcher.py”,行 17、在 app.launch_new_instance() 文件“/opt/conda/lib/python3.10/site-packages/traitlets/config/application.py”, 第 1043 行,launch_instance app.start() 文件“/opt/conda/lib/python3.10/site-packages/ipykernel/kernelapp.py”,行 728,开始 self.io_loop.start() 文件“/opt/conda/lib/python3.10/site-packages/tornado/platform/asyncio.py”, 第 195 行,在“开始”中 self.asyncio_loop.run_forever() 文件“/opt/conda/lib/python3.10/asyncio/base_events.py”,第 603 行,run_forever self._run_once() 文件“/opt/conda/lib/python3.10/asyncio/base_events.py”,第 1909 行,_run_once handle._run() 文件“/opt/conda/lib/python3.10/asyncio/events.py”,第 80 行,_run self._context.run(self._callback, *self._args) 文件“/opt/conda/lib/python3.10/site-packages/ipykernel/kernelbase.py”, 第 513 行,dispatch_queue 等待 self.process_one() 文件“/opt/conda/lib/python3.10/site-packages/ipykernel/kernelbase.py”, 502行,process_one 等待调度(*args) 文件“/opt/conda/lib/python3.10/site-packages/ipykernel/kernelbase.py”, 409 行,dispatch_shell 等待结果 文件“/opt/conda/lib/python3.10/site-packages/ipykernel/kernelbase.py”, 729行,execute_request reply_content = 等待reply_content 文件“/opt/conda/lib/python3.10/site-packages/ipykernel/ipkernel.py”,行 422, 在 do_execute res = shell.run_cell( 文件“/opt/conda/lib/python3.10/site-packages/ipykernel/zmqshell.py”,行 540, 在 run_cell 返回 super().run_cell(*args, **kwargs) 文件“/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, 3009 行,run_cell 结果 = self._run_cell( 文件“/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, 3064行,_run_cell 结果 = Runner(CORO) 文件“/opt/conda/lib/python3.10/site-packages/IPython/core/async_helpers.py”, 第 129 行,pseudo_sync_runner coro.send(无) 文件“/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, 第 3269 行,run_cell_async has_raised = 等待 self.run_ast_nodes(code_ast.body, cell_name, 文件“/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, 第 3448 行,run_ast_nodes 如果等待 self.run_code(code, result, async=asy): 文件“/opt/conda/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, 3508行,run_code exec(code_obj、self.user_global_ns、self.user_ns) 文件“/tmp/ipykernel_32/1342990786.py”,第 29 行,在 model.fit(生成器, steps_per_epoch=1, epochs=500, verbose=0) 文件“/opt/conda/lib/python3.10/site-packages/keras/utils/traceback_utils.py”, 第 65 行,error_handler 返回 fn(*args, **kwargs) 文件“/opt/conda/lib/python3.10/site-packages/keras/engine/training.py”, 1685 行,适合 tmp_logs = self.train_function(迭代器) 文件“/opt/conda/lib/python3.10/site-packages/keras/engine/training.py”, 第 1284 行,train_function 返回step_function(self, iterator) 文件“/opt/conda/lib/python3.10/site-packages/keras/engine/training.py”, 第 1268 行,step_function 输出 = model.distribute_strategy.run(run_step, args=(data,)) 文件“/opt/conda/lib/python3.10/site-packages/keras/engine/training.py”, 第 1249 行,在 run_step 输出 = model.train_step(数据) 文件“/opt/conda/lib/python3.10/site-packages/keras/engine/training.py”, 第 1051 行,train_step 损失 = self.compute_loss(x, y, y_pred, sample_weight) 文件“/opt/conda/lib/python3.10/site-packages/keras/engine/training.py”, 第 1109 行,compute_loss 返回self.compiled_loss( 文件“/opt/conda/lib/python3.10/site-packages/keras/engine/compile_utils.py”, 第 265 行,呼叫 loss_value = loss_obj(y_t, y_p, sample_weight=SW) 文件“/opt/conda/lib/python3.10/site-packages/keras/loss.py”,第 142 行,调用损失 = call_fn(y_true, y_pred) 文件“/opt/conda/lib/python3.10/site-packages/keras/loss.py”,第 268 行,调用中 往返ag_fn(y_true, y_pred, **self._fn_kwargs) 文件“/opt/conda/lib/python3.10/site-packages/keras/loss.py”,第 1469 行,mean_squared_error y_true = tf.cast(y_true, y_pred.dtype) 节点: 'mean_squared_error/Cast' 不支持
将字符串转换为浮点数 [[{{node mean_squared_error/Cast}}]] [作品:__inference_train_function_24923]

我做错了什么?

Python DataFrame Keras Kaggle Sequential

评论


答: 暂无答案