我参考Keras VAE教程(https://keras.io/examples/generative/vae/)将VAE模型从Conv2D转换为Conv1D,并成功拟合了模型。
在模型拟合后,用“预测”法计算列车的平均有效损失。
x_train_pred = vae.predict(x_train)
train_mae_loss = np.mean(np.abs(x_train_pred - x_train), axis=1)
然后错误出现了
NotImplementedError Traceback (most recent call last)
Cell In [98], line 3
1 # Get train MAE Loss
----> 3 x_train_pred = vae.predict(x_train)
4 train_mae_loss = np.mean(np.abs(x_train_pred - x_train), axis=1)
5 # train_mae_loss = np.mean(abs(x_train_pred - x_train), axis=1)
File /notebooks/users/1004831/objupyterlabgpu-1004831/kernels/mytensor2.0.0b/lib/python3.9/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.__traceback__)
68 # To get the full stack trace, call:
69 # `tf.debugging.disable_traceback_filtering()`
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb
File /tmp/__autograph_generated_fileau_h0p6f.py:15, in outer_factory.<locals>.inner_factory.<locals>.tf__predict_function(iterator)
13 try:
14 do_return = True
---> 15 retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
16 except:
17 do_return = False
NotImplementedError: in user code:
File "/notebooks/users/1004831/objupyterlabgpu-1004831/kernels/mytensor2.0.0b/lib/python3.9/site-packages/keras/engine/training.py", line 2041, in predict_function *
return step_function(self, iterator)
File "/notebooks/users/1004831/objupyterlabgpu-1004831/kernels/mytensor2.0.0b/lib/python3.9/site-packages/keras/engine/training.py", line 2027, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/notebooks/users/1004831/objupyterlabgpu-1004831/kernels/mytensor2.0.0b/lib/python3.9/site-packages/keras/engine/training.py", line 2015, in run_step **
outputs = model.predict_step(data)
File "/notebooks/users/1004831/objupyterlabgpu-1004831/kernels/mytensor2.0.0b/lib/python3.9/site-packages/keras/engine/training.py", line 1983, in predict_step
return self(x, training=False)
File "/notebooks/users/1004831/objupyterlabgpu-1004831/kernels/mytensor2.0.0b/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/notebooks/users/1004831/objupyterlabgpu-1004831/kernels/mytensor2.0.0b/lib/python3.9/site-packages/keras/engine/training.py", line 584, in call
raise NotImplementedError(
NotImplementedError: Exception encountered when calling layer "vae_6" " f"(type VAE).
Unimplemented `tf.keras.Model.call()`: if you intend to create a `Model` with the Functional API, please provide `inputs` and `outputs` arguments. Otherwise, subclass `Model` with an overridden `call()` method.
Call arguments received by layer "vae_6" " f"(type VAE):
• inputs=tf.Tensor(shape=(None, 20, 1), dtype=float32)
• training=False
• mask=None
我的初始代码在这里
第一次
这意味着子类,API的问题,但我不能理解的问题。我怎么做,以修复我的代码计算列车损失?
1条答案
按热度按时间avwztpqn1#
我想你在调用采样层的构造函数时忘了指定采样层的大小。