Untill version 1.0.39 models for inference needed to export 2 files:
1 file with data.export()
1 file with model.save()
Then during inference, the list of the class names were recover like this:
empty_data = ImageDataBunch.load_empty()
empty_data.classes --> gives the list of all the classes used during training
Since fastai version 1.0.40 we can export model directly with:
model.export()
This is great because we can do inference using only the “export.pkl” file.
The problem is that I can’t recover the list of class names.
I tried
empty_data = ImageDataBunch.load_empty(“export.pkl”) but I always have an error:
Key_error: ‘x_cls’
When I create the model like this:
model = load_learner(“export.pkl”)
I’m able to make prediction one image at a time with model.predict(img)
It gives the class Name so it means that the names of all the classes are embedded in the file “export.pkl”
How is it possible to get the list of the class names ?
Great. It works. Thanks a lot Sylvain for the quick answer !!!
What is strange is that if I try:
model.data. and try the autocompletion,it doesn’t propose “classes” attribute.
Nevertheless, you told me the solution : …
In a notebook, the auto-completion only works on the first level object: if you type model.data, then data.cl… it will suggest classes in auto-completion, but not when you type model.data.cl…
Not sure this explains what’s going on. When I type ‘data.[tab]cl’, I do not see data.classes autocomplete. But when I type ‘data.classes’, it gives back the list of classes.
Hi @pabsanort the way this information is accessed is different now. When using version 2.7.9 you can see the class names by calling learn.dls.vocab – to see the number of classes you could try learn.dls.c – hope this helps!