ISAT.formats package

Submodules

ISAT.formats.coco module

class ISAT.formats.coco.COCO

Bases: ISAT

COCO format

keep_crowd

keep the crowded objects

Type:

bool

read_from_coco(annotation_file)

Load annotations from a COCO json file.

Parameters:

annotation_file (str) – coco json annotations file.

Return type:

bool

save_to_coco(annotation_file, cates=())

Save annotations to a COCO json file.

Parameters:
  • annotation_file (str) – coco json annotations file.

  • cates (tuple) – coco cates.

Return type:

bool

ISAT.formats.isat module

class ISAT.formats.isat.ISAT

Bases: object

The ISAT format provides a structured approach for representing image annotations.

File Naming: Each image has a corresponding .json file named after the image file (without the image extension).

annos

Dictionary of image annotations. {name: ANNO}

Type:

dict

cates

categories.

Type:

tuple

class ANNO

Bases: object

Annotation class.

info

INFO class.

Type:

INFO

objs

tuple of OBJs.

Type:

tuple[OBJ, …]

class INFO

Bases: object

Contains metadata about the dataset and image.

description

Always “ISAT”.

Type:

str

folder

The directory where the images are stored.

Type:

str

name

The name of the image file

Type:

str

width

The dimensions of the image.

Type:

int

height

The dimensions of the image.

Type:

int

depth

The dimensions of the image; depth is assumed to be 3 for RGB images.

Type:

int

note

An optional field for any additional notes related to the image.

description = ''
folder = ''
name = ''
width = None
height = None
depth = None
note = ''
class OBJ

Bases: object

Lists all the annotated objects in the image.

category

The class label of the object.

Type:

str

group

An identifier that groups objects based on overlapping bounding boxes. If an object’s bounding box is within another, they share the same group number.

Type:

int

segmentation

A list of [x, y] coordinates forming the polygon around the object.

Type:

list | tuple

area

The area covered by the object in pixels.

Type:

float

layer

A float indicating the sequence of the object. It increments within the same group, starting at 1.0 .

Type:

int

bbox

The bounding box coordinates in the format [x_min, y_min, x_max, y_max].

Type:

list | tuple

iscrowd

A boolean value indicating if the object is part of a crowd.

Type:

bool

note

An optional field for any additional notes related to the object.

Type:

str

category = ''
group = None
segmentation = None
area = None
layer = None
bbox = None
iscrowd = False
note = ''
info: INFO
objs: Tuple[OBJ, ...] = ()
annos: Dict[str, ANNO] = {}
cates: Tuple[str] = ()
read_from_ISAT(json_root)

Load annotations from a directory of json files.

Parameters:

json_root (str) – The directory of json files.

Return type:

bool

save_to_ISAT(json_root)

Save annotations to the directory of json files.

Parameters:

json_root (str) – The directory of json files.

Return type:

bool

remove_file_suffix(file_name)

Remove the file suffix from the file name.

Parameters:

file_name (str) – The file name.

Returns:

The file name without the file suffix.

Return type:

str

load_one_isat_json(json_path)

Load annotation from a json file.

Parameters:

json_path (str) – The file path.

Returns:

The instance of the ANNO.

Return type:

ANNO

save_one_isat_json(anno, save_path)

Save annotation to a json file.

Parameters:
  • anno (ANNO) – The instance of the ANNO.

  • save_path (str) – The ISAT json file path.

Return type:

bool

ISAT.formats.labelme module

class ISAT.formats.labelme.LABELME

Bases: ISAT

LABELME format

keep_crowd

keep the crowded objects

Type:

bool

read_from_LABELME(json_root)

Load annotations from the directory of labelme json files.

Parameters:

json_root (str) – the directory of label json files.

Return type:

bool

save_to_LABELME(json_root)

Save annotations to the directory of labelme json files.

Parameters:

json_root (str) – the directory of label json files.

Return type:

bool

save_one_labelme_json(anno, json_path)

Save annotation to a json file.

Parameters:
  • anno (ISAT.ANNO) – the annotation.

  • json_path (str) – the path to save the json file.

Return type:

bool

load_one_labelme_json(json_path)

Load annotation from a labelme json file.

Parameters:

json_path (str) – the path to save the json file.

Returns:

the annotation.

Return type:

ISAT.ANNO

ISAT.formats.voc module

class ISAT.formats.voc.VOC

Bases: ISAT

VOC format

keep_crowd

keep the crowded objects

Type:

bool

is_instance

mark if an object is instance or sematic

Type:

bool

save_to_voc(png_root)

Save annotations to the directory of voc png files.

Parameters:

png_root (str) – the directory to save the voc png files.

Return type:

bool

save_one_voc_png(anno, png_path, cmap, category_index_dict=None)

Save annotation to a VOC png file.

Parameters:
  • anno (ISAT.ANNO) – the annotation.

  • png_path (str) – the path of the png file.

  • cmap (np.ndarray) – color map. shape [n, 3]

  • category_index_dict (dict) – the category index dict. {index: category}.

Return type:

bool

static fill_polygon(segmentation, img, color)

fill polygon with color on image.

Parameters:
  • segmentation (Union[list, tuple]) – the vertices of the polygon. [(x1, y1), (x2, y2), …] .

  • img (np.ndarray) – the image.

  • color (int) – the color of the polygon. save image as mode ‘P’ with PIL.

ISAT.formats.voc_detection module

class ISAT.formats.voc_detection.VOCDetect

Bases: ISAT

VOC format for object detection

keep_crowd

keep the crowded objects

Type:

bool

save_to_XML(xml_root)

Save annotations to the directory of voc xml files.

Parameters:

xml_root (str) – the directory to save the voc xml files

Return type:

bool

save_one_voc_xml(anno, xml_path)

Save annotation to one voc xml file.

Parameters:
  • anno (ISAT.ANNO) – the annotation

  • xml_path (str) – the xml file path

Return type:

bool

ISAT.formats.yolo module

class ISAT.formats.yolo.YOLO

Bases: ISAT

YOLO format

YOLO use txt to save annotations. Every line container a annotation. format: class_index, x1, y1, x2, y2, x3, y3, ….

For cases where a single object contains multiple polygons, referring to the conversion code of YOLOv8 general_json2yolo.py, a straight line is drawn between the polygons to combine the multiple polygons into a single polygon for saving.

read_from_YOLO(img_root, txt_root, class_dict=None)

Load annotations from the directory of YOLO txt files.

Parameters:
  • img_root (str) – The directory of images.

  • txt_root (str) – The directory of YOLO txt files.

  • class_dict (dict) – A dictionary that maps class index to class name. {index: category} .

Return type:

bool

save_to_YOLO(txt_root)

Save annotations to the directory of YOLO txt files.

Parameters:

txt_root (str) – The directory of YOLO txt files.

Return type:

bool

static merge_multi_segment(segments)

https://github.com/ultralytics/JSON2YOLO/blob/c38a43f342428849c75c103c6d060012a83b5392/general_json2yolo.py#L324

Merge multi segments to one list. Find the coordinates with min distance between each segment, then connect these coordinates with one thin line to merge all segments into one.

Parameters:

segments (List(List)) – original segmentations in coco’s json file. like [segmentation1, segmentation2,…], each segmentation is a list of coordinates.

static yolo2isat_segmentation(yolo_seg, img_width, img_height)

Convert YOLO segmentation format to ISAT segmentation format

static get_isat_bbox(segmentation)

Calculate the bbox from the ISAT segmentation

static bbox_within(bbox_1, bbox_2)

Check if two objects belong to the same group

load_one_yolo_txt(image_path, txt_path, class_dict=None)

Load annotations from the directory of yolo txt files.

Parameters:
  • image_path (str) – image path.

  • txt_path (str) – txt path.

  • class_dict (dict) – class dictionary. {index: category} .

Returns:

The instance of the ANNO.

Return type:

ISAT.ANNO

save_one_yolo_txt(anno, save_path, cates_index_dict)

Save annotation to one YOLO txt file

Parameters:
  • anno (ISAT.ANNO) – the annotation.

  • save_path (str) – the path of the txt file.

  • cates_index_dict (dict) – the cates index dictionary. {category: index} .

Return type:

bool

Module contents