擅长:python、mysql、java
<p>我找到了一种将<code>jimp</code>图像转换为<code>tfnode.Tensor</code>的方法:</p>
<pre><code>function preProcess(image){
// const values = imageByteArray(image);
const values = image.bitmap.data;
const outShape = [1, image.bitmap.width, image.bitmap.height, 4];
var input = tf.tensor4d(values, outShape, 'float32');
// Slice away alpha
input = input.slice([0, 0, 0, 0], [1, image.bitmap.width, image.bitmap.height, 3]);
return input;
}
</code></pre>
<p>Jimp图像通常也包含<code>alpha</code>值,所以我也生成了包含alpha值的<code>4D</code>张量,然后只包含<code>sliced</code>RGB值</p>
<p>正如@Edkeveke所说。我可以使用<code>tf.node.decodeImage</code>功能,但我的主要预处理(在培训期间)是在opencv上进行的,所以我需要确保它尽可能接近opencv实现</p>
<p>我还发现了一些带有<code>tensorflow</code>图像函数的<a href="https://github.com/tensorflow/tensorflow/issues/24893" rel="nofollow noreferrer">problems</a></p>
<p>所以我选择不使用tensorflow图像函数</p>