aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Mingxing Tan <tanmingxing@google.com>2017-10-20 15:33:13 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-10-20 15:38:54 -0700
commit703182d854e704ba32770342a2cac28022f7814d (patch)
tree050256d4de4101e2401120e315ac8b3b00c9dcef
parent66b1f43839ccbfe7e44df004fb92d505ab6ed942 (diff)
Add performance guide for fused decode_and_crop_jpeg optimization.
PiperOrigin-RevId: 172943116
-rw-r--r--tensorflow/docs_src/performance/performance_guide.md34
1 files changed, 34 insertions, 0 deletions
diff --git a/tensorflow/docs_src/performance/performance_guide.md b/tensorflow/docs_src/performance/performance_guide.md
index 30fb91f9d9..06bb40f64d 100644
--- a/tensorflow/docs_src/performance/performance_guide.md
+++ b/tensorflow/docs_src/performance/performance_guide.md
@@ -87,6 +87,40 @@ the Dataset API is still strongly recommended. Try to avoid the following:
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
```
+#### Fused decode and crop
+
+If inputs are JPEG images that also require cropping, use fused
+@{tf.image.decode_and_crop_jpeg} to speed up preprocessing.
+`tf.image.decode_and_crop_jpeg` only decodes the part of
+the image within the crop window. This significantly speeds up the process if
+the crop window is much smaller than the full image. For imagenet data, this
+approach could speed up the input pipeline by up to 30%.
+
+Example Usage:
+
+```python
+def _image_preprocess_fn(image_buffer):
+ # image_buffer 1-D string Tensor representing the raw JPEG image buffer.
+
+ # Extract image shape from raw JPEG image buffer.
+ image_shape = tf.image.extract_jpeg_shape(image_buffer)
+
+ # Get a crop window with distorted bounding box.
+ sample_distorted_bounding_box = tf.image.sample_distorted_bounding_box(
+ image_shape, ...)
+ bbox_begin, bbox_size, distort_bbox = sample_distorted_bounding_box
+
+ # Decode and crop image.
+ offset_y, offset_x, _ = tf.unstack(bbox_begin)
+ target_height, target_width, _ = tf.unstack(bbox_size)
+ crop_window = tf.stack([offset_y, offset_x, target_height, target_width])
+ cropped_image = tf.image.decode_and_crop_jpeg(image, crop_window)
+```
+
+`tf.image.decode_and_crop_jpeg` is available on all platforms. There is no speed
+up on Windows due to the use of `libjpeg` vs. `libjpeg-turbo` on other
+platforms.
+
#### Use large files
Reading large numbers of small files significantly impacts I/O performance.