MCPcopy Create free account
hub / github.com/amazon-science/mm-cot / preprocess_for_eval

Function preprocess_for_eval

timm/data/tf_preprocessing.py:161–178  ·  view source on GitHub ↗

Preprocesses the given image for evaluation. Args: image_bytes: `Tensor` representing an image binary of arbitrary size. use_bfloat16: `bool` for whether to use bfloat16. image_size: image size. interpolation: image interpolation method Returns: A preprocessed

(image_bytes, use_bfloat16, image_size=IMAGE_SIZE, interpolation='bicubic')

Source from the content-addressed store, hash-verified

159
160
161def preprocess_for_eval(image_bytes, use_bfloat16, image_size=IMAGE_SIZE, interpolation='bicubic'):
162 """Preprocesses the given image for evaluation.
163
164 Args:
165 image_bytes: `Tensor` representing an image binary of arbitrary size.
166 use_bfloat16: `bool` for whether to use bfloat16.
167 image_size: image size.
168 interpolation: image interpolation method
169
170 Returns:
171 A preprocessed image `Tensor`.
172 """
173 resize_method = tf.image.ResizeMethod.BICUBIC if interpolation == 'bicubic' else tf.image.ResizeMethod.BILINEAR
174 image = _decode_and_center_crop(image_bytes, image_size, resize_method)
175 image = tf.reshape(image, [image_size, image_size, 3])
176 image = tf.image.convert_image_dtype(
177 image, dtype=tf.bfloat16 if use_bfloat16 else tf.float32)
178 return image
179
180
181def preprocess_image(image_bytes,

Callers 1

preprocess_imageFunction · 0.85

Calls 1

_decode_and_center_cropFunction · 0.85

Tested by

no test coverage detected