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 = tf.image.random_brightness(image, max_delta = 32. / 255.)
image = tf.image.random_contrast(image, lower =