Trying Sketch-Gen, derived from Paints-Undo, on Windows (VRAM 6GB or more?)
Last update 7-18-2024
*(7-18) The main text has been slightly modified (three types of models are used for line art, Num Sets refers to the number of variations, and minor corrections were made).
*Since Sketch-Gen (Sketch/Lineart extractor) is based on Paints-Undo, please be sure to check the disclaimer there before use.
▼ 0. About this article
0-1. Overview
In this article, I will introduce the steps to install and run Sketch-Gen (Sketch/Lineart extractor). The author is Kohaku Blueleaf, who also worked on LyCORIS. For information on the base, Paints-Undo, please refer to the article below.
Sketch-Gen can generate line art and sketches from images, which is called Image-to-Sketch. It can also be used for the purpose of creating pairs of images and line art/sketches.
0-2. Operating Environment
The required VRAM for Geforce appears to be 6GB or more (unconfirmed, discussed later). CUDA Toolkit 12.1 or higher is required (I have confirmed this on 12.5; 11.x has not been verified). The Python version is 3.10.
0-3. Official Repository, etc.
https://github.com/KohakuBlueleaf/Paints-UNDO
https://huggingface.co/spaces/KBlueLeaf/Sketch-Gen (Demo)
0-4. GPU Memory Usage
Dedicated GPU memory usage before startup is about 0.7GB. It spiked to about 9GB for a moment when generation started. At other times, it was generally under 6GB.

▼ 1. Installation
I will omit some explanations. Also, I am using "C:\aiwork" as the working directory, so please adjust accordingly. Basically, the procedure is the same as for Paints-Undo.
1-1. Downloading the main files
Open the command prompt and execute the following commands in order, ensuring the directory "C:\aiwork\Sketch-Gen" does not exist.
cd \aiwork
git clone -b sketch-gen https://github.com/KohakuBlueleaf/Paints-UNDO Sketch-Gen
cd Sketch-GenIf you have not installed Git, there is a green "Code" button when you access the repository; click it, select "Download ZIP," and extract the files to an appropriate directory.
1-2. Setting up the environment
Please execute the following commands in order. This will create and enter a virtual environment. During the build process, I received a warning (yellow message) regarding the installation of bitmath, so I addressed it by upgrading pip. It might not be necessary to do this.
python -m venv venv
venv\Scripts\activate
python -m pip install --upgrade pipNext, please execute the following commands in order. The first and fourth lines will take some time. Just in case, I have specified the versions of PyTorch and xFormers (the latest versions at the time of writing). Note that installing onnxruntime (the CPU version of ONNX Runtime) is not an officially documented step.
pip install torch==2.3.1 torchvision --index-url https://download.pytorch.org/whl/cu121
pip install xformers==0.0.27
pip install onnxruntime
pip install -r requirements.txtNote: ONNX Runtime
https://onnxruntime.ai/
▼ 2. Launch
2-1. How to launch
Please execute the following command. Since the model needs to be downloaded, it will take some time for the first run only.
python app.pyOnce the launch is complete, the following message will be displayed. Please access http://127.0.0.1:7860/ in your web browser. Although it is unlikely, if it is interrupted for any reason, please try launching it again.
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.2-2. Launching from the second time onwards
If you open a new command prompt, please execute the following commands in order. If you are creating a batch file, change it to "call venv\Scripts\activate.bat".
cd \aiwork\Sketch-Gen
venv\Scripts\activate
python app.py▼ 3. Operation procedure
3-1. Information
If you follow the repository's installation instructions, warning (yellow) and error (red) messages will appear while generation is in progress. Although it does not seem to affect operation, I have addressed this in this article by adding a step to install onnxruntime.
3-2. Image generation
Drag and drop any image and wait a moment; the prompt obtained by analyzing the image will be displayed. If drag and drop does not work well, click the input field to select a file.
Next, click "Generate Sketch" on the right and wait a moment; the generated images will be displayed in "Sketch Outputs" and "Line Art Outputs" respectively (on my environment, it takes about 1 minute with the default settings).

3-3. Saving images
The generated images are not saved automatically, so please save them manually. They are in WebP format.


3-5. Tips
The output of "Line Art Outputs" is constant depending on the input.
If you want to input a different image, click the [×] in the upper right of the input field to clear it.
Changing "Target size" increases or decreases GPU memory usage and the resolution of the output image. The content of "Sketch Outputs" will also change (a characteristic of Stable Diffusion).
3-6. Parameter Explanation

Settings are basically related to "Sketch Outputs". "Line Art Output" does not change based on settings (only resolution is reflected).
Output Prompt / Negative Prompt
These are the same settings as in Stable Diffusion. You can change them before executing "Generate Sketch".Operation Steps
The process from completion to a blank page is divided into 1000 steps, and you specify the state corresponding to the point after undoing the specified number of times from completion. You can specify multiple values.
Basically, set this to 900 or higher, or 950 or higher. If the value is low, it will be closer to the input image and there will be little change.
The execution time does not change depending on the numerical value.Num Sets
This is the number of sketch variations to output. For example, if you change it from 3 to 4, one new image will be added to the output content from when it was 3. Since there seems to be little change when the value is 1, please increase it to an appropriate value while monitoring the generation time.
Also, the number of images obtained by multiplying the number of set "Operation Steps" by the number of "Num Sets" will be output as "Sketch Outputs". The generation time will also increase or decrease depending on that number of images.Seed / Target size / Steps / CFG Scale
These are the same settings as in Stable Diffusion. "Target size" is the resolution of the output image.
3-7. Termination
Close the open page and close the command prompt window, or stop it with Ctrl+C.
3-8. How to uninstall
If there are any necessary files, move them, and then delete the Sketch-Gen directory while it is not running.
▼ 4. Generated images
4-1. Input image
In the Paints-UNDO article, I have posted the details including the specifics.
4-2. Line Art Outputs
These are consistent contents based on the input (each uses a different model). The reason the resolution settings are reflected is likely because the line art is used to generate the sketches.

4-3. Sketch Outputs
Here, I set Operation Steps to a single value and Num Sets to 10 to output 10 variations. As you lower Num Sets, the number of variations decreases. Note that the reason the order of the images does not necessarily look like the drawing order might be due to the behavior of Paints-Undo itself (where the drawing steps go back and forth).






You can see that as you lower the Operation Steps value, the changes decrease.
Next is an example where I set the Operation Steps values to two and halved the Num Sets. In this case, it included images that looked the same as the single Steps:995 case, as well as images that were not generated by either the single Steps:990 or single Steps:995 settings. I am not entirely sure about this behavior.

However, since the most important thing is to be able to extract the images you need, please try changing the parameters and experimenting with various settings.
▼ 5. Others
Please navigate through the menu to find other articles I have written.
My note account is linked to my main @Mayu_Hiraizumi, but please direct any inquiries regarding the articles to my sub-account @riddi0908.
