I'm developing a react native application where I use TensorflowJs. I'm using cameraWithTensors from tfjs-react-native package which gives me images as Tensors of type int32. I want to convert those tensor data into base64 so I can render it in the app.
Somehow I found a solution to convert base64 data into tensor as shown below but I cannot do the opposite. I found decodJpeg method tfjs docs but it's opposite is not available. I tried many solutions but none of them worked.
URItoTensor = async URI => {
const imgB64 = await FileSystem.readAsStringAsync(URI, {
encoding: FileSystem.EncodingType.Base64,
});
const imgBuffer = tf.util.encodeString(imgB64, 'base64').buffer;
const unit8 = new Uint8Array(imgBuffer)
const tensor = decodeJpeg(unit8);
return tensor;
}