如何在图像数据集上添加标签进行分类? [英] how to add label to image data set for classification?

查看:2330
本文介绍了如何在图像数据集上添加标签进行分类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用安装在mac os上的python 3.6.我有存储图像名称和每个图像上的类编号的文本文件.

I am using python 3.6 installed on mac os. I have text file that store name of image and the class number of every single image on.

     #label.txt:
     img0001.jpg  1
     img0002.jpg  3
     img0003.jpg  5
     img0004.jpg  10
     img0005.jpg  6
     img0006.jpg  8
     img0007.jpg  10
     .....

我想在作为输入数据的标签,并像这样同时将图像提供给网络

I want to give them to my neural network in tensorflow as label of input data and give the image to network in same time like this

    xs = tf.placeholder(tf.float32,[None,#size of my photo]) 
    ys = tf.placeholder(tf.float32,[None,#size of my label if it is an array])

我找不到任何相关文档.有人可以高兴地告诉我该怎么办吗?

I cannot find any related documentation. could some one tell me what should i do for this pleased ?

推荐答案

假设您想知道,如何将图像及其相应的标签输入到神经网络中.

Assuming that you wanted to know, how to feed image and its respective label into neural network.

有两件事:

  1. 读取图像并将其转换为numpy数组.
  2. 将其及其对应的标签馈入网络.

Thomas Pinetz 所述,计算名称和标签后即可.创建一种标签的热编码.

As said by Thomas Pinetz , once you calculated names and labels. Create one hot encoding of labels.

from PIL import Image
number_of_batches = len(names)/ batch_size
for i in range(number_of_batches):
     batch_x = names[i*batch_size:i*batch_size+batch_size]
     batch_y = labels[i*batch_size:i*batch_size+batch_size]
     batch_image_data = np.empty([batch_size, image_height, image_width, image_depth], dtype=np.int)
     for ix in range(len(batch_x)):
        f = batch_x[ix]
        batch_image_data[ix] = np.array(Image.open(data_dir+f))
     sess.run(train_op, feed_dict={xs:batch_image_data, ys:batch_y})

这篇关于如何在图像数据集上添加标签进行分类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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