Skip to content
Great demo for clevergrid usage
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
source_images
style_images
README.md
bucket_management.py
cl_get_results.py
cl_send_source.py
cl_send_style.py
get_bucket_content.py
requirements.txt
send_to_bucket.py
start.sh upadte readme and start.sh. Adding demo photos Jun 26, 2019

README.md

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.

Clever Grid

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.

  1. Runner : Run a script just once. It can be used to train networks
  2. 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

Explaination

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:

  1. To manage storage:

    BUCKET_RESULT
    BUCKET_SOURCE
    BUCKET_STYLE
    
  2. 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

Helpers

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.

  1. Login to your Clever Grid Account

    clever login
    
  2. 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

  3. Add your clever grid application repository to your current git project :

    git remote add clever git+ssh://git@ppush-clevergrid-clevercloud-customers.services.clever-cloud.com/<YOUR_APP_ID>.git
    

    note the <YOUR_APP_ID> field

  4. 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

OR

  • 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"
    
  1. (optional) install required packages:

    Needed for helpers scripts

    pip install boto filechunkio python-dotenv
    
  2. (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
    
  3. (optional) use helpers scripts to send your data to Cellar and uncomment the dedicated part in start.sh:

    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
    
  4. (optional) commit changes in the start.sh file :

    git add start.sh
    git commit -m "update start.sh to use personal data"
    
  5. push the code to your application:

    git push clever
    

    clever is the remote Clever Grid git repository name

  6. Finally start your application with

    clever deploy
    

    for all restart, use clever restart instead of deploy

  7. 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

  1. login to https://dashboard.clevergrid.io
  2. choose your organisation
  3. create an application
  4. select the Python Runner and name it
  5. 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 !

You can’t perform that action at this time.