preface

Recently I saw an interesting project that can generate corresponding abstract paintings from photos.

Project address: Github address

Take a look at the renderings provided by the project.

Is not very interesting, I decided to get the project down to play by myself. Below I share the installation process for your reference.

The installation

Let’s start with the installation instructions given by the author.

The author gives docker installation mode and PIP installation mode. In many previous articles, I used PIP for installation and deployment. This time, I decided to be lazy and use docker mode. Now let’s talk about my installation process, for those of you who haven’t done this before.

Pull the mirror

Follow the author’s instructions to pull the image from the prepared server with the graphics card.

docker pull yaelvinker/clipasso_docker

This command takes a long time. You’ll have to wait.

Start the container

After the image is pulled, I use the following startup command:

docker run –name=hy-c -itd –restart=always –gpus all –shm-size 16G -p 2281:22 –log-opt max-size=50m –log-opt max-file=10 yaelvinker/clipasso_docker

Did not follow the author to provide the command, I make a note here.

1. Map the external graphics card to the container.

Port 22 is mapped to port 2281 for pycharm debugging. If you are interested, please refer to it

Pycharm code docker container runs debugging

If you don’t need similar debugging, you can remove this part of the command.

Pull the project

cd /home
git clone https://github.com/yael-vinker/CLIPasso.git
cd CLIPasso/
Copy the code

The directory structure is as follows

use

Before using it, let’s take a look at some parameter explanations given by the author.

Optional arguments:

  • --num_strokes Defines the number of strokes used to create the sketch, which determines the level of abstraction. The default value is set to 16, but for different images, different numbers might produce better results.
  • --mask_object It is recommended to use images without a background, however, if your image contains a background, you can mask it out by using this flag with “1” as an argument.
  • --fix_scale If your image is not squared, it might be cut off, it is recommended to use this flag with 1 as input to automatically fix the scale without cutting the image.
  • --num_sketches As stated in the paper, by default there will be three parallel running scripts to synthesize three sketches and automatically choose the best one. However, for some environments (for example when running on CPU) this might be slow, so you can specify –num_sketches 1 instead.
  • -cpu If you want to run the code on the cpu (not recommended as it might be very slow).

Just a quick explanation

1. The first parameter –num_strokes is mainly used to identify the stroke number level, and the default value is 16. In short, the larger the number, the more detailed the picture, the smaller the number, the more abstract the picture.

2. The second argument, mask_object, is used to subtract the background, using 1 if necessary.

3. The third parameter –fix_scale is used to configure whether or not the image should be cut. If not, the project will first convert the image to a 1:1 resolution.

4. The fourth parameter, num_sketches, defaults to 3 runs and takes the best one. If you only want one run, configure 1.

5, the fifth parameter whether to use CPU, not detailed.

The sample a

Here is the first image prepared, with a solid white background.

Execute the following command

python run_object_sketching.py --target_file "changjinglu.jpg"
Copy the code

The execution result

Let’s see what happens

You can see that it ran three times.

It’s quite interesting. The general outline is quite clear.

The sample 2

For the second picture I picked one with a background.

Execute the following command

python run_object_sketching.py --target_file "redainiao.jpg" --num_strokes 8 --num_sketches 1 --mask_object 1 --fix_scale 1
Copy the code

In terms of parameters, I reduced the number of strokes and needed to deduct the background and keep the original scale.

The execution result

Let’s see what happens

The overall image is still very good, very clear to see the outline of the bird.

The sample of three

For the third picture, I found a portrait of Mona Lisa, mainly to see the abstract painting effect of oil painting without touching the background.

Execute the following command

python run_object_sketching.py --target_file "mengnalisha.jpg" --num_strokes 32 --num_sketches 1 --fix_scale 1
Copy the code

For the parameters, I added some strokes, keeping the scale and not the background.

The execution result

Let’s see what happens

Ha ha ha, very funny, although the effect is not very good, and I may set the number of strokes is too small. Just to keep you in suspense, if you’re interested you can add more strokes to see what happens.

Supplement (critical)

Take a look at this code.

During containerized deployment installation, the image comes with this preprocessing model. If PIP installation, need to download their own, Google cloud disk, understand all understand. So I put the model on my Baidu cloud disk. If you need it, you can download it from the link below.

Link: pan.baidu.com/s/1sHDJu8XS… Extraction code: TUAN

conclusion

It has been a long time since I wrote this series on machine learning. In fact, I have many interesting projects in my collection on Github, which I will play with whenever I have time. If you have time, you can also change the project into a tool to share, but I am busy recently, and I am researching something new.

Sharing:

Yet high over the city our line of yellow windows must have contributed their share of human secrecy to the casual watcher in the darkening streets, and I was him too, looking up and wondering. I was within and without, Enchanted and repelled by the inexhaustible variety of life. -- The Great GatsbyCopy the code

If this article helped you, please give it a thumbs up. Thanks!

My CSDN home page address: Swordsman Aliang’s home page

Learn together and make progress together.