Skip to content

This repo includes a guide for using the Watson Machine Learning service in IBM Cloud to perform Style Transfer in PyTorch

Notifications You must be signed in to change notification settings

ChrisParsonsDev/wml-pytorch-style-transfer

Repository files navigation

Watson Machine Learning - PyTorch Style Transfer

This readme acts as a step by step guide to using the Watson Machine Learning service for GPUs in the IBM Cloud. The code itself is for a Style Transfer workload, applying the "style" of one image to the "content" of another.

If you're interested in finding out more about style transfer check out this paper.

So what does this repo contain?

  1. pytorch-model - Location of the PyTorch script that does the style transfer.
  2. wml-style-transfer.ipynb - Notebook that executes the PyTorch script via the WML service.
  3. style-transfer-images - Location of sample images to use for Style Transfer. I'd suggest using your own though.

PyTorch Script Usage

You are of course free to use the python script ./pytorch-model/style-transfer.py anywhere you like. Actually, I'd encourage it, but you'll need either GPUs or a whole lot of time.

The script takes a couple of command line arguments to let you specify style/content images as well as the number of training iterations.

Usage:


python3 ./pytorch-model/style-transfer.py --styleImageFile ${DATA_DIR}/style.png --contentImageFile ${DATA_DIR}/content.jpeg --trainingIters 1000

Tutorial..

Create Watson Studio Service

Note It may take a few minutes for IBM Cloud to configure your Watson Studio Service instance.

  • Visit https://cloud.ibm.com/ and create a Watson Machine Learning service.

  • Click the Catalog tab and search "Watson Studio".

alt text

  • Create a "Lite" Watson Studio instance and click "Get Started"

alt text

Create a Watson Studio project

Note You'll be asked what region you'd like to create your Watson Machine Learning Service Instance in. While any region is suitable for this code lab, I'd recommend the US South region.

  • From the landing page select "create project" and select "deep learning"

alt text

alt text

This will initialise a Cloud Object Storage instance and Watson Machine Learning service automatically.

  • Name your project (something like Style Transfer) and It'll automatically connect to the WML/COS instances.

alt text

Create a Notebook asset

  • Click the "add to project" button and "notebook" to create a Jupyter notebook.

alt text

  • Select from URL and insert the URL to the Jupyter notebook in this repo.
 https://github.com/ChrisParsonsDev/wml-pytorch-style-transfer/blob/master/wml-style-transfer.ipynb

alt text

  • Choose the relevant python version/instance size

alt text

  • You'll then see Watson Studio create the notebook from our template.

alt text

Upload Style and Content images

  • Select "find and add data" it's the little icon that looks like 4 bits.

alt text

  • Download the style.jpeg and content.png images from ./style-transfer-images

  • Drag and drop them to upload them to the COS storage instance

Obtaining Credentials

Follow the instructions in the Jupyter notebook to make sure that you're inserting the credentials in the right place.

Cloud Object Storage

  • Select "Insert Credentials" to automatically import your COS credentials to the notebook. (it doesn't matter which image)

alt text

  • To connect the notebook to your WML/COS instances you'll need to obtain some API credentials. Click this link to view your resources.

alt text

  • Select "Cloud Object Storage" - it might have a name like cloud-object-storage-dsx (or similar).

  • Visit the "Service Credentials" tab.

alt text

  • Copy your "editor" credentials to clipboard

alt text

  • Paste them into the cos_credentails dictionary in the notebook.

Watson Machine learning

  • To connect the notebook to your WML/COS instances you'll need to obtain some API credentials. Click this link to view your resources.

  • Select "Watson Machine Learning" - it might have a name like pm-20-dsx (or similar).

  • Visit the "Service Credentials" tab.

  • Copy your "writer" credentials to clipboard

alt text

  • Paste them into the wml_credentials dictionary in the notebook.

Run the notebook!

  • Start running the code cells in the notebook, from the top down, to run the Style Transfer job with the WML service

  • To view the status of your job at any time run this cell:

alt text

  • The status will change to:

alt text

Seeing the results

  • To view the results of the job, you'll need to visit the COS bucket. Click this link to view your resources, select the COS bucket as before.

alt text

  • Select the trained images (they'll be called something like results****) , and "download"

alt text

  • It should look a little like this...

alt text

About

This repo includes a guide for using the Watson Machine Learning service in IBM Cloud to perform Style Transfer in PyTorch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published