I have a JS app which is internally using the TensorFlow.js to run inference on two models. The first model is a GraphModel that consists of 126 nodes. And the second is a LayersModel that consists of 3 layers. The app is using WebGL backend But the issue occurs regardless of the selected backend. The issue is the following: If the app tries to run inference on the second (Layers) model, after running inference on the first model. TensorFlow.js crashes with the following stack trace:
engine.ts:426 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'backend')
at v.moveData (engine.ts:426:29)
at i.get (backend.ts:55:22)
at Object.Nr [as kernelFunc] (Reshape.ts:44:41)
at a (engine.ts:647:22)
at engine.ts:713:23
at v.scopedRun (engine.ts:480:19)
at v.runKernelFunc (engine.ts:709:10)
at v.runKernel (engine.ts:554:17)
at reshape_ (reshape.ts:60:10)
at reshape__op (operation.ts:51:22)
As long as the app is using just one of the models, the crash doesn't happen
I've fixed this issue by converting the LayersModel into a GraphModel. So now I have two GraphModels in my app