Skip to content

Instantly share code, notes, and snippets.

@ChunML
Created December 12, 2018 04:53
Show Gist options
  • Save ChunML/4b6a0ca737a4c52f295c80032c913cdf to your computer and use it in GitHub Desktop.
Save ChunML/4b6a0ca737a4c52f295c80032c913cdf to your computer and use it in GitHub Desktop.
means = [123.68, 116.779, 103.939]
def _parse_data(filename, label, new_size=224):
img_string = tf.read_file(filename)
img = tf.image.decode_jpeg(img_string)
img = tf.image.resize_images(img, (new_size, new_size))
img.set_shape([new_size, new_size, 3])
img = tf.to_float(img)
channels = tf.split(axis=2, num_or_size_splits=3, value=img)
for i in range(3):
channels[i] -= means[i]
new_img = tf.concat(axis=2, values=channels)
label = tf.cast(label, tf.int64)
return new_img, label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment