什么是Keras img_to_array? (与C#中的Bitmap数组相比)

问题描述 投票:0回答:1

我想了解什么是keras.preprocessing.image.img_to_array

https://github.com/tensorflow/tensorflow/blob/r1.8/tensorflow/python/keras/_impl/keras/preprocessing/image.py

当我查看数组的内容时,它们如下(所有元素都在float中):

image1 = img_to_array(image.load_img(ImagePath, target_size=(128,128))) / 255

[0.16470588743686676, 0.3019607961177826, 0.07450980693101883], [0.1we23423423486676, 0.3023423423423423, 0.01353463453458483] ......

它们似乎是图像的RGB通道,但为什么它是分数?但是,如果我在C#中查看位图,它们是整数,如(Alpha,R,G,B)

[100,123,024,132],[021,055,243,015].... 

有人可以解释一下从C#中的img_to_array和Bitmap数组格式生成的图像数组的区别是什么?

谢谢,PCG

c# keras rgb
1个回答
3
投票

img_to_arrayKeras implementation的文档中得到了很好的解释:

def img_to_array(img, data_format='channels_last', dtype='float32'):
    """Converts a PIL Image instance to a Numpy array.
    # Arguments
        img: PIL Image instance.
        data_format: Image data format,
            either "channels_first" or "channels_last".
        dtype: Dtype to use for the returned array.
    # Returns
        A 3D Numpy array.
    # Raises
        ValueError: if invalid `img` or `data_format` is passed.
    """

所以它将采用PIL Image实例并将其转换为numpy数组,使用dtype float32。如果从PNG图像开始,图像内的值将介于0和255之间。这通常由8位无符号整数表示;然而,img_to_array将被抛弃。在您的代码示例中,数组除以255,这就是为什么您最终得到0到1之间的浮点数。

© www.soinside.com 2019 - 2024. All rights reserved.