TensorFlow 提供了丰富的图像处理功能,帮助开发者实现各种图像处理任务。以下是一些常用的图像处理API:

1. tf.image

tf.image 包含了一系列用于图像处理的函数,如调整图像大小、裁剪、颜色转换等。

  • 调整图像大小: tf.image.resize
    resized_image = tf.image.resize(image, [new_height, new_width])
    
  • 裁剪图像: tf.image.crop_to_bounding_box
    cropped_image = tf.image.crop_to_bounding_box(image, y_offset, x_offset, crop_height, crop_width)
    
  • 颜色转换: tf.image.grayscale
    grayscale_image = tf.image.grayscale(image)
    

2. tf.keras.applications

tf.keras.applications 包含了一些预训练的模型,可以用于图像分类等任务。

  • VGG16: tf.keras.applications.vgg16
    model = tf.keras.applications.vgg16.VGG16(weights='imagenet')
    
  • ResNet50: tf.keras.applications.resnet50
    model = tf.keras.applications.resnet50.ResNet50(weights='imagenet')
    

3. tf.image_dataset

tf.image_dataset 是一个用于加载和预处理图像数据集的API。

  • 加载图像数据集: tf.image_dataset.from_tensor_slices
    dataset = tf.image_dataset.from_tensor_slices(image_data)
    

更多关于图像处理的API


TensorFlow 图像处理示例