tensorflow / tfjs

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

A TensorFlow fully convolutional model with no fixed input size cannot run properly in TensorFlow.js. #7960

Open OysterQAQ opened 1 year ago

OysterQAQ commented 1 year ago

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

Describe the current behavior

When converting a TensorFlow SavedModel to a tfjs model using tensorflowjs_converter and running it on tfjs@4.0.0, I encountered the following errors:

Uncaught (in promise) Error: Incompatible shape during merge: 1,76,282,64 vs. 1,260,1084,64 In versions 4.4.0 to 4.11.0, I received the following error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'backend') The original model is a fully convolutional model with no fixed input dimensions, designed for image super-resolution. It runs well on TensorFlow. You can find the specific code at https://github.com/OysterQAQ/ACG2vec-model/blob/master/real-cugan_tf/upcunet_v3_tfjs.py. SavedModel.zip tfjs_model.zip

const test = async () => {

  await tf.setBackend('cpu');
  const model = await tf.loadGraphModel("./models/tfjs_model/model.json");

console.log(111);

  const inputTensor = tf.zeros([1,224, 3080, 3], 'int32');
  const outputTensor = await model.executeAsync(inputTensor);
  if (outputTensor) {
  console.log(outputTensor.dataSync());
} else {
  console.error('outputTensor is undefined');
}
  inputTensor.dispose();
  outputTensor.dispose();

}
test();

Describe the expected behavior

Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/CodePen/any notebook.

Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

gaikwadrahul8 commented 1 year ago

Hi, @OysterQAQ

Thank you for bringing this issue to our attention and I was trying to replicate the same issue with tfjs-model which you provided in the issue template and I'm also getting same error which you mentioned above so we'll have to dig more into this issue and will update you soon. Thank you!

For your reference I have added error log output :

gaikwadrahul-macbookpro:test-7960 gaikwadrahul$ node index.js

============================
Hi, looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, visit https://github.com/tensorflow/tfjs-node for more details. 
============================
111
/Users/gaikwadrahul/Desktop/TFJS/test-7960/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4522
        var srcBackend = info.backend;
                              ^

TypeError: Cannot read properties of undefined (reading 'backend')
    at Engine.moveData (/Users/gaikwadrahul/Desktop/TFJS/test-7960/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4522:31)
    at DataStorage.get (/Users/gaikwadrahul/Desktop/TFJS/test-7960/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:230:28)
    at MathBackendCPU.incRef (/Users/gaikwadrahul/Desktop/TFJS/test-7960/node_modules/@tensorflow/tfjs-backend-cpu/dist/tf-backend-cpu.node.js:292:36)
    at Object.reshape [as kernelFunc] (/Users/gaikwadrahul/Desktop/TFJS/test-7960/node_modules/@tensorflow/tfjs-backend-cpu/dist/tf-backend-cpu.node.js:3825:13)
    at kernelFunc (/Users/gaikwadrahul/Desktop/TFJS/test-7960/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4707:32)
    at /Users/gaikwadrahul/Desktop/TFJS/test-7960/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4767:27
    at Engine.scopedRun (/Users/gaikwadrahul/Desktop/TFJS/test-7960/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4572:23)
    at Engine.runKernelFunc (/Users/gaikwadrahul/Desktop/TFJS/test-7960/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4763:14)
    at Engine.runKernel (/Users/gaikwadrahul/Desktop/TFJS/test-7960/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:4636:21)
    at reshape_ (/Users/gaikwadrahul/Desktop/TFJS/test-7960/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:9638:19)

Node.js v18.17.0
gaikwadrahul-macbookpro:test-7960 gaikwadrahul$ 
OysterQAQ commented 1 year ago

Is there any progress?