擅长:python、mysql、java
<p>您可以将操作符链接在一起以将图像转换为灰度,然后需要使用<code>dataSync()</code>提取预测</p>
<pre><code>const imageDataArrayBuffer = await response.arrayBuffer();
const imageData = new Uint8Array(imageDataArrayBuffer);
const imageTensor = decodeJpeg(imageData).resizeBilinear([48,48]).reshape([48,48,3])
# grayscale = (1, width, height, 1)
const grayscale = tf.browser.fromPixels(imageTensor)
.mean(2)
.toFloat()
.expandDims(0)
.expandDims(-1)
# Extract the results out
const result = await model.predict(imageTensor).dataSync()[0]
</code></pre>