javascript - 在本机反应中将RGB转换为灰度
问题描述
我已经在灰度图像上训练了一个模型。它接受 48x48 像素和灰度格式组合为 48x48x1。我在本机反应中使用此模型。我从手机存储中选择的图像被转换为 tensor3d RGB。我想将它们转换为灰度。
const decodeJpeg=(rawImageData)=>{
//Function to convert jpeg image to tensors
const TO_UINT8ARRAY = true;
const { width, height, data } = jpeg.decode(rawImageData, TO_UINT8ARRAY);
// Drop the alpha channel info for mobilenet
const buffer = new Uint8Array(width * height * 3);
let offset = 0; // offset into original data
for (let i = 0; i < buffer.length; i += 3) {
buffer[i] = data[offset];
buffer[i + 1] = data[offset + 1];
buffer[i + 2] = data[offset + 2];
offset += 4;
}
return tf.tensor3d(buffer, [height, width, 3]);
}
尝试了下面的代码,但它没有帮助。
const imageTensor = decodeJpeg(imageData).resizeBilinear([48,48]).reshape([48,48,1])
解决方案
推荐阅读
- java - 使用 openjdk 8u292 版本的 ldap ssl 连接的匿名绑定失败,但 oracle jdk 1.8.0_162 工作正常
- php - 在 CURL 中发送 APi 密钥和密钥
- pdfbox - PDFBox - 签署 PDF 已由另一个人签署
- cmd - 如何从 taskkill 命令中排除一个窗口标题?
- javascript - 在带有包裹的javascript中更改视频src
- flutter - 当我在颤动中执行 tojson 时出现错误
- android - 如何在 Fragment 中访问我的 xml 元素
- javascript - Javascript 不会更新 blazor 组件的值
- docker - 无法在具有 ubuntu 18.04 特权的 docker 上运行 Gazebo9
- python - 在 HuggingFace 中将模型加载为 DPRQuestionEncoder