image = tf.image.resize_images(image, height, width, method = np.random.randint(4))
报错:ValueError: ‘size’ must be a 1-D Tensor of 2 elements
改为:image = tf.image.resize_images(img, new_shape, method = np.random.randint(4) 后可以正常运行
以下为完整的图像预处理代码:
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
def distort_color(image, color_ordering = 0):
if color_ordering == 0:
image = tf.image.random_brightness(image, max_delta = 32. / 255.)
image = tf.image.random_saturation(image, lower = 0.5, upper = 1.5)
image = tf.image.random_hue(image, max_delta = 0.2)
image = tf.image.random_contrast(image, lower = 0.5, upper = 1.5)
elif color_ordering == 1:
image = tf.image.random_saturation(image, lower = 0.5, upper = 1.5)
image

在使用TensorFlow进行图像预处理时,尝试使用`tf.image.resize_images`函数时遇到了`ValueError`,错误提示'size'必须是一个包含2个元素的1-D Tensor。解决方法是将参数改为`new_shape`,例如:`image = tf.image.resize_images(img, new_shape, method=np.random.randint(4))`。修改后的代码成功运行。"
112199526,10536069,MySQL入门教程:创建与管理数据库及表格,"['数据库管理', 'SQL', 'MySQL', '数据操作', '数据库入门']
最低0.47元/天 解锁文章
1066

被折叠的 条评论
为什么被折叠?



