基于python多处理的并行Keras模型训练

基于python多处理的并行Keras模型训练,python,tensorflow,keras,training-data,early-stopping,Python,Tensorflow,Keras,Training Data,Early Stopping,我正在64核CPU工作站上同时培训多个Keras MLP型号。 因此,我使用Python多处理池为每个CPU分配一个正在训练的模型。 对于正在培训的模型,我使用的是以以下方式定义的提前停止和模型检查点回调: es = EarlyStopping(monitor='val_mse', mode='min', verbose=VERBOSE_ALL, patience=10) mc = ModelCheckpoint('best_model.h5', monitor='val_mse', mode=

我正在64核CPU工作站上同时培训多个Keras MLP型号。 因此,我使用Python多处理池为每个CPU分配一个正在训练的模型。 对于正在培训的模型,我使用的是以以下方式定义的提前停止和模型检查点回调:

es = EarlyStopping(monitor='val_mse', mode='min', verbose=VERBOSE_ALL, patience=10)
mc = ModelCheckpoint('best_model.h5', monitor='val_mse', mode='min', verbose=VERBOSE_ALL, save_best_only=True)
使用单一模型,培训将顺利完成。 然而,当我开始使用多处理池时,我最终会遇到回调问题。出现hdf5型号保存问题:

Traceback (most recent call last):
  File "C:\Users\ICN_admin\Anaconda3\lib\site-packages\tensorflow_core\python\keras\callbacks.py", line 1029, in _save_model
    self.model.save(filepath, overwrite=True)
  File "C:\Users\ICN_admin\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 1008, in save
    signatures, options)
  File "C:\Users\ICN_admin\Anaconda3\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 112, in save_model
    model, filepath, overwrite, include_optimizer)
  File "C:\Users\ICN_admin\Anaconda3\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 92, in save_model_to_hdf5
    f = h5py.File(filepath, mode='w')
  File "C:\Users\ICN_admin\Anaconda3\lib\site-packages\h5py\_hl\files.py", line 394, in __init__
    swmr=swmr)
  File "C:\Users\ICN_admin\Anaconda3\lib\site-packages\h5py\_hl\files.py", line 176, in make_fid
    fid = h5f.create(name, h5f.ACC_TRUNC, fapl=fapl, fcpl=fcpl)
  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py\h5f.pyx", line 105, in h5py.h5f.create
OSError: Unable to create file (file signature not found)
这个错误或多或少是偶然出现的,通过异常,我可以捕捉到它以重复模型训练。 但是有没有办法通过设置标志或使用不同的回调文件格式来解决这个问题

Tensorflow版本:2.1.0

Keras版本:2.3.1

图书馆包括:

from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras.callbacks import ModelCheckpoint

确保每次创建
h5
文件时,在调用新文件或创建新文件之前,使用
f.close()
将其关闭。有时问题可以归结为使用多个worker,尝试减少worker节点可能会解决您的问题。您可以遵循此线程并检查用户的建议,确保每次创建
h5
文件时,在调用新文件或创建新文件之前,使用
f.close()
关闭该文件。有时问题可以归结为使用多个worker,尝试减少worker节点可能会解决您的问题。您可以按照此线程检查用户的建议