img_to_array

as name suggests,img_to_array就是将图片转化成数组。

from keras.preprocessing.image import img_to_array
import cv2
image = cv2.imread('dcl.jpg')
print('[DEBUG]', type(image)) #  <class 'numpy.ndarray'>
image = img_to_array(image)
print('[DEBUG]', type(image)) #  <class 'numpy.ndarray'>

img_to_array 转换前后类型都是一样的,唯一区别是转换前元素类型是整型,转换后元素类型是浮点型(和keras等机器学习框架相适应的图像类型。Keras introduced a special function called img_to_array which accepts an input image and then orders the channels correctly based on the image_data_format setting)。

在 /.keras/keras.json.文件下,有如下的设置:

{
"epsilon": 1e-07,
"floatx": "float32",
"image_data_format": "channels_last",
"backend": "tensorflow"
}

image_data_format 有两个值:
channels_last
channels_first

由于历史原因,
tensorflow中为channels_last,即图片格式为(heights,weights,channels)
theano中为channels_first,即图片格式为(channels,heights,weights)

为了兼容 tensorflow 和 theano 两种后端,所以有了 img_to_array 。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值