MCPcopy Create free account
hub / github.com/QWTforGithub/T2LDM / _decode_and_random_crop

Function _decode_and_random_crop

timm/data/tf_preprocessing.py:91–110  ·  view source on GitHub ↗

Make a random crop of image_size.

(image_bytes, image_size, resize_method)

Source from the content-addressed store, hash-verified

89
90
91def _decode_and_random_crop(image_bytes, image_size, resize_method):
92 """Make a random crop of image_size."""
93 bbox = tf.constant([0.0, 0.0, 1.0, 1.0], dtype=tf.float32, shape=[1, 1, 4])
94 image = distorted_bounding_box_crop(
95 image_bytes,
96 bbox,
97 min_object_covered=0.1,
98 aspect_ratio_range=(3. / 4, 4. / 3.),
99 area_range=(0.08, 1.0),
100 max_attempts=10,
101 scope=None)
102 original_shape = tf.image.extract_jpeg_shape(image_bytes)
103 bad = _at_least_x_are_equal(original_shape, tf.shape(image), 3)
104
105 image = tf.cond(
106 bad,
107 lambda: _decode_and_center_crop(image_bytes, image_size),
108 lambda: tf.image.resize([image], [image_size, image_size], resize_method)[0])
109
110 return image
111
112
113def _decode_and_center_crop(image_bytes, image_size, resize_method):

Callers 1

preprocess_for_trainFunction · 0.85

Calls 3

_at_least_x_are_equalFunction · 0.85
_decode_and_center_cropFunction · 0.85

Tested by

no test coverage detected