Updating old fasiai notebook

I finished part 1 of the course, and thought I might begin coding my own stuff. I found style transfer really interesting, and wanted to try it out myself. I was given a link to an old lecture with this notebook: courses/dl2/style-transfer.ipynb

The problem is that it is using an old version of the fastai library. I would love to implement this kind of style transfer, using the new library.

So is there already a newer version of this notebook out there? Or would any of you be willing to help me figure out the new equivalents to the old code?

I would just follow the steps explained in the video, but I am fairly new to fastai, and python. So the whole thing is just a bit overwhelming.

Thanks in advance.

I have the same approach for style transfer implemented in v2 here: https://github.com/muellerzr/Practical-Deep-Learning-for-Coders-2.0/blob/master/Computer%20Vision/05_Style_Transfer.ipynb

Ahhh beautiful. And with lots of comments. You just saved me a huge headache. Thank you so much.

I am trying to implement it in v1. Just slowly going through it to gain a good understanding of all the things. The versions are not that different, so I have not had that much trouble so far, but this method has given me some trouble:

def get_style_im(url):
  download_url(url, 'style.jpg')
  fn = 'style.jpg'
  dset = Datasets(fn, tfms=[PILImage.create])
  dl = dset.dataloaders(after_item=[ToTensor()], after_batch=[IntToFloatTensor(), Normalize.from_stats(*imagenet_stats)], bs=1)
  return dl.one_batch()[0]

So from what I can understand, this is supposed to take our image, and make it into a batch the model can use. So my V1 version is:

data = (ImageList.from_folder(FolderPath)
        .filter_by_func(lambda fname: Path(fname).name == StyleImageName)
        .transform(normalize(imagenet_stats), size=128)

But this does not work. Right now it is specifically the ‘normalize(imagenet_stats)’ i can’t get to work. How would i normalize it by the imagenet stats? Is this even remotely close to a similar solution?