Painting style transfer on photos
We aim to quickly and easly make our own favorite pictures look like a famous painter production. Hence we provide an easy way to provide some style examples and our personal pictures. It's even possible to blend styles.
Core engine provide from https://github.com/titu1994/Neural-Style-Transfer.git and has been made by Somshubra Majumdar. We thank him cheerly for his great job.
What is it ?
Clever Grid is a GPU as a Service platform allowing any developer or data scientist to train their Machine Learning models seamlessly. They only have to provide the necessary code. No tidious driver configuration and dependency management is involved except the code dependencies.
How it Works
Based on Clever Cloud, Clever Grid provides two running modes.
- Runner : Run a script just once. It can be used to train networks
- Web service : Build a Web service and put it in production
These instances are stateless !! It means that data stored on disk cannot be saved. You need to use an add-on like Cellar instead. Cellar is Clever Cloud's S3 API compatible object storage
These instances run the provided code.
Setup is done using environment variables. This is for example how you specify the starting script (in Bash or Python).
for further information, refer to https://www.clever-cloud.com/doc/
Painting style transfer on photos
We only need a start.sh file (which can also be a python file -> don't forget to change the starting env variable). Here's what we need to do:
- First we get the data source from our Cellar source bucket. They are the pictures we want to apply style on
- We get some painting we want to use as style source from Cellar
- We run Somshubra Majumdar's awesome script with the needed arguments. (It can be adjusted for better results. Ref on Somshubra Majumdar's documentation)
- We send the result back to our Cellar bucket
Needed Environment Variables:
To manage storage:
BUCKET_RESULT BUCKET_SOURCE BUCKET_STYLE
To manage Cellar add-on:
CELLAR_ADDON_HOST CELLAR_ADDON_KEY_ID CELLAR_ADDON_KEY_SECRET
These are automatically setup when an Addon is linked to an Application
We use three additional python files to get and send data in Cellar : bucket_management.py, get_bucket_content.py, send_to_bucket.py
We provide some helpers python script based on .env file.
environment variables must be the same than in the Clever Grid application
Helper Usage :
python cl_get_results.py param
param is a destination folder where we get results from buckets
python cl_send_source.py param
param is the source folder where pictures to process are stored
python cl_get_style.py param
param is the style folder where painting style examples are stored
Quick Start :
You need the Clever Cloud CLI client. See: https://www.clever-cloud.com/doc/clever-tools/getting_started/
If you do not have a Clever Cloud account, you can get on for free here: https://api.clever-cloud.com/v2/sessions/signup
Steps 5 to 8 are to help you send your data into a Cellar storage object.
Login to your Clever Grid Account
Link to your python_ml runner application
clever link <APP_ID>
You need a strong enough instance of your application for this task. Use at least a size L
You need to have a Python Runner application in https://dashboard.clevergrid.io (see the section : Create an application on Clever Grid)
<APP_ID> can be find on the application overview page
Add your clever grid application repository to your current git project :
git remote add clever git+ssh://firstname.lastname@example.org/<YOUR_APP_ID>.git
note the <YOUR_APP_ID> field
Set the needed environment variables:
This example run with python 3.6
- In the Environment Variables menu under our Application menu in the clever grid console
Whit the clever CLI (Command Line tools) :
clever env set BUCKET_RESULT <BUCKET_RESULT_NAME> clever env set BUCKET_SOURCE <BUCKET_SOURCE_NAME> clever env set BUCKET_STYLE <BUCKET_STYLE_NAME> clever env set CC_MLPYTHON_START_SCRIPT "start.sh" clever env set CC_PYTHON_VERSION "3.6"
(optional) install required packages:
Needed for helpers scripts
pip install boto filechunkio python-dotenv
(optional) set up a .env file with the same environment variables than in the Clever Grid application
this step allow you to use helpers python script to send your data to Cellar
echo "BUCKET_RESULT=<BUCKET_RESULT_NAME>" > .env echo "BUCKET_SOURCE=<BUCKET_SOURCE_NAME>" >>.env echo "BUCKET_STYLE=<BUCKET_STYLE_NAME>" >> .env
(optional) use helpers scripts to send your data to Cellar and uncomment the dedicated part in
This part allow you to send your own data instead of the examples ones
python cl_send_source.py picture_source_folder python cl_send_style.py.py style_source_folder
(optional) commit changes in the
git add start.sh git commit -m "update start.sh to use personal data"
push the code to your application:
git push clever
clever is the remote Clever Grid git repository name
Finally start your application with
for all restart, use clever restart instead of deploy
Wait until the end (see logs into the console or in your terminal). Then get the result:
python cl_get_results.py dest_folder
Create an application on Clever Grid
- login to https://dashboard.clevergrid.io
- choose your organisation
- create an application
- select the Python Runner and name it
- choose your instance size and the number of nodes needed
Issues and Limits
This is a quick usage demonstration of Clever Grid. It is not optimized and the usage of to many style source files and pictures to treat can raise an OOM (Out Of Memory) during the execution !