解决Keras进行model.save时报错 Unable to create file (file locking disabled ... use HDF5_USE_FILE ...

我在使用Keras进行model.save时出现的问题

我在使用Keras进行model.save时出现如下问题,主要是在windows本地不会出现问题,但是已上传到服务器就完蛋了,所以导出找解决方法,貌似没查到中文的。

	model.save(os.path.join(file_dir, 'model.h5'), overwrite=True, include_optimizer=True)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/network.py", line 1090, in save
    save_model(self, filepath, overwrite, include_optimizer)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/saving.py", line 379, in save_model
    f = h5dict(filepath, mode='w')
  File "/usr/local/lib/python3.5/dist-packages/keras/utils/io_utils.py", line 186, in __init__
    self.data = h5py.File(path, mode=mode)
  File "/usr/local/lib/python3.5/dist-packages/h5py/_hl/files.py", line 312, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
  File "/usr/local/lib/python3.5/dist-packages/h5py/_hl/files.py", line 148, 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 98, in h5py.h5f.create
OSError: Unable to create file (file locking disabled on this file system (use HDF5_USE_FILE_LOCKING environment variable to override), errno = 38, error message = 'Function not implemented')

错误的重点在于:
OSError: Unable to create file (file locking disabled on this file system (use HDF5_USE_FILE_LOCKING environment variable to override), errno = 38, error message = 'Function not implemented')

解决方法

在写Python的脚本前面加上一句:
os.environ["HDF5_USE_FILE_LOCKING"] = 'FALSE'

按照错误将这个环境变量赋值为false即可。希望可以帮到你。

参考:

https://github.com/gdhugo/coral_singularity/issues/1

你可能感兴趣的:(Keras)