Code Monkey home page Code Monkey logo

virtual_sketching's Introduction

General Virtual Sketching Framework for Vector Line Art - SIGGRAPH 2021

[Paper] | [Project Page] | [中文Readme] | [中文论文介绍]

This code is used for line drawing vectorization, rough sketch simplification and photograph to vector line drawing.

    

Outline

Dependencies

Testing with Trained Weights

Model Preparation

Download the models here:

  • pretrain_clean_line_drawings (105 MB): for vectorization
  • pretrain_rough_sketches (105 MB): for rough sketch simplification
  • pretrain_faces (105 MB): for photograph to line drawing

Then, place them in this file structure:

outputs/
    snapshot/
        pretrain_clean_line_drawings/
        pretrain_rough_sketches/
        pretrain_faces/

Usage

Choose the image in the sample_inputs/ directory, and run one of the following commands for each task. The results will be under outputs/sampling/.

python3 test_vectorization.py --input muten.png

python3 test_rough_sketch_simplification.py --input rocket.png

python3 test_photograph_to_line.py --input 1390.png

Note!!! Our approach starts drawing from a randomly selected initial position, so it outputs different results in every testing trial (some might be fine and some might not be good enough). It is recommended to do several trials to select the visually best result. The number of outputs can be defined by the --sample argument:

python3 test_vectorization.py --input muten.png --sample 10

python3 test_rough_sketch_simplification.py --input rocket.png --sample 10

python3 test_photograph_to_line.py --input 1390.png --sample 10

Reproducing Paper Figures: our results (download from here) are selected by doing a certain number of trials. Apparently, it is required to use the same initial drawing positions to reproduce our results.

Additional Tools

a) Visualization

Our vector output is stored in a npz package. Run the following command to obtain the rendered output and the drawing order. Results will be under the same directory of the npz file.

python3 tools/visualize_drawing.py --file path/to/the/result.npz 

b) GIF Making

To see the dynamic drawing procedure, run the following command to obtain the gif. Result will be under the same directory of the npz file.

python3 tools/gif_making.py --file path/to/the/result.npz 

c) Conversion to SVG

Our vector output in a npz package is stored as Eq.(1) in the main paper. Run the following command to convert it to the svg format. Result will be under the same directory of the npz file.

python3 tools/svg_conversion.py --file path/to/the/result.npz 
  • The conversion is implemented in two modes (by setting the --svg_type argument):
    • single (default): each stroke (a single segment) forms a path in the SVG file
    • cluster: each continuous curve (with multiple strokes) forms a path in the SVG file

Important Notes

In SVG format, all the segments on a path share the same stroke-width. While in our stroke design, strokes on a common curve have different widths. Inside a stroke (a single segment), the thickness also changes linearly from an endpoint to another. Therefore, neither of the two conversion methods above generate visually the same results as the ones in our paper. (Please mention this issue in your paper if you do qualitative comparisons with our results in SVG format.)


Training

Preparations

Download the models here:

  • pretrain_neural_renderer (40 MB): the pre-trained neural renderer
  • pretrain_perceptual_model (691 MB): the pre-trained perceptual model for raster loss

Download the datasets here:

  • QuickDraw-clean (14 MB): for clean line drawing vectorization. Taken from QuickDraw dataset.
  • QuickDraw-rough (361 MB): for rough sketch simplification. Synthesized by the pencil drawing generation method from Sketch Simplification.
  • CelebAMask-faces (370 MB): for photograph to line drawing. Processed from the CelebAMask-HQ dataset.

Then, place them in this file structure:

datasets/
    QuickDraw-clean/
    QuickDraw-rough/
    CelebAMask-faces/
outputs/
    snapshot/
        pretrain_neural_renderer/
        pretrain_perceptual_model/

Running

It is recommended to train with multi-GPU. We train each task with 2 GPUs (each with 11 GB).

python3 train_vectorization.py

python3 train_rough_photograph.py --data rough

python3 train_rough_photograph.py --data face

Citation

If you use the code and models please cite:

@article{mo2021virtualsketching,
  title   = {General Virtual Sketching Framework for Vector Line Art},
  author  = {Mo, Haoran and Simo-Serra, Edgar and Gao, Chengying and Zou, Changqing and Wang, Ruomei},
  journal = {ACM Transactions on Graphics (Proceedings of ACM SIGGRAPH 2021)},
  year    = {2021},
  volume  = {40},
  number  = {4},
  pages   = {51:1--51:14}
}

Projects Using this Model/Method

Painterly style transfer (TVCG 2023) Robot calligraphy (ICRA 2024)
Geometrized cartoon line inbetweening (ICCV 2023) Stroke correspondence and inbetweening (TOG 2024)
Modelling complex vector drawings (ICLR 2024)

virtual_sketching's People

Contributors

markmohr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

virtual_sketching's Issues

The paper's code seems not being here

Hello,

I just have read your paper and got so interested in this project, but when I followed the link to this github page, it seems like there is no implementation code here. Could I ask will they be upload in the further and when?

Thank you very much!
Tan

Setting same init cursors position for all test images

Hey, can you please tell me how should I set the same initial cursor position for all the images for which I perform vectorization. And does setting the same init cursor results in same stroke data every time?

Thank you.

关于Vgg16微调

作者您好,我想问一下,在微调vgg16的过程中,是以345种类别的数据,训练几次呢?我发现vgg16训练过多的次数后,好像反而不利于sketching模型的收敛

Train the neural renderer

Hi Mark,

Thank you for your excellent and impressive work.
I would like to train the neural renderer myself. However, if I generate a random stroke (i.e. a single fixed-width line, say wideth=3) and use L-2 loss, the trained neural renderer will output a solid dark image. I think it is due to the small difference between the dark image and the one with a single line. I cannot find the code for training the neural renderer. Could you please share small ideas or the code you used to train it?

Best regards,
Rongkai

Fine tuning on other data

Hello! Great work!
I was wondering is there a way to fine-tune your pretrained model for vectorization.
In train_vectorization.py file, if I'm not mistaken,there is only a cold start variant of training(I mean, pre-trained clean_vectorization module was not loaded). Training from the without pretrained model was working fine, but when I tried to load from clean_vectorization_model(by adding load_checkpoint(sess,model_dir, gen_model_pretrain=True)) I encountered following error(about architecture missmatching)

2 root error(s) found.

(0) Invalid argument: tensor_name = Variable_1; expected dtype int32 does not equal original dtype float
tensor_name = Variable_3; expected dtype float does not equal original dtype int32
[[node save_1/RestoreV2 (defined at /opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py:1748) ]]
[[save_1/RestoreV2/_271]]
(1) Invalid argument: tensor_name = Variable_1; expected dtype int32 does not equal original dtype float
tensor_name = Variable_3; expected dtype float does not equal original dtype int32
[[node save_1/RestoreV2 (defined at /opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py:1748) ]]
0 successful operations.
0 derived errors ignored.

Original stack trace for 'save_1/RestoreV2':
File "train_vectorization.py", line 319, in
main()
File "train_vectorization.py", line 315, in main
trainer(model_params)
File "train_vectorization.py", line 296, in trainer
load_checkpoint(sess, '/logs/snapshot/pretrain_clean_line_drawings', gen_model_pretrain=True)
File "/code/virtual_sketching/utils.py", line 51, in load_checkpoint
restorer = tf.train.Saver(load_var)
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/training/saver.py", line 828, in init
self.build()
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/training/saver.py", line 840, in build
self._build(self._filename, build_save=True, build_restore=True)
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/training/saver.py", line 878, in _build
build_restore=build_restore)
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/training/saver.py", line 508, in _build_internal
restore_sequentially, reshape)
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/training/saver.py", line 328, in _AddRestoreOps
restore_sequentially)
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/training/saver.py", line 575, in bulk_restore
return io_ops.restore_v2(filename_tensor, names, slices, dtypes)
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/ops/gen_io_ops.py", line 1696, in restore_v2
name=name)
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/framework/op_def_library.py", line 794, in _apply_op_helper
op_def=op_def)
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 3357, in create_op
attrs, op_def, compute_device)
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 3426, in _create_op_internal
op_def=op_def)
File "/opt/anaconda3/envs/virtual_sketching/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 1748, in init
self._traceback = tf_stack.extract_stack()

I figured out that likely the problem was that the class for Virtual_Sketching are different for training and testing . From the error logs above it is hard to tell where exactly the problem is. Maybe you already encounter this kind of situation-error. I will be very grateful , if you could suggest some solutions or where to look at or maybe tell the right way to do fine-tuning.

Requires Matplotlib

Looks like matplotlib is required for this, but its not in the requirements listed on the readme

#utils.py
import matplotlib.pyplot as plt

有关model_common_train代码中的问题

作者您好,请问model_common_train.py的931行代码
filter_curr_stroke_image_soft = tf.multiply(tf.subtract(1.0, curr_state_soft), curr_stroke_image_large)
这里是不是应该改为
filter_curr_stroke_image_soft = tf.multiply(curr_state_soft, curr_stroke_image_large)
不需要tf.subtract(1.0, curr_state_soft)这个一步操作

Questions of the loss weight reg

Hi, thank you for the great work. We ran into a small problem. The model always generated sketches with more than 300 strokes. We hope to get sketches with fewer but longer strokes. In the Figure 13 of the main paper, the length of the strokes is highly correlated to the loss weight of reg. But we find only weight 0.1 is released in your trained model. Could you please share models with a larger weight(e.g. 1.0)? Or other solutions to get strokes as long as possible? Many thanks!

关于光标初始位置是否随机选取?

您好!

我们已成功复现了您的工作,并且取得了非常理想的效果。目前,我们正尝试将您的工作应用于我们自己的数据集进行可视化处理。在此过程中,我有一个问题想要咨询您:关于光标的初始位置是否是随机选取的。我注意到您在论文中提到了是 Q_0 随机确定的。

期待您的回复,谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.