ResizeBilinear 将调整图像的高度和宽度,这意味着它不会影响通道数,即图像形状的最后一个维度。
如果您的图像的最后一个通道为 256,则以下内容将起作用
tf.fromPixels(loadedImage).resizeBilinear([7,7])
仅当两个大小匹配时,重塑张量才会起作用。
常量图像 = tf.ones([183, 275, 3 ])
调整大小 = tf.image.resizeBilinear(图像, [7, 7])
console.log(resized.pad([[0, 0], [0, 0], [126, 127]]).shape);
图像通常具有 [h, w, 3] 形状。
resize = tf.fromPixels(loadedImage).resizeBilinear([7,7]) // [7, 7, 3]
然后使用tf.pad
对于最后一个维度
const image = tf.ones([183, 275, 3 ])
resized = tf.image.resizeBilinear(image, [7, 7])
console.log(resized.pad([[0, 0], [0, 0], [126, 127]]).shape);// [7,7,256]
// reshape the tensor to be a 4d
resized.reshape([1,7,7,256])