【发布时间】:2021-07-18 13:43:03
【问题描述】:
尝试使用 TensorflowJS 进行预测。但是,在上面的输入图像中显示错误?我的图像是 Uint8Array 类型。如何传递 Uint8Array 类型来制作张量?
async predict(imageData: any) {
let img = tf.browser.fromPixels(imageData, 3).resizeBilinear([256, 256]) # problem showing here
img = imageData.reshape([256, 256, 3])
img = tf.cast(img, 'float32')
const segmentation = this.model.predict(img) as any
console.log('success')
}
loadImage(file: FileList) {
this.fileToUpload = file.item(0);
let reader = new FileReader();
reader.readAsDataURL(this.fileToUpload);
reader.onload = (event: any) => {
this.imageUrl = reader.result
this.predict(this.convertDataURIToBinary(this.imageUrl)); # passing Unit8Array image from here
}
}
知道如何克服它吗?谢谢你的建议。
更新
使用 '@ViewChild('ImageRef') ImageRef: ElementRef;' 解决了这个问题.最后,我将 Unit8Array 转换为 imageData,然后使用 putImageData 绘制到画布中。
但在另一部分面临问题。当我进行图像分割时,结果与我在 python 中所做的相反。有什么想法吗?
我在 python 中做过 - >
img_face = cv2.resize(frame,(256,256))
img_face = cv2.cvtColor(img_face, cv2.COLOR_BGR2RGB)
img_face = img_face / 255.0
img_face = img_face.astype(np.float32)
mask = model.predict(np.expand_dims(img_face , axis=0))[0]
而我当前的 js 部分已经在上面提到了 predict() func。
【问题讨论】:
标签: javascript angular tensor tensorflow.js tensorflowjs-converter