DiffBMP: Fast Differentiable Painting with Any Image Primitives
Project description
DiffBMP
Overview
DiffBMP provides tools and methodologies for fast differentiable painting with any image primitives. It includes initialization techniques, rendering methods, and evaluation scripts aimed at comparing the effectiveness and quality of various vector art generation algorithms.
Installation
From PyPI (Recommended)
pip install pydiffbmp
System Requirements:
- Python: 3.8, 3.9, 3.10, or 3.11
- Platform: Linux x86_64 (pre-built CUDA binaries included)
- GPU: NVIDIA GPU with CUDA capability 8.6+ (RTX 3090, A100, RTX 4090, L40S, etc.)
- CUDA Driver: 11.8+ (no CUDA toolkit installation required)
- PyTorch: 1.13.0+
Additional system dependencies:
sudo apt-get install poppler-utils
From Source (Development)
For development or if you need to customize CUDA kernels:
git clone https://github.com/smhongok/diffbmp.git
cd diffbmp
pip install -r requirements.txt
# Build CUDA extensions (requires CUDA toolkit 12.3+)
./build_wheels.sh
# Install in editable mode
pip install -e .
Build Requirements (only for source installation):
- CUDA Toolkit 12.3+ (recommended)
- C++ compiler (GCC 9.4.0+ recommended)
- PyTorch 1.13.0+
Usage
Building
Tips :
- Recommended CUDA version is 12.3.
- Recommended C++ version is 9.4.0.
To build:
cd cuda_tile_rasterizer && python setup.py clean && rm -rf build/ *.egg-info *.so && python setup.py build_ext --inplace && cd ..
To build for fp16:
cd cuda_tile_rasterizer && python setup_fp16.py clean && rm -rf build/ *.egg-info *.so && python setup_fp16.py build_ext --inplace && cd ..
To build for psd_exporter:
cd cuda_tile_rasterizer && python setup_psd_export.py clean && rm -rf build/ *.egg-info *.so && python setup_psd_export.py build_ext --inplace && cd ..
If you want to specify the spec of your GPU or CUDA version:
cd cuda_tile_rasterizer && TORCH_CUDA_ARCH_LIST="8.6" CUDA_HOME=/usr/local/cuda-12.1 python setup_fp16.py clean && rm -rf build/ *.egg-info *.so && TORCH_CUDA_ARCH_LIST="8.6" CUDA_HOME=/usr/local/cuda-12.1 python setup_fp16.py build_ext --inplace && cd ..
If you have some errors when you build, remove followings and do above commands again:
cuda_tile_rasterizer/cuda_tile_rasterizer, cuda_tile_rasterizer/cuda_tile_rasterizer_fp16, cuda_tile_rasterizer/build
Running the Main Script
Execute the main script with a configuration file:
python main.py --config configs/default.json
Evaluating Methods
To compare different circle-art methods:
python compare_methods.py --config configs/default.json
Running Evaluations
To execute specific evaluations on generated results:
python run_evaluation.py
Dynamic DiffBMP Visualization Methods
To visualize frame-by-frame primitive (x,y) movement:
paste the code below in configs/sequential.json
sequential_debug = {
"route_visualization": {
"enabled": True,
"export_path": "./outputs/seq_test"
}
}
To visualize per-pixel gradient of opacity-reduced primitives (by our heuristic):
paste the code below in configs/sequential.json
sequential_debug = {
"gradient_visualization": {
"enabled": True,
"enable_non_problematic_primitive": False,
"gradient_threshold": 1e-15,
"save_dir": "./outputs/vis_class/debug_gradients_sequential"
}
}
To visualize difference mask between frames (which becomes critical input for our heuristic):
paste the code below in configs/sequential.json
sequential_debug = {
"diff_mask": {
"enabled": True,
"export_path": "./outputs/vis_class/diff_mask_sequential"
}
}
Complete debugging config:
sequential_debug = {
"gradient_visualization": {
"enabled": True,
"enable_non_problematic_primitive": False,
"gradient_threshold": 1e-15,
"save_dir": "./outputs/vis_class/debug_gradients_sequential"
},
"diff_mask": {
"enabled": True,
"export_path": "./outputs/vis_class/diff_mask_sequential"
},
"route_visualization": {
"enabled": True,
"export_path": "./outputs/seq_test"
}
}
Assets
- Put any predefined SVG templates based on 'path' tag in the
assets/svgdirectory. - Put fonts for rendering in
assets/font.
Examples and Datasets
The images directory contains various datasets and sample images categorized for quick testing:
- Artwork
- Nature
- Movie Posters
- Benchmark images (BSDS500, CelebA)
Contributing
Feel free to submit pull requests or report issues to enhance the functionality or resolve problems.
License
Please do not distribute. This is for the purpose of anonymous review.
Enjoy creating beautiful SVG drawing artwork!
Testing
To test all default*.json configs:
python test_configs.py --gpu 6 --no-wandb
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydiffbmp-0.1.0.tar.gz.
File metadata
- Download URL: pydiffbmp-0.1.0.tar.gz
- Upload date:
- Size: 552.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afa07407b6176f85874cb2f0e909ade8ccc8c8d8d1b65ab3a429d3ffc36e673d
|
|
| MD5 |
da3f0fc3e150903113274572956669b0
|
|
| BLAKE2b-256 |
ee770b5e46873b41d526c762f5927dd3c1bb24fcbde3e98494210c040d0c96a3
|
File details
Details for the file pydiffbmp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydiffbmp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 587.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8671f06defacf6c373c51f9b53c38ef7a212284b726bebadc779ba257797434a
|
|
| MD5 |
a7041de463c962760f4028e256d4f8d3
|
|
| BLAKE2b-256 |
d3cd9c1ad1e72f0cca6b1c1798b9d3d676f8ca4c139b0ec2df9b173083d2c838
|