def decode(self, filename, distort_data, whiten_data = True):
"""distort: random distort the iamge"""
image_tensor = tf.read_file(filename)
image_tensor = self.decode_fun(image_tensor, channels = self.channels, ratio = self.ratio)
image_tensor = tf.image.convert_image_dtype(image_tensor, tf.float32)
image_tensor = tf.image.resize_images(image_tensor,
[self.shape[0] + self.offset, self.shape[1] + self.offset])
if distort_data:
# it will crop in the function
image_tensor = self.distort_op(image_tensor)
else:
image_tensor = tf.image.resize_image_with_crop_or_pad(image_tensor,
self.shape[0], self.shape[1])
if whiten_data:
# Subtract off the mean and divide by the variance of the pixels.
image_tensor = tf.image.per_image_whitening(image_tensor)
return image_tensor
评论列表
文章目录