tensorflow / tfjs

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

decodeJpeg() function don't work in react native #4516

Closed Junhano closed 3 years ago

Junhano commented 3 years ago

So I basically copy the same code from the doc (https://blog.tensorflow.org/2020/02/tensorflowjs-for-react-native-is-here.html) about using tensorflow in react native. However when I want to call decodeJpeg function it returns an error

Error: Expected image (JPEG, PNG, or GIF), but got unsupported image type getImageType@http://192.168.0.141:8081/index.bundle?platform=ios&dev=true&minify=false:377324:22

I tried different ways and don't know if my setup is wrong or the doc is wrong Below is what I tried (1)

const response = await fetch(imageurl, {}, {isBinary: true});
    const imageData = await response.arrayBuffer();

    const img = decodeJpeg(imageData);

(2)

const img = decodeJpeg(imageurl)

the imageurl is from iPhone photo library so technically it's not from online but I think they should work the same. Do I need to show more setup?

mattsoulanille commented 3 years ago

@Junhano, since you're using a local image on iOS, is it possible the image you've loaded uses Apple's HEIF format? You may have to convert it to a supported format before calling decodeJpeg.

Junhano commented 3 years ago

@Junhano, since you're using a local image on iOS, is it possible the image you've loaded uses Apple's HEIF format? You may have to convert it to a supported format before calling decodeJpeg.

I did print out the URL and it ends with jpg

tafsiri commented 3 years ago

Could you try wrapping your arraybuffer in a UInt8Array similar to this example https://js.tensorflow.org/api_react_native/0.5.0/#decodeJpeg.

If that doesn't work could you upload a sample image file that shows this behaviour.

Junhano commented 3 years ago

fixed

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

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