Hi
When I run this code:
learn_inf = load_learner("model.pkl")
print(learn_inf.predict('fish.jpg'))
I get this error:
Traceback (most recent call last):
File "...\test.py", line 105, in <module>
print(learn_inf.predict('fish.jpg'))
File "...\venv\lib\site-packages\fastai\learner.py", line 266, in predict
dec = self.dls.decode_batch(inp + tuplify(dec_preds))[0]
File "...\venv\lib\site-packages\fastai\data\core.py", line 80, in decode_batch
def decode_batch(self, b, max_n=9, full=True): return self._decode_batch(self.decode(b), max_n, full)
File "...\venv\lib\site-packages\fastai\data\core.py", line 79, in decode
def decode(self, b): return to_cpu(self.after_batch.decode(self._retain_dl(b)))
File "...\venv\lib\site-packages\fastai\data\core.py", line 58, in _retain_dl
if not getattr(self, '_types', None): self._one_pass()
File "...\venv\lib\site-packages\fastai\data\core.py", line 51, in _one_pass
b = self.do_batch([self.do_item(None)])
File "...\venv\lib\site-packages\fastai\data\load.py", line 133, in do_item
try: return self.after_item(self.create_item(s))
File "...\venv\lib\site-packages\fastai\data\load.py", line 140, in create_item
if self.indexed: return self.dataset[s or 0]
File "...\venv\lib\site-packages\fastai\data\core.py", line 333, in __getitem__
res = tuple([tl[it] for tl in self.tls])
File "...\venv\lib\site-packages\fastai\data\core.py", line 333, in <listcomp>
res = tuple([tl[it] for tl in self.tls])
File "...\venv\lib\site-packages\fastai\data\core.py", line 297, in __getitem__
res = super().__getitem__(idx)
File "...\venv\lib\site-packages\fastcore\foundation.py", line 111, in __getitem__
def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)
File "...\venv\lib\site-packages\fastcore\foundation.py", line 115, in _get
if is_indexer(i) or isinstance(i,slice): return getattr(self.items,'iloc',self.items)[i]
IndexError: list index out of range
In addition, when I change the code to:
files = get_image_files(TEST_FOLDER)
test_dl = learn_inf.dls.test_dl(files)
preds = learn_inf.get_preds(dl=test_dl)
I get these errors:
AttributeError: Can't get attribute 'func1' on <module '__main__' (built-in)>
and
...
File "...\conda3\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
BrokenPipeError: [Errno 32] Broken pipe
However, I’ve included def func1: ...
in this code (before load_learner) in the same way as in the network training code.
And another strange thing happens when I execute it: It seems that the entire program runs twice before getting that error! For example, I have print('hi there')
in line 1 of a .py file while the “get_preds” is in line 100. When I execute the file I can see hi there
twice in the output!
I’m rather new to fastai and I might be making some mistakes… It would be much appreciated if someone could help me.
(I’m using fastai version 2.3.1 and fastcore version 1.3.20)