How to get the label strings of the fine-tuned network using the checkpoint files or tf-record?

40 Views Asked by At

For example, I finetuned a VGG network using my own data set, with only 2 labels foo and bar. I have converted images to tf.record using an example via this link:

labels_to_class_names = dict(zip(range(len(class_names)), class_names))
dataset_utils.write_label_file(labels_to_class_names, dataset_dir)

I'm going to build an API to predict images based on this new model, my question is: Is there any formal way to get the label string from the checkpoint files, or from the data set (for example predict_image("abc.png") returns foo string)? Since I have no clue which node in the logits layer that represents label foo, and which one represents bar

I've tried searching around but no help, and I'm still a tensorflow noobie.

1

There are 1 best solutions below

0
f4. On

The model (and incidentally the checkpoint files) do not have the name of each classes. All it has is a certain number of output neurons, the first one corresponding to the first class, the second one to the second class and so on.

If you want to know which one is which, look at the label file created by this line (most likely named labels.txt):

dataset_utils.write_label_file(labels_to_class_names, dataset_dir)

Alternatively you can inspect the contents of the labels_to_class_names dict:

In [1]: class_names=['aaa', 'bbb', 'ccc']

In [2]: labels_to_class_names = dict(zip(range(len(class_names)), class_names))

In [3]: labels_to_class_names
Out[3]: {0: 'aaa', 1: 'bbb', 2: 'ccc'}

-> value at index 0 in the output of the model = class 'aaa', etc