Deterministic hint generation (DHT): batch scripts
The scripts in this directory built the hint datasets of the paper. For new images the hintauc library is the
easiest entry point (pip install hintauc; hintauc.generate_hints(...) is the same pipeline as a function);
the scripts here are the batch tools with sharding and resume.
The pipeline (one colour image β hint maps)
- Region segmentation β Felzenszwalb (
scale=100, sigma=0.5, min_size=100) on the image at its original resolution (the paper's maps were computed from the Danbooru2021 files, not from the 512 Γ 512 ground-truth copies); SLIC and Quickshift variants (generate_hints.py) and DanbooRegion (danbooregion_hints.py) for the robustness study. - Region-id map β a unique colour per region; disconnected parts of one region are split and recoloured.
- Scribble per region β ZhangβSuen skeleton β 3 Γ 3 dilation β longest path (FilFinder, branch/skeleton threshold 3 px), clipped to the region; coloured with the region's mean colour.
- Dot per region β the in-region path pixel with the smallest total Manhattan distance to the other in-region path
pixels (
dot_method="medoid", the rule of the paper's stored maps).
Output files per image (64 px by default):
<id>.image_region64.png region-id map
<id>.image_scribble_mask64.png scribble mask <id>.image_scribble_col64.png scribble colours
<id>.image_dot_mask64.png dot mask <id>.image_dot_col64.png dot colours
<id>.image_flatten_img64.png region-mean colour image
At evaluation time the hints of the largest βΞ±Β·nβ regions are kept (hintauc.HintResult.at_ratio, the DetFill loader).
FilFinder breaks medial-axis ties with an unseeded generator, so regenerated scribbles differ from the stored maps
(and between two runs) in a few pixels; the stored maps are the reference for every reported number.
Run
pip install -r requirements.txt
python generate_hints.py --segmenter slic --split test \
--src_root /path/to/src --txt_dir /path/to/split_lists --out_root /path/to/output
--src_root:<src_root>/segmentation_regions/felzenszwalb/<dir>/<id>.image.png(the colour images).--txt_dir:{train,valid,test}.txt, one<dir>/<id>.image.pngper line (the paper's lists:../detfill/configs/illust/).- Output:
<out_root>/<segmenter>/<dir>/<id>.image_{region,scribble_mask,scribble_col}64.png. --limit Nfor a quick check;--shard / --nshardsto split the work;--path_method geodesicfor the dependency-free longest path (outputs go to<segmenter>_geodesic/; do not mix the two methods in one evaluation).
Felzenszwalb hints for a single image without the batch tool:
import hintauc
hints = hintauc.generate_hints("image.png", size=64) # Felzenszwalb by default
hints.save("out/image") # the file set above
Files
| File | Role |
|---|---|
generate_hints.py |
batch generator for the alternative segmenters (SLIC / Quickshift; sharding; resume-safe); contains the verbatim make_scribbling port. Felzenszwalb maps: hintauc.generate_hints |
danbooregion_hints.py |
DanbooRegion-segmenter variant (needs the upstream DanbooRegion code and weights) |
compare_path_methods.py |
compares the FilFinder and geodesic longest paths on stored region maps |
canonical/hint_dot_generation_fixdot.py |
archival copy of the script that produced the paper's stored maps |
canonical/hint_dot_generation.py |
archival copy of the earlier version (dot = truncated mean of the path; not the rule of the released maps) |
canonical/all_segmentations.py |
archival copy of the segmentation stage |
requirements.txt |
dependencies of the scripts in this directory |