SPIN API Modules

class spin.spin.SPIN(annotation_dir, image_dir, split='test', download=False)[source]

Bases: object

__init__(annotation_dir, image_dir, split='test', download=False)[source]

Initialize the SPINViewer with annotations and image directories.

Parameters:
  • annotation_dir (str) – Directory containing annotation files.

  • image_dir (str) – Directory containing images.

  • split (str) – Dataset split, e.g., “train”, “test”. Default is “test”.

  • download (bool) – Download data.

display_annotations(image_id, fig_size=[30, 20], draw_bbox=False)[source]

Display annotations for a given image ID.

Parameters:
  • image_id (int) – ID of the image to display.

  • fig_size (List[int]) – Size of the figure to display. Default is [30, 20].

  • draw_bbox (bool) – If True, draw bounding boxes. Default is False.

Return type:

None

download_spin(link='https://joshmyersdean.github.io/spin/spin_coco.zip', save_directory='spin_jsons', save_name='spin.zip')[source]

Downloads a file using a shared link.

Parameters:
  • sharepoint_link – The shared link URL to the file.

  • save_directory (str) – The directory where the file should be saved.

  • save_name (str) – The name to save the file as.

Return type:

None

Returns:

None.

getImgIds()[source]

Get a list of all image IDs.

Return type:

List[int]

Returns:

List of image IDs.

get_categories(granularity='subpart', verbose=False)[source]

Get the categories for a given granularity level.

Parameters:
  • granularity (str) – Level of granularity (“subpart”, “part”, “whole”). Default is “subpart”.

  • verbose (bool) – If True, prints additional information. Default is False.

Return type:

Dict[int, Entry]

Returns:

Dictionary of categories.

Raises:

NotImplementedError – If the granularity is not supported.

get_image(image_id)[source]

Get the image corresponding to the given image ID.

Parameters:

image_id (int) – ID of the image to retrieve.

Return type:

Image

Returns:

PIL Image object.

get_object_name_for_file(img_id)[source]

Get the object name corresponding to the given image ID.

Parameters:

img_id (int) – ID of the image.

Return type:

str

Returns:

Object name.

rasterize_coco_segmentations(coco, image_id, background_class)[source]

Rasterizes COCO segmentations for a specified image, allowing the user to specify which class is the background.

Parameters:
  • coco (COCO) – COCO object containing the dataset annotations.

  • image_id (int) – ID of the image to rasterize segmentations for.

  • background_class (int) – Class ID to be used as the background.

Return type:

ndarray

Returns:

A 2D numpy array with the same dimensions as the image, where each pixel value represents the class ID.

rasterize_dataset(save_path='spin_dataset/annotations')[source]

Rasterizes COCO segmentations for a specified split for all granularities.

Parameters:

save_path (str) – Where to save annotations.

Return type:

None

class spin.types.Entry[source]

Bases: TypedDict

id: int
name: str
exception spin.exceptions.InitialRequestError(status_code)[source]

Bases: Exception

Exception raised for errors in the initial request.

spin.helpers.unzip_file(zip_path, extract_to)[source]

Unzips a file to a specified directory. All files in the zipped folder will be placed directly in the target directory without preserving folder structure.

Parameters:
  • zip_path (str) – The path to the zip file.

  • extract_to (str) – The directory where the files should be extracted.

Return type:

None