sketchkit.image2sketch.photosketch package

Subpackages

Submodules

sketchkit.image2sketch.photosketch.generate module

PhotoSketch programmatic API.

This module exposes a PhotoSketchModel that mirrors the high level contract used by other image2sketch backends. It wraps the original PhotoSketch Pix2Pix generator while managing checkpoint discovery and downloading automatically.

class sketchkit.image2sketch.photosketch.generate.PhotoSketchModel(*, checkpoint_dir: str | PathLike | None = None, model_name: str = 'pretrained', auto_download: bool = True, device: str | device | None = None, input_size: int = 256)[source]

Bases: object

High level wrapper around the PhotoSketch Pix2Pix generator.

DEFAULT_CHECKPOINT_DIR = PosixPath('/home/euruson/.cache/sketchkit/image2sketch/photosketch')
DEFAULT_INPUT_SIZE = 256
DEFAULT_MODEL_NAME = 'pretrained'
GENERATOR_FILENAME = 'latest_net_G.pth'
GENERATOR_SHA1 = '5968e8f007c650008a265c11f2d2a3887e5840d4'
INPUT_CHANNELS = 3
MODEL_ARCHIVE_NAME = 'photosketch_pretrained.zip'
MODEL_DOWNLOAD_URL = 'https://drive.google.com/uc?export=download&id=1TQf-LyS8rRDDapdcTnEgWzYJllPgiXdj'
MODEL_DRIVE_ID = '1TQf-LyS8rRDDapdcTnEgWzYJllPgiXdj'
NUM_FILTERS = 64
OUTPUT_CHANNELS = 1
RESNET_BLOCKS = 9
_download_and_extract() None[source]
_extract_archive(archive_path: Path) None[source]
_generator: Module | None
_initialise_generator() Module[source]
_install_from_local_archive() bool[source]
_install_from_local_file() bool[source]
_prepare_tensor(image: Image) Tensor[source]
static _resolve_device(device: str | device | None) device[source]
static _resolve_size(size: int | Tuple[int, int]) Tuple[int, int][source]
_tensor_to_image(tensor: Tensor, size: Tuple[int, int]) Image[source]
static _to_pil_image(image: Image | ndarray | str | PathLike) Image[source]
static _validate_sha1(path: Path, expected: str) bool[source]
property checkpoint_dir: Path
ensure_assets() None[source]

Ensure that the pretrained PhotoSketch weights exist locally.

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

Generate sketch images for the provided image input(s).

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

Generate sketches for a batch of images.

Module contents

Public entry points for the PhotoSketch image2sketch backend.

class sketchkit.image2sketch.photosketch.PhotoSketchModel(*, checkpoint_dir: str | PathLike | None = None, model_name: str = 'pretrained', auto_download: bool = True, device: str | device | None = None, input_size: int = 256)[source]

Bases: object

High level wrapper around the PhotoSketch Pix2Pix generator.

DEFAULT_CHECKPOINT_DIR = PosixPath('/home/euruson/.cache/sketchkit/image2sketch/photosketch')
DEFAULT_INPUT_SIZE = 256
DEFAULT_MODEL_NAME = 'pretrained'
GENERATOR_FILENAME = 'latest_net_G.pth'
GENERATOR_SHA1 = '5968e8f007c650008a265c11f2d2a3887e5840d4'
INPUT_CHANNELS = 3
MODEL_ARCHIVE_NAME = 'photosketch_pretrained.zip'
MODEL_DOWNLOAD_URL = 'https://drive.google.com/uc?export=download&id=1TQf-LyS8rRDDapdcTnEgWzYJllPgiXdj'
MODEL_DRIVE_ID = '1TQf-LyS8rRDDapdcTnEgWzYJllPgiXdj'
NUM_FILTERS = 64
OUTPUT_CHANNELS = 1
RESNET_BLOCKS = 9
_download_and_extract() None[source]
_extract_archive(archive_path: Path) None[source]
_generator: Module | None
_initialise_generator() Module[source]
_install_from_local_archive() bool[source]
_install_from_local_file() bool[source]
_prepare_tensor(image: Image) Tensor[source]
static _resolve_device(device: str | device | None) device[source]
static _resolve_size(size: int | Tuple[int, int]) Tuple[int, int][source]
_tensor_to_image(tensor: Tensor, size: Tuple[int, int]) Image[source]
static _to_pil_image(image: Image | ndarray | str | PathLike) Image[source]
static _validate_sha1(path: Path, expected: str) bool[source]
property checkpoint_dir: Path
ensure_assets() None[source]

Ensure that the pretrained PhotoSketch weights exist locally.

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

Generate sketch images for the provided image input(s).

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

Generate sketches for a batch of images.