tfjs
tfjs copied to clipboard
Cannot load model from converted keras model with quantization
My intention is to squeeze model size from 4.8M to 1.2M.
TensorFlow.js version
6.1.0
Browser version
Chrome Version 73.0.3683.86 (Official Build) (64-bit)
Describe the problem or feature request
Step1 convert keras model to tfjs model.
tensorflowjs_converter --quantization_bytes 1 --input_format=keras ./my_model.h5 ./assets
it outputs 2 files group1-shard1of1 and model.json in assets folder
Step2 use the output model in my project
this.model = await tf.loadModel('/assets/model.json');
it gives errors:
core.js:1448 ERROR Error: Uncaught (in promise): RangeError: byte length of Float32Array should be a multiple of 4
RangeError: byte length of Float32Array should be a multiple of 4
at new Float32Array (<anonymous>)
at eval (weights_loader.js:134)
at Array.forEach (<anonymous>)
at eval (weights_loader.js:130)
at Array.forEach (<anonymous>)
at Object.eval (weights_loader.js:115)
at step (weights_loader.js:32)
at Object.eval [as next] (weights_loader.js:13)
at fulfilled (weights_loader.js:4)
at ZoneDelegate.invoke (zone.js:388)
at resolvePromise (zone.js:824)
at eval (zone.js:734)
at rejected (app.component.ts:14)
at ZoneDelegate.invoke (zone.js:388)
at Object.onInvoke (core.js:4749)
at ZoneDelegate.invoke (zone.js:387)
at Zone.run (zone.js:138)
at eval (zone.js:882)
at ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4740)
***if without flag quantization_bytesin step 1 ***, the output model will be loaded normally, and works fine.
@changkaizhao Two comment:
- We have a PR under review that will improve quantization of models converted from keras: https://github.com/tensorflow/tfjs-converter/pull/346 (cc @pyu10055 )
- The error you are getting may be unrelated. Can you check in your developer tools what the response status of the weight file is? Is it 200? Does the content look correct? It should be some binary data. If you see an error or warning message there, it might indicate the HTTP server is serving the file incorrectly.
This has been fixed in #2366 , closing this.