Using the superres GAN in a loop

I would like to use the superres GAN from Lesson 7 in an RNN-like loop: I have an input image x, and would like to produce f(x), f(f(x)), etc, saving each as a file.

Is there a “natural” way to do this using the fastai lib?

Cheers

I’d think the fastest way is to make a test set, and then run get_preds(), from those predictions go through them all and save them, that way you get GPU access. Otherwise learn.predict()

So you recommend making a test set from the single input image?

Yep. If you have a set number of predictions you want, make a test set where the entire input is the exact same image.

Hmm sorry I don’t get it :smile_cat:

I want to feed the output of one step back in as input for the next step, I don’t get how it would be useful to have many copies of the initial image as input.

Ah! My bad, that would make more sense then!

I’d recommend a little loop that looks something like this:

fname = 'orig'
ext = '.jpg'
im = open_image(fname+ext)
new = fname
for x in range(5):
  im = open_image(new+ext)
  res = learn.predict(im)
  new = fname + f'{x}'
  res[img].save(new + ext)

Where the original fname is the name of your original image, and img is the index in the results that is the picture (look at the results from learn.predict() to find this)

1 Like

Thanks! :+1::+1: I was thinking along those lines as well.