Make a random crop of image_size.
(image_bytes, image_size, resize_method)
| 89 | |
| 90 | |
| 91 | def _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 | |
| 113 | def _decode_and_center_crop(image_bytes, image_size, resize_method): |
no test coverage detected