Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to show images after fit? #15

Closed
turgut090 opened this issue Oct 30, 2020 · 2 comments
Closed

How to show images after fit? #15

turgut090 opened this issue Oct 30, 2020 · 2 comments

Comments

@turgut090
Copy link

Hi. The learner has a method learn.progress.show_cycle_gan_imgs. However, how to plot it with matplotlib's plt.show() if I use python repl.
There is an argument event_name in learn.progress.show_cycle_gan_imgs.
I would like to do it after fit:

>>> learn.fit_flat_lin(1,1,2e-4)
epoch     train_loss  id_loss_A  id_loss_B  gen_loss_A  gen_loss_B  cyc_loss_A  cyc_loss_B  D_A_loss  D_B_loss  time    
/home/turgut/.local/share/r-miniconda/envs/r-reticulate/lib/python3.6/site-packages/fastprogress/fastprogress.py:74: UserWarning: Your generator is empty.
  warn("Your generator is empty.")
0         10.809340   1.621755   1.690260   0.420364    0.452442    3.359353    3.504819    0.370692  0.370692  00:08     
1         9.847495    1.283465   1.510985   0.353303    0.349454    2.682495    3.135504    0.253919  0.253919  00:07 

UPIT/upit/train/cyclegan.py

Lines 167 to 176 in 020f8e2

def after_epoch(self):
"Update images"
if (self.learn.epoch+1) % self.show_img_interval == 0:
if self.imgA: self.imgA_result = torch.cat((self.learn.xb[0][1].detach(),self.learn.pred[0].detach()),dim=-1); self.last_gen=self.imgA_result
if self.imgB: self.imgB_result = torch.cat((self.learn.xb[0][0].detach(),self.learn.pred[1].detach()),dim=-1); self.last_gen=self.imgB_result
if self.imgA and self.imgB : self.last_gen = torch.cat((self.imgA_result,self.imgB_result),dim=-2)
img = TensorImage(self.learn.dls.after_batch.decode(TensorImage(self.last_gen[0]))[0])
self.imgs.append(img)
self.titles.append(f'Epoch {self.learn.epoch}')
self.progress.mbar.show_imgs(self.imgs, self.titles,imgsize=10)

@tmabraham
Copy link
Owner

tmabraham commented Oct 30, 2020

Typically I get preds on a batch and show like this:

b = dls.train.one_batch()
_,_,preds = learn.get_preds(dl=[b], with_decoded=True)

dls.show_batch((b[0], b[1]), max_n=2, show=True)
dls.show_batch((preds[0],preds[1]), max_n=2, show=True)

Check this kernel for another example (kernel on training and testing).

@turgut090
Copy link
Author

That's great! Thanks, again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants