Trying out style transfer with Azure Notebooks

Perhaps I'm late to the party but only just discovered the cool things you can do with a style transfer algorithm which you can try out on https://deepart.io/ and http://ostagram.ru.

Here's an example:
Senns kunstzinning This is my dog after style transfer
After doing some googling it turns out that the machine learning model is public property and can be downloaded. The academics behind it are Leon A. Gatys, Alexander S. Ecker, and Matthias Bethge by the way. I then found a blog that implemented it in a Jupyter notebook.

I wanted to find a way to use it in a web application of my own, so I tried to use Azure Machine Learning to run the code and create an API with it. I knew that Jupyter Notebooks were supported in Azure ML (although in preview).
After some trying out, I couldnt get it to work because I couldnt find versions of Pytorch and torchvision that worked with the version of Python that Azure Machine Learning uses (3.4.5).

I decided to give it a last try in Azure Notebooks. And it worked!
Turns out it uses Python 3.5 which Pytorch and Torchvision latest versions require, and the Notebook ran.

The cool thing about Jupyter notebooks is that you can mix all kinds of content like code, text, images and the output of the code. See the output of the last run of my notebook.
At the bottom you see the styled image. Too bad this is low quality, Azure Notebooks is not very powerful and it doesnt use a Graphical Processing Unit, which would be required to style high resolution images like it is done on http://deepart.io. Even with this low quality the algorithm takes 10 minutes to complete style transfer on one image.
Trying to get higher quality output results in extremely long processing times and errors due to RAM limitations. Being able to run it in Azure Machine Learning wouldnt have helpen anyway, since it also doesnt support running code on GPU.

If I would want to create a real Web App like deepart.io from this Notebook I would need to use one of the Azure Datascience Virtual Machines. Sadly, they cost about 30$ a day to run, which would max out my bankaccount pretty soon. So, not a viable option for a hobby project :-)

If you want to try out the notebook at the Pytorch blog then you need to take into account that the images you supply to it need to be perfectly square and they both need to be of the exact same resolution. But if you follow the blog and first try it with the two demo images picasso.jpg and dancing.jpg then the notebook will run in Azure Notebooks without a problem.

Show Comments