keras_to_tensorflow
keras_to_tensorflow copied to clipboard
ValueError: axes don't match array
Hello, I tried converting my .h5 file to a protobuf file I could use on ML-engine. I get the following error
Using TensorFlow backend.
usage: keras_to_tensorflow.py [-h] [-input_fld INPUT_FLD]
[-output_fld OUTPUT_FLD]
[-input_model_file INPUT_MODEL_FILE]
[-output_model_file OUTPUT_MODEL_FILE]
[-output_graphdef_file OUTPUT_GRAPHDEF_FILE]
[-num_outputs NUM_OUTPUTS]
[-graph_def GRAPH_DEF]
[-output_node_prefix OUTPUT_NODE_PREFIX]
[-quantize QUANTIZE]
[-theano_backend THEANO_BACKEND] [-f F]
set input arguments
optional arguments:
-h, --help show this help message and exit
-input_fld INPUT_FLD
-output_fld OUTPUT_FLD
-input_model_file INPUT_MODEL_FILE
-output_model_file OUTPUT_MODEL_FILE
-output_graphdef_file OUTPUT_GRAPHDEF_FILE
-num_outputs NUM_OUTPUTS
-graph_def GRAPH_DEF
-output_node_prefix OUTPUT_NODE_PREFIX
-quantize QUANTIZE
-theano_backend THEANO_BACKEND
-f F
input args: Namespace(f=None, graph_def=False, input_fld='.', input_model_file='VGG16_data_augmented.h5', num_outputs=1, output_fld='', output_graphdef_file='model.ascii', output_model_file='', output_node_prefix='output_node', quantize=False, theano_backend=False)
Input file specified (VGG16_data_augmented.h5) only holds the weights, and not the model defenition.
Save the model using mode.save(filename.h5) which will contain the network architecture
as well as its weights.
If the model is saved using model.save_weights(filename.h5), the model architecture is
expected to be saved separately in a json format and loaded prior to loading the weights.
Check the keras documentation for more details (https://keras.io/getting-started/faq/)
Traceback (most recent call last):
File "keras_to_tensorflow.py", line 123, in <module>
raise err
File "keras_to_tensorflow.py", line 114, in <module>
net_model = load_model(weight_file_path)
File "/Users/harrymoreno/.local/share/virtualenvs/plantDisease-brvaIQZx/lib/python3.6/site-packages/keras/engine/saving.py", line 263, in load_model
load_weights_from_hdf5_group(f['model_weights'], model.layers)
File "/Users/harrymoreno/.local/share/virtualenvs/plantDisease-brvaIQZx/lib/python3.6/site-packages/keras/engine/saving.py", line 915, in load_weights_from_hdf5_group
reshape=reshape)
File "/Users/harrymoreno/.local/share/virtualenvs/plantDisease-brvaIQZx/lib/python3.6/site-packages/keras/engine/saving.py", line 556, in preprocess_weights_for_loading
weights = convert_nested_model(weights)
File "/Users/harrymoreno/.local/share/virtualenvs/plantDisease-brvaIQZx/lib/python3.6/site-packages/keras/engine/saving.py", line 532, in convert_nested_model
original_backend=original_backend))
File "/Users/harrymoreno/.local/share/virtualenvs/plantDisease-brvaIQZx/lib/python3.6/site-packages/keras/engine/saving.py", line 556, in preprocess_weights_for_loading
weights = convert_nested_model(weights)
File "/Users/harrymoreno/.local/share/virtualenvs/plantDisease-brvaIQZx/lib/python3.6/site-packages/keras/engine/saving.py", line 532, in convert_nested_model
original_backend=original_backend))
File "/Users/harrymoreno/.local/share/virtualenvs/plantDisease-brvaIQZx/lib/python3.6/site-packages/keras/engine/saving.py", line 674, in preprocess_weights_for_loading
weights[0] = np.transpose(weights[0], (3, 2, 0, 1))
File "/Users/harrymoreno/.local/share/virtualenvs/plantDisease-brvaIQZx/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 598, in transpose
return _wrapfunc(a, 'transpose', axes)
File "/Users/harrymoreno/.local/share/virtualenvs/plantDisease-brvaIQZx/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 51, in _wrapfunc
return getattr(obj, method)(*args, **kwds)
ValueError: axes don't match array
I have the h5py module installed and importable in this notebook. I also saved the model using model.save('foo.h5'). The only thing that might be an issue is that I made my mode parallelizable over many gpus like so using data parallelism.
I tried this utility on a no parallelized model and it converted fine. Thoughts?