tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.52k stars 1.94k forks source link

Uncaught (in promise) TypeError: Cannot read property 'reduce' of undefined #4105

Closed ghafran closed 3 years ago

ghafran commented 4 years ago

When creating a model using AutoML with Multi Classification.

Getting this error from tensorflowjs when running const model = await tf.automl.loadImageClassification('/model/model.json');

tfjs:17 Uncaught (in promise) TypeError: Cannot read property 'reduce' of undefined
    at e.t.transformGraph (tfjs:17)
    at e.t.loadSync (tfjs:17)
    at e.<anonymous> (tfjs:17)
    at u (tfjs:17)
    at Generator._invoke (tfjs:17)
    at Generator.forEach.e.<computed> [as next] (tfjs:17)
    at Um (tfjs:17)
    at o (tfjs:17)

html code:

<script src="https://unpkg.com/@tensorflow/tfjs"></script>
<script src="https://unpkg.com/@tensorflow/tfjs-automl"></script>
<img id="daisy" src="test2.jpg">
<script>
    async function run() {
        const model = await tf.automl.loadImageClassification('/model/model.json');
        const image = document.getElementById('daisy');
        const predictions = await model.classify(image);
        console.log(predictions);
        // Show the resulting object on the page.
        const pre = document.createElement('pre');
        pre.textContent = JSON.stringify(predictions, null, 2);
        document.body.append(pre);
    }
    run();
</script>

Model Multi-Classification, Edge, Exported for Tensorflowjs

Nothing crazy here just a simple export and run from browser. The model works fine when deployed in GCP with "Test&Use".

ghafran commented 4 years ago

@pyu10055 Not sure if this falls in your court :)

ghafran commented 4 years ago

Just tried this on models that were working previously. Looks like something changed during the model export or creation process on AutoML that is causing this issue.

ghafran commented 4 years ago

This seems to be fixed today. I retrained the models this morning and exported. Worked as expected. I love voodoo magic self healing :)

google-ml-butler[bot] commented 4 years ago

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

ghafran commented 4 years ago

This issue popped up again :(

rthadur commented 4 years ago

cc @pyu10055 @tafsiri

pyu10055 commented 4 years ago

@ghafran can you share your model file? thanks

ghafran commented 4 years ago

Attached. Just exported it from AutoML Multi-classification using edge, faster performance. Getting same error. @pyu10055

ghafran commented 4 years ago

@pyu10055 thanks for posting the fix. Your a life saver!

ghafran commented 4 years ago

@pyu10055 I see the fix has been completed. Can I regenerate the model now or do we need to wait for a production push? Thanks.

google-ml-butler[bot] commented 4 years ago

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

ghafran commented 4 years ago

@pyu10055 This issues still seems to be happening. Do we know when the fix will be deployed?

Vivek1907 commented 4 years ago

Even I am also facing the same issue :( The model I exported about 3 weeks ago is working perfectly fine but the model I exported yesterday is not working and showing the error "cannot read property reduce of undefined" :(

ghafran commented 3 years ago

Our customers are getting agitated. Do have an estimate of when this will be pushed?

pyu10055 commented 3 years ago

@ghafran The fix will be available in the next release, but meanwhile you can lock your tfjs version to 2.6.0, that should temporarily solve your problem.

Vivek1907 commented 3 years ago

I think I found a solution

In your model.json file just remove this line:- "modelInitializer": {"versions": {}},.

@ghafran so here is the modified model.json

model_json.zip

Replace your model.json with the above file

So, this should work even with the latest tfjs version

ghafran commented 3 years ago

@Vivek1907 that work around fixes it! Thank you!

zholmes1 commented 3 years ago

@Vivek1907 Worked for me too. Thanks!

ghafran commented 3 years ago

Just trained, exported, and ran the models with latest versions. All is good now.

google-ml-butler[bot] commented 3 years ago

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

jml1996jsonhost commented 3 years ago

Does anyone here have any insight about the problem described at the bottom of this stackoverflow post: https://stackoverflow.com/questions/65402617/tensorflow-automl-model-in-react