keras-js icon indicating copy to clipboard operation
keras-js copied to clipboard

Unable to generate model_weights.buf and model_metadata.json

Open ghassanmas opened this issue 7 years ago • 7 comments

I got error when running:

$ python encoder.py /path/to/model.hdf5

Which is :

Traceback (most recent call last): File "encoder.py", line 114, in <module> encoder.serialize() File "encoder.py", line 62, in serialize self.model.model_config = hdf5_file.attrs['model_config'] 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 "/home/ghassan/anaconda2/lib/python2.7/site-packages/h5py/_hl/attrs.py", line 58, in __getitem__ attr = h5a.open(self._id, self._e(name)) 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/h5a.pyx", line 77, in h5py.h5a.open KeyError: "Can't open attribute (Can't locate attribute: 'model_config')" The way I generated the model.hdf5 file is by :

happyModel.save_weights("model.hdf5")

Using Keras version: 2.0.7

ghassanmas avatar Nov 18 '17 20:11 ghassanmas

I'm having the same issue using latest version of Keras. After digging around the closed issues I was able to use encoder.py and got a .bin file. I do not know what to do with it now cause I just want to load it inside my html file but keras still requires the three separate files. I am not using node.js, should I?

kvue avatar Nov 20 '17 22:11 kvue

I did the same by saving the whole model as hdf5 file I was able to generate the .bin using the encoder.py but then when trying to load the model in keras.js it expect 3 files !. I am also using keras.js as a file, I don't think it would make such a different using node.js only if the module in node,js is updated such that when creating a new model it could take the file .bin as the only argument.

ghassanmas avatar Nov 20 '17 22:11 ghassanmas

The encoder.py from the keras.js v3 release page:https://github.com/transcranial/keras-js/releases gives you the model_weights.buf and model_metadata.json files. I got no errors this time.

kvue avatar Nov 21 '17 00:11 kvue

@kvue , keras.js v3, worked for me. Thanks

jageshmaharjan avatar Nov 21 '17 10:11 jageshmaharjan

@kvue Also worked for me ! much appreciated. You know also when downloading the project from https://github.com/transcranial/keras-js/releases the hierarchy of files is different for example the "encoder.py" is in the root.

ghassanmas avatar Nov 21 '17 18:11 ghassanmas

The releases encoder.py file also works for me! Thanks

fedden avatar Nov 24 '17 01:11 fedden

Thanks for pointing to the right solution!!

EzzatOmar avatar Nov 27 '17 22:11 EzzatOmar