python - 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()
解决方案
注意显示的消息...它们可能是警告。
“剪辑输入数据...” - 这表明您应该标准化图像。
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()
推荐阅读
- c# - 无法获取 C# 默认接口方法进行编译
- powershell - 如何在 PowerShell 中带有尾随空格的文件夹上使用 Set-Location?
- reactjs - 更新 MaterialUI 的“TextField”值会导致页面上的其他 TextField 值清除
- javascript - 如何将 LocalStorage 添加到按钮以更改颜色
- java - 使用 @Query 更新不更新 ReactiveCrudRepository 中的数据
- kubernetes-helm - 错误:创建:创建失败:服务器响应状态码 413 但未返回更多信息
- python-asyncio - 如何使用 asyncio.Future 将基于事件的通信转换为 async/await
- javascript - 在我的 html 中包含一个 svg 元素会破坏 jquery ui
- django - Django REST 在 DetailView 上抛出 404 错误
- python - 在 Python 上使用 selenium 单击多个元素