小编Jon*_*n.H的帖子

在 Keras 中加载由 callbakcs.ModelCheckpoint() 保存的模型时出错

callbacks.ModelCheckpoint()使用 HDF5 文件自动保存了我的模型。

# Checkpoint In the /output folder
filepath = "./model/mnist-cnn-best.hd5"

# Keep only a single checkpoint, the best over test accuracy.
checkpoint = keras.callbacks.ModelCheckpoint(filepath, monitor='val_acc', 
                                             verbose=1, save_best_only=True,
                                             mode='max')

# Train
model.fit(x_train, y_train,
          batch_size=batch_size,
          epochs=epochs,
          verbose=1,
          validation_data=(x_test, y_test),
          callbacks=[checkpoint])
Run Code Online (Sandbox Code Playgroud)

当我加载模型时,发生了错误。

  model = keras.models.load_model("./mnist-cnn-best.hd5")

  File "D:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\saving.py", line 251, in load_model
    training_config['weighted_metrics'])
KeyError: 'weighted_metrics'
Run Code Online (Sandbox Code Playgroud)

如果我使用参数 ' compile=False '加载模型,它可以正常工作。

我知道在 keras 中保存模型的正常方法是:

from keras.models import load_model

model.save('my_model.h5')  # creates a HDF5 file 'my_model.h5'
del model  # deletes the existing …
Run Code Online (Sandbox Code Playgroud)

hdf5 keras tensorflow-lite

8
推荐指数
1
解决办法
4195
查看次数

semaphore_tracker:似乎有 1 个泄漏的信号量需要在关闭时清理 len(cache))

我通过 python3.6 运行 autokeras 代码。训练完一个模型后出现这样的警告:

Saving model.                                                              
+--------------------------------------------------------------------------+
|        Model ID        |          Loss          |      Metric Value      |
+--------------------------------------------------------------------------+
|           0            |    48.8651391018182    |   0.9489116312994325   |
+--------------------------------------------------------------------------+
/usr/local/lib/python3.6/multiprocessing/semaphore_tracker.py:143: UserWarning: semaphore_tracker: There appear to be 1 leaked semaphores to clean up at shutdown
  len(cache))
Run Code Online (Sandbox Code Playgroud)

我的训练代码:

clf = ImageClassifier(verbose=True)
clf.fit(x_train, y_train, time_limit=72*60*60)
clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)
y = clf.evaluate(x_test, y_test)
print(y)
Run Code Online (Sandbox Code Playgroud)

semaphore multiprocessing python-3.x auto-keras

5
推荐指数
1
解决办法
2万
查看次数