juvian
(julian)
January 19, 2020, 6:23pm
1
After exporting model with
learn.export(file='final model.pkl')
And trying to load it using
learn = load_learner(path=EXPERIMENT_PATH / ('bce' + str(0)), file = 'final model.pkl')
I get ValueError: num_samples should be a positive integer value, but got num_samples=0
I guess the error is related to not having data, but I just want to use it for inference. What should I do?
mschmit5
(Mike)
January 20, 2020, 3:58am
2
If the problem has to do with needing data as you say then have a look here https://docs.fast.ai/vision.data.html#ImageDataBunch.single_from_classes
juvian
(julian)
January 20, 2020, 10:33pm
3
That method is deprecated and links to use load_empty instead. load_empty docs mention
But its never used in the tutorial…
Its unclear what I need to pass it because if I pass my exported learner path and fname, it doesn’t work
mschmit5
(Mike)
January 20, 2020, 10:34pm
4
I couldn’t find a link to load_empty in the docs so I just linked to single_from_classes because it says it’s deprecated anyway
juvian
(julian)
January 20, 2020, 10:49pm
5
I guess the only way is just loading model and give it the image as tensor, normalizing + applying custom transforms manually.
Edit: found an easy hackish way: redefine len in custom itemList to return at least 1
def __len__(self):
return max(1, len(self.items))
mschmit5
(Mike)
January 20, 2020, 11:53pm
6
Did you pass it a "path"
or a Path("path")
? What error do you get?
juvian
(julian)
January 21, 2020, 12:11am
7
Passed it a Path(“path”) same as used in load_learner. Thing is load_empty expects an export of only the databunch, so it tries to unpack stuff that is not in the pkl file from learn.save, but rather the data attribute of learn.save. There is no way to tell it that though, and the fix I found is easy and short so no need to keep diving ^^