首页 > 解决方案 > Tensorflow 图像调整大小无法按预期工作

问题描述

我正在使用以下代码调整图像大小,但得到了意想不到的结果。我还附上了输出截图。有人可以解释为什么会这样吗?

import cv2
import tensorflow as tf
import matplotlib.pyplot as plt

test_img = cv2.imread('deer12.jpeg')
test_img = cv2.cvtColor(test_img,cv2.COLOR_BGR2RGB)
plt.imshow(test_img, cmap=plt.cm.binary)
plt.show()
test_img=tf.image.resize(test_img,(32,32))
plt.imshow(test_img, cmap=plt.cm.binary)
plt.show()

产生: 图像

标签: pythontensorflow

解决方案


注意显示的消息...它们可能是警告。
“剪辑输入数据...” - 这表明您应该标准化图像。

import cv2
import tensorflow as tf
import matplotlib.pyplot as plt

test_img = cv2.imread('deer12.jpeg')
test_img = cv2.cvtColor(test_img,cv2.COLOR_BGR2RGB)
plt.imshow(test_img, cmap=plt.cm.binary)
plt.show()

test_img = test_img / 255.0  # this one

test_img=tf.image.resize(test_img,[32,32])
plt.imshow(test_img, cmap=plt.cm.binary)
plt.show()

推荐阅读