sketchkit.image2sketch.swiftsketch package

Subpackages

Submodules

sketchkit.image2sketch.swiftsketch.generate module

SwiftSketch programmatic API.

This module exposes the SwiftSketchModel selected by SketchGenerator(method="SwiftSketch"). The implementation wraps the original SwiftSketch diffusion pipeline while providing a higher level API that handles checkpoint management and preprocessing automatically.

class sketchkit.image2sketch.swiftsketch.generate.SwiftSketchModel(*, device: str | device | None = None, use_refine: bool = True, guidance_param: float = 2.5, fix_scale: bool = True, checkpoint_dir: str | PathLike | None = None, auto_download: bool = True, mask_model_factory: Callable[[device], Module] | None = None, feature_extractor_factory: Callable[[device, str], Module] | None = None, diffusion_factory: Callable[[SimpleNamespace], Tuple[Module, object]] | None = None, refine_model_factory: Callable[[SimpleNamespace], Module] | None = None)[source]

Bases: object

High level wrapper around the SwiftSketch diffusion pipeline.

static _control_points_to_sketch(control_points: Tensor, canvas_size: Tuple[int, int]) Sketch[source]
_default_diffusion_factory(args: SimpleNamespace) Tuple[Module, object][source]
_default_feature_extractor_factory(device: device, image_features_type: str) Module[source]
_default_mask_model_factory(device: device) Module[source]
static _device_index(device: device) int[source]
_ensure_archive(archive_path: Path, url: str) None[source]
static _find_model_member(zf: ZipFile, folder: str) str[source]
_initialise_pipeline() None[source]
static _load_args(archive_path: Path, folder: str) SimpleNamespace[source]
_load_state_dict(archive_path: Path, folder: str) dict[source]
static _resolve_device(device: str | device | None) device[source]

Determine which device SwiftSketch should run on.

By default, a CUDA-capable GPU is required. Users can override the selection via the SKETCHKIT_SWIFTSKETCH_DEVICE environment variable or by explicitly passing a device argument. When neither is supplied and CUDA is unavailable, the model refuses to run unless the SKETCHKIT_ALLOW_CPU_FALLBACK environment variable is set to "1". This makes it possible to exercise the pipeline on CPU for testing while keeping the production default focused on GPU runtimes.

static _resolve_size(size: int | Tuple[int, int]) Tuple[int, int][source]
static _to_pil_image(image: Image | ndarray | str | PathLike) Image[source]
property checkpoint_dir: Path
property device: device
ensure_assets() None[source]

Ensure that the model archives are available locally.

generate(image: Image | ndarray | str | PathLike | Sequence[Image | ndarray | str | PathLike], size: int | Tuple[int, int] | None = None) Sketch | List[Sketch][source]

Generate sketches for the provided image(s).

generate_batch(images: Sequence[Image | ndarray | str | PathLike], *, size: int | Tuple[int, int] | None = None) List[Sketch][source]
property model_archive_path: Path
property refine_archive_path: Path

Module contents

SwiftSketch image-to-vector-sketch backend.

class sketchkit.image2sketch.swiftsketch.SwiftSketchModel(*, device: str | device | None = None, use_refine: bool = True, guidance_param: float = 2.5, fix_scale: bool = True, checkpoint_dir: str | PathLike | None = None, auto_download: bool = True, mask_model_factory: Callable[[device], Module] | None = None, feature_extractor_factory: Callable[[device, str], Module] | None = None, diffusion_factory: Callable[[SimpleNamespace], Tuple[Module, object]] | None = None, refine_model_factory: Callable[[SimpleNamespace], Module] | None = None)[source]

Bases: object

High level wrapper around the SwiftSketch diffusion pipeline.

static _control_points_to_sketch(control_points: Tensor, canvas_size: Tuple[int, int]) Sketch[source]
_default_diffusion_factory(args: SimpleNamespace) Tuple[Module, object][source]
_default_feature_extractor_factory(device: device, image_features_type: str) Module[source]
_default_mask_model_factory(device: device) Module[source]
static _device_index(device: device) int[source]
_ensure_archive(archive_path: Path, url: str) None[source]
static _find_model_member(zf: ZipFile, folder: str) str[source]
_initialise_pipeline() None[source]
static _load_args(archive_path: Path, folder: str) SimpleNamespace[source]
_load_state_dict(archive_path: Path, folder: str) dict[source]
static _resolve_device(device: str | device | None) device[source]

Determine which device SwiftSketch should run on.

By default, a CUDA-capable GPU is required. Users can override the selection via the SKETCHKIT_SWIFTSKETCH_DEVICE environment variable or by explicitly passing a device argument. When neither is supplied and CUDA is unavailable, the model refuses to run unless the SKETCHKIT_ALLOW_CPU_FALLBACK environment variable is set to "1". This makes it possible to exercise the pipeline on CPU for testing while keeping the production default focused on GPU runtimes.

static _resolve_size(size: int | Tuple[int, int]) Tuple[int, int][source]
static _to_pil_image(image: Image | ndarray | str | PathLike) Image[source]
property checkpoint_dir: Path
property device: device
ensure_assets() None[source]

Ensure that the model archives are available locally.

generate(image: Image | ndarray | str | PathLike | Sequence[Image | ndarray | str | PathLike], size: int | Tuple[int, int] | None = None) Sketch | List[Sketch][source]

Generate sketches for the provided image(s).

generate_batch(images: Sequence[Image | ndarray | str | PathLike], *, size: int | Tuple[int, int] | None = None) List[Sketch][source]
property model_archive_path: Path
property refine_archive_path: Path