tensorflow生成图片标签_tensorflow – 用图像和多标签写入tfrecords进行分类

我想用TensorFlow执行多标签分类.

我有大约95000张图像,每张图像都有一个相应的标签矢量.每张图片都有7个标签.这7个标签表示为尺寸为7的张量.每个图像的形状为(299,299,3).

我现在如何将带有相应标签矢量/张量的图像写入.tfrecords文件

我目前的代码/方法:

def get_decode_and_resize_image(image_id):

image_queue = tf.train.string_input_producer(['../../original-data/'+image_id+".jpg"])

image_reader = tf.WholeFileReader()

image_key, image_value = image_reader.read(image_queue)

image = tf.image.decode_jpeg(image_value,channels=3)

resized_image= tf.image.resize_images(image, 299, 299, align_corners=False)

return resized_image

init_op = tf.initialize_all_variables()

with tf.Session() as sess:

# Start populating the filename queue.

sess.run(init_op)

coord = tf.train.Coordinator()

threads = tf.train.start_queue_runners(coord=coord)

# get all labels and image ids

csv= pd.read_csv('../../filteredLabelsToPhotos.csv')

#create a writer for writing to the .tfrecords file

writer = tf.python_io.TFRecordWriter("tfrecords/data.tfrecords")

for index,row in csv.iterrows():

# the labels

image_id = row['photo_id']

lunch = tf.to_float(row["lunch"])

dinner= tf.to_float(row["dinner"])

reservations= tf.to_float(row["TK"])

outdoor = tf.to_float(row["OS"])

waiter = tf.to_float(row["WS"])

classy = tf.to_float(row["c"])

gfk = tf.to_float(row["GFK"])

labels_list = [lunch,dinner,reservations,outdoor,waiter,classy,gfk]

labels_tensor = tf.convert_to_tensor(labels_list)

#get the corresponding image

image_file= get_decode_and_resize_image(image_id=image_id)

#here : how do I now create a TFExample and write it to the .tfrecords file

coord.request_stop()

coord.join(threads)

在我创建.tfrecords文件之后,我可以从TensorFlow培训代码中读取它并自动批处理数据吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值