def single_input_image(image_str, mean_image_path, png_with_alpha=False, image_size=512):
mean_image_str = tf.convert_to_tensor(mean_image_path, dtype=tf.string)
file_contents = tf.read_file(image_str)
if png_with_alpha:
uint8image = tf.image.decode_png(file_contents, channels=4)
uint8image.set_shape([image_size, image_size, 4])
else:
uint8image = tf.image.decode_image(file_contents, channels=NUM_CHANNELS)
uint8image.set_shape([image_size, image_size, NUM_CHANNELS])
image = tf.cast(uint8image, tf.float32)
#subtract mean image
mean_file_contents = tf.read_file(mean_image_str)
if png_with_alpha:
mean_uint8 = tf.image.decode_png(mean_file_contents, channels=4)
mean_uint8.set_shape([image_size, image_size, 4])
else:
mean_uint8 = tf.image.decode_image(mean_file_contents, channels=NUM_CHANNELS)
mean_uint8.set_shape([image_size, image_size, NUM_CHANNELS])
image_mean_free = tf.subtract(image, tf.cast(mean_uint8, tf.float32))
return image_mean_free
评论列表
文章目录