I am working on learning the LSTM network on the Google Cloud Machine Learning engine using Keras with the TensorFlow backend. I managed to deploy my model and complete a successful training task after making some changes to gcloud and my python script.
Then I tried to get my model to maintain breakpoints after each era using the Keras modelCheckpoint callback . Starting a local tutorial with Google Cloud works just fine as expected. Weights are stored in the specified path after each era. But when I try to run the same job online in the Google Cloud Machine Learning Engine, it weights.hdf5doesnβt write to my Google Cloud Bucket. Instead, I get the following error:
...
File "h5f.pyx", line 71, in h5py.h5f.open (h5py/h5f.c:1797)
IOError: Unable to open file (Unable to open file: name =
'gs://.../weights.hdf5', errno = 2, error message = 'no such file or
directory', flags = 0, o_flags = 0)
I investigated this problem, and it turned out that there were no problems with the Bucket itself, since the Keras Tensorboard callback works fine and writes the expected result to the same segment. I also made sure that it was h5pyenabled by providing this at setup.pylocated at:
βββ setup.py
βββ trainer
βββ __init__.py
βββ ...
Actual inclusion in setup.pyshown below:
from setuptools import setup, find_packages
setup(name='kerasLSTM',
version='0.1',
packages=find_packages(),
author='Kevin Katzke',
install_requires=['keras','h5py','simplejson'],
zip_safe=False)
I assume the problem boils down to the fact that GCS cannot be accessed with openPythons I / O, as it provides a custom implementation instead:
import tensorflow as tf
from tensorflow.python.lib.io import file_io
with file_io.FileIO("gs://...", 'r') as f:
f.write("Hi!")
After checking how the Keras modelCheckpoint callback implements the actual file entry, it turns out that it uses h5py.File () for I / O:
with h5py.File(filepath, mode='w') as f:
f.attrs['keras_version'] = str(keras_version).encode('utf8')
f.attrs['backend'] = K.backend().encode('utf8')
f.attrs['model_config'] = json.dumps({
'class_name': model.__class__.__name__,
'config': model.get_config()
}, default=get_json_type).encode('utf8')
h5py package Pythonic- HDF5 binary data format h5py.File() , HDF5 , : , .
, modelCheckpoint GCS Bucket? " " - hdf5, GCS file_io.FileIO()?