Custom-built Keras model configuration + weights conversion problem

Hi,

I was trying to convert the configuration and weights of a Mobilenetv2 model into a single h5 file and got an error "OSError: Unable to open file (file signature not found)". Any tips on what is going wrong here would be appreciated!


(base) root@351e8b651607:/workspace# python /workspace/scripts/convert_model.py -w /data1/our_mobilenet/model.h5 keras /data1/our_mobilenet/model.json /data1/our_mobilenet/model_structure_weights.onnx
/workspace/miniconda/lib/python3.7/site-packages/numpy/__init__.py:156: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
 from . import _distributor_init
Using TensorFlow backend.
Traceback (most recent call last):
 File "/workspace/libs/ONNX_Convertor/keras-onnx/generate_onnx.py", line 32, in <module>
  converter.loadFromFile(args.kfile)
 File "/workspace/libs/ONNX_Convertor/keras-onnx/onnx_keras/frontend.py", line 47, in loadFromFile
  self.kmodel = Kmodels.load_model(kpath, custom_objects={ 'tf': tf, 'relu6': helper.relu6 })
 File "/workspace/miniconda/lib/python3.7/site-packages/keras/engine/saving.py", line 417, in load_model
  f = h5dict(filepath, 'r')
 File "/workspace/miniconda/lib/python3.7/site-packages/keras/utils/io_utils.py", line 186, in __init__
  self.data = h5py.File(path, mode=mode)
 File "/workspace/miniconda/lib/python3.7/site-packages/h5py/_hl/files.py", line 312, in __init__
  fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
 File "/workspace/miniconda/lib/python3.7/site-packages/h5py/_hl/files.py", line 142, in make_fid
  fid = h5f.open(name, flags, fapl=fapl)
 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 78, in h5py.h5f.open
OSError: Unable to open file (file signature not found)
Traceback (most recent call last):
 File "/workspace/scripts/convert_model.py", line 58, in <module>
  args.input_model], check=True)
 File "/workspace/miniconda/lib/python3.7/subprocess.py", line 512, in run
  output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['python', '/workspace/libs/ONNX_Convertor/keras-onnx/generate_onnx.py', '-o', '/data1/our_mobilenet/model_structure_weights.onnx', '-O2', '--duplicate-shared-weights', '/data1/our_mobilenet/model.json']' returned non-zero exit status 1.

Comments

  • If you want to convert a Keras model, you can save it as hdf5 instead of h5 and JSON, then the script should work fine.

    here is the example from the toolchain manual in document center:

    python /workspace/scripts/convert_model.py keras /docker_mount/onet.hdf5 /docker_mount/onet.onnx

The discussion has been closed due to inactivity. To continue with the topic, please feel free to post a new discussion.