Skip to content

Question regarding tf.ready() and ml5.setBackend("webgl"); in NeuralNetwork examples #205

@jchwenger

Description

@jchwenger

Hi there,

I came across the error on Chrome for this example:

engine.js:103 Uncaught (in promise) Error: Backend 'undefined' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods
    at get backend (engine.js:103:19)
    at b.makeTensor (engine.js:612:35)
    at s (tensor_ops_util.js:66:19)
    at Module.a (tensor.js:199:12)
    at SD.formatInputsForPredictionAll (index.js:443:12)
    at SD.predictSyncInternal (index.js:883:28)
    at SD.predictSync (index.js:828:17)
    at finishedTraining (sketch.js:130:18)
    at callcallback.js:35:9

Which goes away if you add the following line, as you did in your current example:

  // For this example to work across all browsers
  // "webgl" or "cpu" needs to be set as the backend
  ml5.setBackend("webgl");

Curious about it, I did a quick search in the source code, and now I wonder if it might not be a case of just adding tf.ready() at the right spot in NeuralNetwork/index.js? I'm sorry I'm not yet fully set up to make this experiment. It seems that it's called in all the other classes but not this one:

Screenshot 2024-09-17 at 11 05 48

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions