def imagenet_preprocess_example(example, mode, resize_size=None):
"""Preprocessing used for Imagenet and similar problems."""
if resize_size is None:
resize_size = [299, 299]
def preprocess(img):
img = tf.image.resize_images(img, [360, 360])
img = common_layers.image_augmentation(
tf.to_float(img) / 255., crop_size=resize_size)
return tf.to_int64(img * 255.)
def resize(img):
return tf.to_int64(tf.image.resize_images(img, resize_size))
inputs = tf.cast(example["inputs"], tf.int64)
if mode == tf.estimator.ModeKeys.TRAIN:
example["inputs"] = tf.cond( # Preprocess 90% of the time.
tf.less(tf.random_uniform([]), 0.9),
lambda img=inputs: preprocess(img),
lambda img=inputs: resize(img))
else:
example["inputs"] = resize(inputs)
return example
评论列表
文章目录