I want to perform multi-label classification using TensorFlow. I have about 95,000 images, and for each image there is a corresponding label vector. There are 7 shortcuts for each image. These 7 marks are presented as a tensor of size 7. Each image has a shape (299,299.3).
How can I now write an image with the corresponding label vector / tensor to a .tfrecords file
my current code / approach:
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:
sess.run(init_op)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
csv= pd.read_csv('../../filteredLabelsToPhotos.csv')
writer = tf.python_io.TFRecordWriter("tfrecords/data.tfrecords")
for index,row in csv.iterrows():
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)
image_file= get_decode_and_resize_image(image_id=image_id)
coord.request_stop()
coord.join(threads)
And after I created the .tfrecords file, can I then read it from my TensorFlow Training Code and load the data automatically?
ZCDEV source
share