Computer vision with TensorFlow
Stay organized with collections
Save and categorize content based on your preferences.
TensorFlow provides a number of computer vision (CV) and image classification
tools. This document introduces some of these tools and provides an overview of
resources to help you get started with common CV tasks.
TensorFlow provides CV tools through the higher-level Keras libraries and the
lower-level tf.image
module. For most use cases, the Keras libraries
will be more convenient than the built-in TensorFlow alternatives.
But if the Keras options don't fit your use case, or you want lower-level
control over image preprocessing, you might need the lower-level TensorFlow
tools.
KerasCV
If you're just getting started with a CV project, and you're not sure which
libraries and tools you'll need, KerasCV is a good
place to start. KerasCV is a library of modular CV components built on Keras
Core. KerasCV includes models, layers, metrics, callbacks, and other tools that
extend the high-level Keras API for CV tasks. The KerasCV APIs can help with
data augmentation, classification, object detection, segmentation,
image generation, and other common CV workflows. You can use KerasCV to quickly
assemble production-grade, state-of-the-art training and inference pipelines.
Keras utilities
tf.keras.utils
provides several high-level image preprocessing utilities. For
example, tf.keras.utils.image_dataset_from_directory
generates a
tf.data.Dataset
from a directory of images on disk.
If KerasCV doesn't fit your use case, you can use tf.image
and tf.data
to
write your own data augmentation pipelines or layers.
The tf.image
module contains various functions for image processing, such as
tf.image.flip_left_right
, tf.image.rgb_to_grayscale
,
tf.image.adjust_brightness
, tf.image.central_crop
, and
tf.image.stateless_random*
.
The tf.data
API enables you to build complex input pipelines from simple,
reusable pieces.
TensorFlow Datasets
TensorFlow Datasets is a collection of
datasets ready to use with TensorFlow. Many of the datasets (for example,
MNIST,
Fashion-MNIST, and
TF Flowers) can be
used to develop and test computer vision algorithms.
Where to start
The following resources will help you get up and running with TensorFlow and
Keras CV tools.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-03-23 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-03-23 UTC."],[],[],null,["# Computer vision with TensorFlow\n\n\u003cbr /\u003e\n\nTensorFlow provides a number of computer vision (CV) and image classification\ntools. This document introduces some of these tools and provides an overview of\nresources to help you get started with common CV tasks.\n\nVision libraries and tools\n--------------------------\n\nTensorFlow provides CV tools through the higher-level Keras libraries and the\nlower-level [`tf.image`](https://www.tensorflow.org/api_docs/python/tf/image) module. For most use cases, the Keras libraries\nwill be more convenient than the built-in TensorFlow alternatives.\nBut if the Keras options don't fit your use case, or you want lower-level\ncontrol over image preprocessing, you might need the lower-level TensorFlow\ntools.\n\n### KerasCV\n\nIf you're just getting started with a CV project, and you're not sure which\nlibraries and tools you'll need, [KerasCV](https://keras.io/keras_cv/) is a good\nplace to start. KerasCV is a library of modular CV components built on Keras\nCore. KerasCV includes models, layers, metrics, callbacks, and other tools that\nextend the high-level Keras API for CV tasks. The KerasCV APIs can help with\ndata augmentation, classification, object detection, segmentation,\nimage generation, and other common CV workflows. You can use KerasCV to quickly\nassemble production-grade, state-of-the-art training and inference pipelines.\n\n### Keras utilities\n\n[`tf.keras.utils`](https://www.tensorflow.org/api_docs/python/tf/keras/utils) provides several high-level image preprocessing utilities. For\nexample, [`tf.keras.utils.image_dataset_from_directory`](https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image_dataset_from_directory) generates a\n[`tf.data.Dataset`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset) from a directory of images on disk.\n\n### [`tf.image`](https://www.tensorflow.org/api_docs/python/tf/image)\n\nIf KerasCV doesn't fit your use case, you can use [`tf.image`](https://www.tensorflow.org/api_docs/python/tf/image) and [`tf.data`](https://www.tensorflow.org/api_docs/python/tf/data) to\nwrite your own data augmentation pipelines or layers.\n\nThe [`tf.image`](https://www.tensorflow.org/api_docs/python/tf/image) module contains various functions for image processing, such as\n[`tf.image.flip_left_right`](https://www.tensorflow.org/api_docs/python/tf/image/flip_left_right), [`tf.image.rgb_to_grayscale`](https://www.tensorflow.org/api_docs/python/tf/image/rgb_to_grayscale),\n[`tf.image.adjust_brightness`](https://www.tensorflow.org/api_docs/python/tf/image/adjust_brightness), [`tf.image.central_crop`](https://www.tensorflow.org/api_docs/python/tf/image/central_crop), and\n`tf.image.stateless_random*`.\n\nThe [`tf.data`](https://www.tensorflow.org/api_docs/python/tf/data) API enables you to build complex input pipelines from simple,\nreusable pieces.\n\n### TensorFlow Datasets\n\n[TensorFlow Datasets](https://www.tensorflow.org/datasets) is a collection of\ndatasets ready to use with TensorFlow. Many of the datasets (for example,\n[MNIST](https://www.tensorflow.org/datasets/catalog/mnist),\n[Fashion-MNIST](https://www.tensorflow.org/datasets/catalog/fashion_mnist), and\n[TF Flowers](https://www.tensorflow.org/datasets/catalog/tf_flowers)) can be\nused to develop and test computer vision algorithms.\n\nWhere to start\n--------------\n\nThe following resources will help you get up and running with TensorFlow and\nKeras CV tools.\n\n- [KerasCV](https://keras.io/keras_cv/): Documentation and resources for KerasCV.\n- [KerasCV developer guides](https://keras.io/guides/keras_cv/): Guides to performing common CV tasks using KerasCV. If you're new to KerasCV, [Classification with KerasCV](https://keras.io/guides/keras_cv/classification_with_keras_cv/) is a good place to start.\n- [TensorFlow tutorials](https://www.tensorflow.org/tutorials): The core\n TensorFlow documentation (this guide) includes a number of CV and image\n processing tutorials.\n\n - [Basic classification: Classify images of clothing](https://www.tensorflow.org/tutorials/keras/classification): Train a neural network model to classify images of clothing, like sneakers and shirts.\n - [Load and preprocess images](https://www.tensorflow.org/tutorials/load_data/images):\n Load and preprocess an image dataset in three ways:\n\n 1. Use high-level Keras preprocessing utilities to read a directory of images on disk.\n 2. Write your own input pipeline from scratch [using `tf.data`](https://www.tensorflow.org/guide/data).\n 3. Download a dataset from the large [catalog](https://www.tensorflow.org/datasets/catalog/overview) available in [TensorFlow Datasets](https://www.tensorflow.org/datasets).\n - [Load video data](https://www.tensorflow.org/tutorials/load_data/video):\n Load and preprocess AVI video data using the\n [UCF101 human action dataset](https://www.tensorflow.org/datasets/catalog/ucf101).\n\n - [Convolutional Neural Network (CNN)](https://www.tensorflow.org/tutorials/images/cnn):\n Train a simple [Convolutional Neural Network](https://developers.google.com/machine-learning/glossary/#convolutional_neural_network)\n (CNN) to classify\n [CIFAR images](https://www.cs.toronto.edu/%7Ekriz/cifar.html)\n using the\n [Keras API](https://www.tensorflow.org/guide/keras/overview).\n\n - [Image classification](https://www.tensorflow.org/tutorials/images/classification):\n Classify images of flowers using a [`tf.keras.Sequential`](https://www.tensorflow.org/api_docs/python/tf/keras/Sequential) model and load data\n using [`tf.keras.utils.image_dataset_from_directory`](https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image_dataset_from_directory).\n\n - [Transfer learning and fine-tuning](https://www.tensorflow.org/tutorials/images/transfer_learning):\n Classify images of cats and dogs by using transfer learning from a\n pre-trained network.\n\n - [Data augmentation](https://www.tensorflow.org/tutorials/images/data_augmentation):\n Increase the diversity of your training set by applying random (but\n realistic) transformations, such as image rotation.\n\n - [Image segmentation](https://www.tensorflow.org/tutorials/images/segmentation):\n Perform image segmentation, using a modified\n [U-Net](https://lmb.informatik.uni-freiburg.de/people/ronneber/u-net/).\n\n - [Video classification with a 3D convolutional neural network](https://www.tensorflow.org/tutorials/video/video_classification):\n Train a 3D convolutional neural network (CNN) for video classification using\n the [UCF101](https://www.crcv.ucf.edu/data/UCF101.php) action\n recognition dataset.\n\n - [Transfer learning for video classification with MoViNet](https://www.tensorflow.org/tutorials/video/transfer_learning_with_movinet):\n Use a pre-trained MoViNet model and the\n [UCF101 dataset](https://www.crcv.ucf.edu/data/UCF101.php) to\n classify videos for an action recognition task."]]