tensorflow / tfjs

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

[tfjs-tflite] ERROR: failed to delegate CONV_2D node #2 #5531

Closed josephrocca closed 3 years ago

josephrocca commented 3 years ago

System information

The following code fails with a bunch of errors:

<img id="imgInputEl" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEBOgE6AAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAIQAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAAHRyWFlaAAABZAAAABRnWFlaAAABeAAAABRiWFlaAAABjAAAABRyVFJDAAABoAAAAChnVFJDAAABoAAAAChiVFJDAAABoAAAACh3dHB0AAAByAAAABRjcHJ0AAAB3AAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAFgAAAAcAHMAUgBHAEIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFhZWiAAAAAAAABvogAAOPUAAAOQWFlaIAAAAAAAAGKZAAC3hQAAGNpYWVogAAAAAAAAJKAAAA+EAAC2z3BhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABYWVogAAAAAAAA9tYAAQAAAADTLW1sdWMAAAAAAAAAAQAAAAxlblVTAAAAIAAAABwARwBvAG8AZwBsAGUAIABJAG4AYwAuACAAMgAwADEANv/bAEMACgcHCAcGCggICAsKCgsOGBAODQ0OHRUWERgjHyUkIh8iISYrNy8mKTQpISIwQTE0OTs+Pj4lLkRJQzxINz0+O//bAEMBCgsLDg0OHBAQHDsoIig7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O//AABEIADIAMgMBIgACEQEDEQH/xAAbAAACAwEBAQAAAAAAAAAAAAAABQIDBgQHAf/EACwQAAEDAwIEBAcBAAAAAAAAAAEAAgMEBREhMQYSQVEVMmFxFBYzUoGRwdH/xAAaAQACAwEBAAAAAAAAAAAAAAACBAABBQMG/8QAIhEAAgEEAgIDAQAAAAAAAAAAAAECAwQREhMhBTEUIiNB/9oADAMBAAIRAxEAPwD0LCg9zY28zzgKzC566MmE9Mjfslry6+PDKWWwqVPd9kYaymqZHRxSAvbqW9VN72McGueATsCd1jbnNLSVbJ6dxZLEc8w6rR2yqN1t0dZI0AvadB6EhILyj4dtfsNStMPOei/xCkM4gMwa86AHTKvIWR4hp+WNxHuEx4TvDrjRPp53F09Ppk7ub0P8TFjfO46muwK9vpHaPod8qFPCFqCh0t3GVyXGXEZwuzGiV3IvMTmgarB8tssP+DdukzK3BwlkcAn9gcGcP0zR0Ys/VERnkJAc84z2T+hqKYwNp6c4EbAMd/VZEqc+FzXpGlOSwonDesPgdnfKS8HvdDxIYx5ZInNP41/icXd2GEeqS2BwhvxlzoyMn96f6mPGNqogay/FnoOUJX4kEL1W6MbRj8KmrpI6mIsdlpI8zdwrQdVI7IKkIzWJLKCjJrtGa+UKY1BlkqJ5SfvcNPZdkPD1NC4OjLg4bHKbFfRsg4YJYx0Hyyb9mbulkrZQfh3ROHZ+Qk9v4Ur4J5JZZGBzzqGnOB2C3TlURqudG0pUnmKCnXnJatiIWWXH1ChPEJrSJw2ZeFNyEKMpFZ3Uh5UIUYSIuVbkIVopkEIQrBP/2Q==">

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.8.0/dist/tf.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-tflite@0.0.1-alpha.4/dist/tf-tflite.js"></script>

<script>
  (async function() {
    const esrgan = await tflite.loadTFLiteModel('https://tfhub.dev/captain-pool/lite-model/esrgan-tf2/1');
    console.log("esrgan:", esrgan);

    const outputTensor = tf.tidy(() => {
      let img = tf.browser.fromPixels(imgInputEl);
      let input = tf.sub(tf.div(tf.expandDims(img), 127.5), 1); // normalise [-1,1]
      console.log("input:", input);

      let outputTensor = esrgan.predict(input);
      return tf.mul(tf.add(outputTensor, 1), 127.5) // de-normalize
    });
    console.log(outputTensor, outputTensor.shape);
  })();
</script>

image ... image

vladmandic commented 3 years ago

just a thought, tfjs-tflite@0.0.1-alpha.4 npm package is 3 months old which tfjs has went through quite a lot of changes since then - can you try with tflite built from main?

i got a lot of errors with both tfjs-tflite and tfjs-backend-webgpu using old alpha builds, quite a few resolved after a fresh build.

rthadur commented 3 years ago

I agree , there is a older version on npm, requesting @jinjingforever for pushing newer version to npm.Thank you

jinjingforever commented 3 years ago

Thank you guys for investigation. Actually tfjs-tflite@0.0.1-alpha.4 is indeed the latest version. The errors shown here are from the tflite c++ runtime. It is likely that the model is not working well with XNNPACK that tflite is using. I will do more digging with the tflite team and report back if I have anything. Thank you!

jinjingforever commented 3 years ago

Hi, I just published a new version of the tfjs-tflite package (0.0.1-alpha.6) which should fix this problem. See this demo. The model is a little bit slow but it works:) It might get a bit faster if you set up your server for cross-origin isolation (codepen doesn't support it unfortunately).

Thanks!

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

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

josephrocca commented 3 years ago

Thank you!