【发布时间】:2020-10-15 07:14:23
【问题描述】:
我正在开发一个使用 TensorflowJs 的反应原生应用程序。我正在使用来自tfjs-react-native 包的cameraWithTensors,它将图像作为int32 类型的张量提供给我。我想将这些张量数据转换为 base64,以便在应用程序中呈现它。
不知何故,我找到了一种将 base64 数据转换为张量的解决方案,如下所示,但我不能反其道而行之。我找到了decodJpeg 方法 tfjs 文档,但它相反不可用。我尝试了很多解决方案,但都没有奏效。
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;
}
【问题讨论】:
标签: react-native base64 decode tensor tensorflow.js