Reputation: 2070
I'm using slim to convert data into TF-Record format and looking at this example, where the MNIST data-set is being converted.
On lines 127
to 128
, the image png_string
is assigned a label, labels[j]
.
example = dataset_utils.image_to_tfexample(png_string, 'png'.encode(), _IMAGE_SIZE, _IMAGE_SIZE, labels[j])
I would like to add another label, but as I look to the dataset_utils
file and the image_to_tfexample
function, I see:
def image_to_tfexample(image_data, image_format, height, width, class_id):
return tf.train.Example(features=tf.train.Features(feature={
'image/encoded': bytes_feature(image_data),
'image/format': bytes_feature(image_format),
'image/class/label': int64_feature(class_id),
'image/height': int64_feature(height),
'image/width': int64_feature(width),
}))
And it seems like I would have to edit this function to add another label (add another line of image/class/label': int64_feature(class_id)
?)
I'm not entirely sure of how to add another label on which I'd like to train my neural network (maybe I'd just have to create another image_to_tfexample()
with the same image but a different label?)
Upvotes: 0
Views: 136
Reputation: 17201
Add it similar to the one you have already declared:
def image_to_tfexample(image_data, image_format, height, width, class_id, label):
return tf.train.Example(features=tf.train.Features(feature={
'image/encoded': bytes_feature(image_data),
'image/format': bytes_feature(image_format),
'image/class/label': int64_feature(class_id),
'image/label':int64_feature(label)
'image/height': int64_feature(height),
'image/width': int64_feature(width),
}))
Remove the features you are not using, it will unnecessary increase your tfrecords
size.
Upvotes: 1