sketchkit.image2sketch.swiftsketch.utils package¶
Submodules¶
sketchkit.image2sketch.swiftsketch.utils.dist_util module¶
Helpers for distributed training.
- sketchkit.image2sketch.swiftsketch.utils.dist_util.dev()[source]¶
Get the device to use for torch.distributed.
- sketchkit.image2sketch.swiftsketch.utils.dist_util.load_state_dict(path, **kwargs)[source]¶
Load a PyTorch file without redundant fetches across MPI ranks.
sketchkit.image2sketch.swiftsketch.utils.fixseed module¶
sketchkit.image2sketch.swiftsketch.utils.get_data module¶
sketchkit.image2sketch.swiftsketch.utils.get_features module¶
sketchkit.image2sketch.swiftsketch.utils.model_util module¶
sketchkit.image2sketch.swiftsketch.utils.parser_util module¶
sketchkit.image2sketch.swiftsketch.utils.sketch_utils module¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.calculate_highest_points(strokes)[source]¶
Vectorized function to calculate the maximum y-coordinate (highest point) for each Bézier curve in the strokes. :param strokes: Tensor of shape [Nstrokes, 4, 2], representing strokes with 4 control points (x, y).
- Returns:
Tensor of shape [Nstrokes] representing the highest point (max y) for each stroke.
- Return type:
max_y_points
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.calculate_length(strokes, num_samples=100)[source]¶
Approximates the length of each Bézier curve using sampling. :param strokes: Tensor of shape [Nstrokes, 4, 2], representing strokes with 4 control points (x, y). :param num_samples: Number of samples along the curve to approximate length.
- Returns:
Tensor of shape [Nstrokes] representing the length of each stroke.
- Return type:
lengths
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.create_masked_image(image, mask)[source]¶
Apply the predicted mask to the input image.
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.denormalize_points(points, scaling_factor, canvas_width)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.extract_control_points_from_svg(svg_content)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.generate_svg_content(canvas_width, canvas_height, shapes, shape_groups)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.get_features_dim(image_features_type)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.get_mask(im: <module 'PIL.Image' from '/home/euruson/code/actions-runner/_work/SketchKit/SketchKit/.venv/lib/python3.12/site-packages/PIL/Image.py'>, device, model)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.get_thick_contour_tensor(mask, canvas_width, canvas_height)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.load_compressed_npz(file_path, svg_keys=[], features_key='CLIPMiddle_layer4_features')[source]¶
Load compressed .npz file and reconstruct the original objects.
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.load_entry(file_path, svg_keys=[], features_key='CLIPMiddle_layer4_features')[source]¶
Load a .npy or .npz file into a Python dict.
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.log_diffusion_process_to_wandb(timesteps, xt_Denoising_Process, x0_Denoising_Process, title='')[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.log_grid(input_images, target_sketches, output_sketches, epoch, output_dir, log_to_wandb, log_name='test')[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.log_grid_images_list(input_images, output_dir, log_to_wandb, log_name='test')[source]¶
Create a grid from a list of images, save it, and optionally log it to W&B.
- Parameters:
input_images (list) – List of image paths or PIL Images.
output_dir (str) – Directory to save the grid image.
log_to_wandb (bool) – Whether to log the grid to W&B.
log_name (str) – Name for the logged image in W&B.
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.log_grid_model_sketches(diffusion_sketch_list, predict_sketch_list, target_sketch_list, step, log_name='test', mode='train', group_size=10)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.log_grid_model_sketches_all(diffusion_sketch_list, predict_sketch_list, target_sketch_list, step, log_name='test', mode='train')[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.log_grid_test(input_images, output_sketches, epoch, output_dir, log_to_wandb, log_name='test')[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.log_model_prediction(x0_sketch, xt_sketch, predict_x0_sketch, t, quartile, step)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.log_refine_model_prediction(diffusion_sketch, predict_sketch, target_sketch, step)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.plot_row(axs, k, titles, row_num, lst)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.rander_image_from_points(control_points_batch, canvas_width, canvas_height, return_svg_content=False)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.render_image_from_norm_points(points, scaling_factor, canvas_size=224)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.render_image_from_norm_points_svg(points, scaling_factor, canvas_size=224)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.render_paths(control_points, canvas_width, canvas_height, save_svg=False, return_svg_content=False, output_dir='', name='')[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.save_svg_from_points(control_points, canvas_width, canvas_height, save_path)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.sort_by_contour_and_attn(opt_svg, mask, attn_map)[source]¶
- sketchkit.image2sketch.swiftsketch.utils.sketch_utils.sort_strokes(strokes, by='highest_point', SVG_content=None, mask=None, attn_map=None)[source]¶
Sorts strokes by the specified criterion (‘highest_point’ or ‘length’ or ‘contour). :param strokes: Tensor of shape [Nstrokes, 4, 2] representing strokes with 4 control points. :param by: Criterion for sorting, either ‘highest_point’ or ‘length’ or ‘contour.
- Returns:
Tensor of sorted strokes with the same shape as strokes.
Module contents¶
Runtime utilities used by the SwiftSketch backend.