使用 sklearn load_files() 从 png 加载图像作为数据 [英] Using sklearn load_files() to load images from png as data

查看:52
本文介绍了使用 sklearn load_files() 从 png 加载图像作为数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 sklearn 构建一个简单的图像识别器.

I'm currently using sklearn to build a simple image recogniser.

我需要使用 load_files('./directory/') 从该目录中的子文件夹加载图像.

I need to use load_files('./directory/') to load images from sub-folders within that directory.

它正确获取了目标值,但数据属性不是简单的像素值.我假设我需要设置编码参数来考虑图像文件,但找不到确切使用的内容.

It correctly gets the target values but the data attributes are not simple pixel values. I assume I need to set the encoding parameter to consider the image files but can't find what exactly to use.

推荐答案

编码参数用于解码假设文本编码(例如 UTF-8)的文件内容的原始字节.

The encoding parameter is used to decode the raw bytes of the content of the files assuming a text encoding (e.g. UTF-8).

对于图像文件,您需要自己迭代 filenames 属性的内容并使用类似 scipy.misc.imread(您还需要安装 PIL 或 Pillow 包).

For image files you will need to iterate the content of the filenames attribute yourself and use something like scipy.misc.imread (you will also need to install PIL or Pillow package).

这是一个实用函数,用于将来自野外标记面孔的 jpeg 文件数据加载为 numpy 数组:

Here is a utility function to load the data of jpeg files from the Labeled Faces in the Wild as numpy arrays:

https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/lfw.py#L108

您可以使用它来了解如何编写自己的自定义数据集加载器.

You can use it to understand how to write your own custom dataset loader.

这篇关于使用 sklearn load_files() 从 png 加载图像作为数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆