我打算将模型大小从4.8M压缩到1.2M。
TensorFlow.js版本6.1.0
浏览器版本Chrome版本73.0.3683.86(正式版本)(64位)
我执行了以下过程:
Step1 将keras模型转换为tfjs模型。
tensorflowjs_converter --quantization_bytes 1 --input_format=keras ./my_model.h5 ./assets
它在group1-shard1of1
文件夹中输出2个文件model.json
和assets
Step2 在我的tensorflowjs项目中使用输出模型
this.model = await tf.loadModel('/assets/model.json');
它给出了错误:
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)
如果在第1步中没有标记quantization_bytes
,则输出模型将正常加载,并且可以正常工作。