UnpicklingError: invalid load key, 'H'

3,336 views
Skip to first unread message

xuzha...@gmail.com

unread,
Mar 24, 2017, 7:27:30 PM3/24/17
to Keras-users
I trained a CNN and saved it using model.save_weights('trained.h5'). Then I load it using weights = pkl.load(open('./nets/trained.h5', 'rb')). I got the error below:

runfile('/var/home/xzhang/sensor_fusion_iscas_2016-master/test_convnet.py', wdir='/var/home/xzhang/sensor_fusion_iscas_2016-master')
Reloaded modules: spike_tester_theano, theano_layers
Traceback (most recent call last):

  File "<ipython-input-30-0b27d6aed9fc>", line 1, in <module>
    runfile('/var/home/xzhang/sensor_fusion_iscas_2016-master/test_convnet.py', wdir='/var/home/xzhang/sensor_fusion_iscas_2016-master')

  File "/usr/local/lib/python2.7/dist-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
    execfile(filename, namespace)

  File "/usr/local/lib/python2.7/dist-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
    builtins.execfile(filename, *where)

  File "/var/home/xzhang/sensor_fusion_iscas_2016-master/test_convnet.py", line 15, in <module>
    weights = pkl.load(open('./nets/my_mnist_54.33_wts_normd.h5', 'rb'))

UnpicklingError: invalid load key, 'H'.

Daπid

unread,
Mar 25, 2017, 7:18:39 AM3/25/17
to xuzha...@gmail.com, Keras-users
Save_weights creates a hdf5 file, not a pickle. You need to load the architecture and then use the method load_weights on the h5 file. 

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/14a442d6-8818-477c-806a-471eb81fe2dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages