Python版本:3.12.4
PIP版本:24.1.1
KERAS版本:3.4.1
TENSORFLOW 版本:2.16.1
我一直在尝试在 jupyter 笔记本上运行代码来训练模型:
实际上会引发错误:
ValueError Traceback (most recent call last)
Cell In[10], line 2
1 # Model chekpoint Callback
----> 2 cp_callback = tf.keras.callbacks.ModelCheckpoint(
3 model_save_path, verbose=1, save_weights_only=False)
4 # Callback for early Termination
5 es_callback = tf.keras.callbacks.EarlyStopping(patience=20, verbose=1)
File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\keras\src\callbacks\model_checkpoint.py:191, in ModelCheckpoint.__init__(self, filepath, monitor, verbose, save_best_only, save_weights_only, mode, save_freq, initial_value_threshold)
189 else:
190 if not self.filepath.endswith(".keras"):
--> 191 raise ValueError(
192 "The filepath provided must end in `.keras` "
193 "(Keras model format). Received: "
194 f"filepath={self.filepath}"
195 )
ValueError: The filepath provided must end in `.keras` (Keras model format). Received: filepath=model/keypoint_classifier/keypoint_classifier.hdf5
代码:
# Model chekpoint Callback
cp_callback = tf.keras.callbacks.ModelCheckpoint(
model_save_path, verbose=1, save_weights_only=False)
# Callback for early Termination
es_callback = tf.keras.callbacks.EarlyStopping(patience=20, verbose=1)
我看到 save_weights_only=False 所以将“.keras”附加到 model_save_path 然后它就会起作用。 我注意到我的模型中存在类似问题,然后将 .keras 附加到文件路径解决了该问题。