Categories
Misc

Model runs fine as a directory, but throws an error when used as an .h5 file: ValueError: All `axis` values to be kept must have known shape. Got axis: (-1,), input shape: [None, None], with unknown axis at index: 1

Interesting issue that I can’t quite wrap my head around.

We have a working Python project using Tensorflow to create and then use a model. This works great when we output the model as a directory, but if we output the model as an .h5 file, we run into the following error whenever we try to use the model:

ValueError: All `axis` values to be kept must have known shape. Got axis: (-1,), input shape: [None, None], with unknown axis at index: 1 

Here is how we were and how we are currently saving the model:

# this technique works (saves model to a directory) tf.keras.models.save_model( dnn_model, filepath='./true_overall', overwrite=True, include_optimizer=True, save_format=None, signatures=None, options=None, save_traces=True ) #this saves the file, but throws an error when the file is used tf.keras.models.save_model( dnn_model, filepath='./true_overall.h5', overwrite=True, include_optimizer=True, save_format=None, signatures=None, options=None, save_traces=True ) 

‚Äč

This is how we’re importing the model for use:

dnn_model = tf.keras.models.load_model('./neural_network/true_overall.) #works dnn_model = tf.keras.models.load_model('./neural_network/true_overall.h5') #doesn't work 

What would cause a model to work when saved as a directory but have issues when saved as an h5 file?

submitted by /u/jengl
[visit reddit] [comments]

Leave a Reply

Your email address will not be published. Required fields are marked *