Load and preprocess an image. Args: image: a tf.string tensor with an JPEG-encoded image. central_fraction: do a central crop with the specified fraction of image covered. Returns: An ops.Tensor that produces the preprocessed image.
(image, central_fraction=0.875)
| 55 | FLAGS = None |
| 56 | |
| 57 | def PreprocessImage(image, central_fraction=0.875): |
| 58 | """Load and preprocess an image. |
| 59 | |
| 60 | Args: |
| 61 | image: a tf.string tensor with an JPEG-encoded image. |
| 62 | central_fraction: do a central crop with the specified |
| 63 | fraction of image covered. |
| 64 | Returns: |
| 65 | An ops.Tensor that produces the preprocessed image. |
| 66 | """ |
| 67 | |
| 68 | # Decode Jpeg data and convert to float. |
| 69 | image = tf.cast(tf.image.decode_jpeg(image, channels=3), tf.float32) |
| 70 | |
| 71 | image = tf.image.central_crop(image, central_fraction=central_fraction) |
| 72 | # Make into a 4D tensor by setting a 'batch size' of 1. |
| 73 | image = tf.expand_dims(image, [0]) |
| 74 | image = tf.image.resize_bilinear(image, |
| 75 | [FLAGS.image_size, FLAGS.image_size], |
| 76 | align_corners=False) |
| 77 | |
| 78 | # Center the image about 128.0 (which is done during training) and normalize. |
| 79 | image = tf.multiply(image, 1.0/127.5) |
| 80 | return tf.subtract(image, 1.0) |
| 81 | |
| 82 | |
| 83 | def LoadLabelMaps(num_classes, labelmap_path, dict_path): |