Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fastai show_batch and show_results does nothing

I build a model on fastai v2.3.1. When I try to call functions show_batch and show_results it does not show anything. Here is the problematic code:

from fastai.vision.all import *
from fastai.data.all import *
import fastai.vision
import zipfile as zf
import random
import timeit



fields = DataBlock(blocks=(ImageBlock, CategoryBlock),
                   get_items=get_image_files,
                   get_y=yer,
                   splitter=RandomSplitter(valid_pct=0.2, seed=random.randint(0, 10)),
                   item_tfms=RandomResizedCrop(224, min_scale=0.5),
                   batch_tfms=aug_transforms()
                   )


dls = fields.dataloaders(os.path.join(Path(os.getcwd()), "train"), num_workers=0, bs=32)

dls.show_batch()

learn = cnn_learner(dls, resnet18, metrics=error_rate)

learn.fine_tune(2)

learn.show_results()

I can use model but these functions.

like image 820
Yunus Gedik Avatar asked Oct 14 '25 14:10

Yunus Gedik


1 Answers

I ran into the same thing, found the answer here: https://www.debuggingtissue.com/latest-articles/how-to-save-fastai-plots-when-using-an-external-server-or-terminal-environment

Basically PyPlot is creating a graphics object but not displaying it, so you need to immediately tell plt to save/show the buffer.

So it's as easy as typing "plt.show()" after the show_results() call!

import matplotlib.pyplot as plt

...

learn.show_results()

plt.show()

(Took me forever to find that out, hope this helps!)

like image 140
Sandy Antunes Avatar answered Oct 17 '25 06:10

Sandy Antunes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!