【问题标题】:Processing an Image using Tensorflow使用 TensorFlow 处理图像
【发布时间】:2018-08-29 05:29:21
【问题描述】:

我有 15 张图片存储在本地。如何使用 TensorFlow 将这些图像转换为数组以进行 CNN 类型的分类?

【问题讨论】:

  • 两种方式:例如,您可以使用 PIL 库将图像转换为数组,然后轻松使用它们。或者你可以使用 tensorlfow 的 dataset API 对你的图片进行预处理,然后将它们传递给生成器(推荐这种方法)

标签: python tensorflow


【解决方案1】:

将图像转换为numpy数组格式

import cv2
im = cv2.imread("some_image.tiff")

将它们重塑为任意但相同的大小

def reshape(image_array):
    return np.reshape(image_array, [128, 128, 3])

将它们全部放在一个列表中,然后将它们标准化,以便它们都具有标准化的像素值:

def per_image_standardization(arrays):
    sess = tf.InteractiveSession()
    standardized_tensors = tf.map_fn(lambda array:                            
        tf.image.per_image_standardization(array), 
                                           arrays)
    standardized_images = standardized_tensors.eval()
    return standardized_images

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 1970-01-01
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2021-01-15
    相关资源
    最近更新 更多