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

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”.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (1 by maintainers)

Most upvoted comments

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