tfjs icon indicating copy to clipboard operation
tfjs copied to clipboard

Error when load model using tf.loadLayersModel

Open AmmarYasir29 opened this issue 5 years ago • 11 comments

when run the code (async function () { console.log("wating for model load!"); const model = await tf.loadLayersModel("simple/model.json"); console.log("model: ", model); })(); I got error Uncaught (in promise) Error: Input 0 is incompatible with layer flatten_3: expected min_ndim=3, found ndim=2. at new e (errors.ts:48) at e.assertInputCompatibility (topology.ts:790) at topology.ts:985 at rh (common.ts:43) at e.apply (topology.ts:978) at e.add (models.ts:500) at e.fromConfig (models.ts:948) at Rp (generic_utils.ts:277) at cd (serialization.ts:31) at models.ts:300

I use script tag verson 1.0.0 OR 2.0.0 same error <script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>

How can fix it ??

AmmarYasir29 avatar Mar 04 '21 18:03 AmmarYasir29

Please use latest version 3.2.0 and let us know , if that does not help , please share reproducible code in codepen or in a GitHub repo. Thank you

rthadur avatar Mar 04 '21 19:03 rthadur

this is my code on github https://github.com/AmmarYasir29/tensorflowJS

I try the last verson that you tell me ans the same error:

Uncaught (in promise) Error: Input 0 is incompatible with layer flatten_3: expected min_ndim=3, found ndim=2. at t.n.assertInputCompatibility (topology.js:790)

AmmarYasir29 avatar Mar 05 '21 07:03 AmmarYasir29

@rthadur any help ??

AmmarYasir29 avatar Mar 05 '21 19:03 AmmarYasir29

i guess the model file is missing , is it fine to share the model also , thank you

rthadur avatar Mar 05 '21 23:03 rthadur

I convert model from .h5 format to .json to load embedded it to web by console.log("wating form model load!"); const model = await tf.loadLayersModel("http://localhost:3000/fjs/model.json"); But the error appear IMG Error and I cant fix that

The mdoel in h5 format the model h5 and the json format

AmmarYasir29 avatar Mar 06 '21 12:03 AmmarYasir29

@rthadur the error still appear and the model not load Is there solution ?

AmmarYasir29 avatar Mar 13 '21 12:03 AmmarYasir29

@lina128 can you help me ?

AmmarYasir29 avatar Mar 26 '21 13:03 AmmarYasir29

if you are loading the model from local folder you need to use below code

model = await tf. loadLayersModel('model/model.json');

rthadur avatar Mar 26 '21 16:03 rthadur

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.

google-ml-butler[bot] avatar Mar 24 '22 21:03 google-ml-butler[bot]

Closing as stale. Please @mention us if this needs more attention.

google-ml-butler[bot] avatar Apr 11 '22 17:04 google-ml-butler[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Apr 11 '22 17:04 google-ml-butler[bot]