Firstly I’d like to warn everyone reading this that I"m new to Python and fastai.
I’ve collected a bunch of images, ran it through this code:
dls = SegmentationDataLoaders.from_label_func(
path, bs=2, fnames = files, label_func = label_func, codes = codes, num_workers = 0 )
learn = unet_learner( dls, resnet34 )
learn.fine_tune(10)
Now I’ve got something that I can call
result1 = learn.predict(PILImage.create( 'test/result-00001-image-1.png' ))
The output of this seems to be 3 different things:
m, i, p = result1
Questions:
-
How do I “save” the learned model so that I don’t have to rerun the training everytime I open my ipynb file?
-
How do I visualize the output of the prediction? I see that I can call m.show()
but the output is very small and hard to understand. Looking at the source code there seems to be an argument that can be passed into the ‘show’ function named figsize… What does this do? I can’t find documentation on this.
- How would I overlay my result-00001-image-1.png image with the results from m, i, p to see how things look relative to the image? ie how do I convert m, i, and p, into an image that I can then composite together with the original png file?
I tried using export and load_learner. I exported the file and I can see it… but I can’t load it. I get this error:
AttributeError Traceback (most recent call last)
in
----> 1 learn = load_learner( path/‘export.pkl’ )
~\anaconda3\envs\fastAi\lib\site-packages\fastai\learner.py in load_learner(fname, cpu, pickle_module)
372 "Load a Learner
object in fname
, optionally putting it on the cpu
"
373 distrib_barrier()
→ 374 res = torch.load(fname, map_location=‘cpu’ if cpu else None, pickle_module=pickle_module)
375 if hasattr(res, ‘to_fp32’): res = res.to_fp32()
376 if cpu: res.dls.cpu()
~\anaconda3\envs\fastAi\lib\site-packages\torch\serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
592 opened_file.seek(orig_position)
593 return torch.jit.load(opened_file)
→ 594 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
595 return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
596
~\anaconda3\envs\fastAi\lib\site-packages\torch\serialization.py in _load(zip_file, map_location, pickle_module, pickle_file, **pickle_load_args)
851 unpickler = pickle_module.Unpickler(data_file, **pickle_load_args)
852 unpickler.persistent_load = persistent_load
→ 853 result = unpickler.load()
854
855 torch._utils._validate_loaded_sparse_tensors()
AttributeError: Can’t get attribute ‘label_func’ on <module ‘main’>
So it seems like my exported model won’t load … don’t know why.
I had a look at that computer vision documentation but it doesn’t say anywhere what figsize is for. What do the 2 numbers mean? ie figsize=(7,8) … what does the 7 and 8 mean in the context of the show_results output? I’ve been playing around with the numbers and nothing seems to make sense.