Obtain the image from the filename (for both training and validation). The following operations are applied: - Decode the image from jpeg format - Convert to float and to range [0, 1]
(filename, label, size)
| 4 | |
| 5 | |
| 6 | def _parse_function(filename, label, size): |
| 7 | """Obtain the image from the filename (for both training and validation). |
| 8 | |
| 9 | The following operations are applied: |
| 10 | - Decode the image from jpeg format |
| 11 | - Convert to float and to range [0, 1] |
| 12 | """ |
| 13 | image_string = tf.read_file(filename) |
| 14 | |
| 15 | # Don't use tf.image.decode_image, or the output shape will be undefined |
| 16 | image_decoded = tf.image.decode_jpeg(image_string, channels=3) |
| 17 | |
| 18 | # This will convert to float values in [0, 1] |
| 19 | image = tf.image.convert_image_dtype(image_decoded, tf.float32) |
| 20 | |
| 21 | resized_image = tf.image.resize_images(image, [size, size]) |
| 22 | |
| 23 | return resized_image, label |
| 24 | |
| 25 | |
| 26 | def train_preprocess(image, label, use_random_flip): |