Usefull features

Here are some usefull features for data management and data visualisation.

Visualisation

detectools.visualisation.visualisation(image: Tensor, target: BaseFormat | SegmentationFormat, classes: List[str] = [], colors: List[Tuple[int, int, int]] = [(0, 102, 204), (51, 255, 51), (255, 0, 0), (51, 51, 255), (255, 51, 255), (255, 255, 0), (86, 255, 255), (100, 200, 100), (250, 50, 125), (125, 250, 0), (125, 50, 250), (125, 125, 125), (20, 20, 200)], color_objects: bool = False) Tensor[source]

Draw boxe(s) on image from DetectionTarget or DetectionObject.

Parameters:
  • image (Tensor) – Image (RGB & uint8).

  • target (Union[BaseFormat, SegmentationFormat]) – Target as BaseFormat or Annotation.

  • classes (List[str], optional) – Names of classes to draw, if no list passed classes names are not displayed. Defaults to [].

  • colors (List[Tuple[int, int, int]], optional) – List of RGB colors for visualisations. Defaults to COLORS.

  • color_objects (bool, optional) – If True one random color/object, if False one color/class. Defaults to False.

Returns:

  • Visaulisation of objects on RGB image.

Return type:

Tensor

detectools.visualisation.draw_object(image: Tensor, obj: BaseAnnotation, classes: List[str] = [], colors: List[Tuple[int, int, int]] = [(0, 102, 204), (51, 255, 51), (255, 0, 0), (51, 51, 255), (255, 51, 255), (255, 255, 0), (86, 255, 255), (100, 200, 100), (250, 50, 125), (125, 250, 0), (125, 50, 250), (125, 125, 125), (20, 20, 200)]) Tensor[source]

Draw bounding boxe & mask from Annotation to image.

Parameters:
  • image (Tensor) – Tensor image (uint8 & RGB).

  • obj (BaseAnnotation) – Annotation to draw.

  • classes (List[str], optional) – Names of classes to draw, cif no list passed classes names are not displayed. Defaults to [].

  • colors (List[Tuple[int, int, int]], optional) – List of RGB colors for visualisations. Defaults to COLORS.

Returns:

  • Image with annotation drawed.

Return type:

Tensor

detectools.visualisation.draw_objects(image: Tensor, objects: BaseFormat, classes: List[str] = [], colors: List[Tuple[int, int, int]] = [(0, 102, 204), (51, 255, 51), (255, 0, 0), (51, 51, 255), (255, 51, 255), (255, 255, 0), (86, 255, 255), (100, 200, 100), (250, 50, 125), (125, 250, 0), (125, 50, 250), (125, 125, 125), (20, 20, 200)], color_objects: bool = False)[source]

Draw all bounding boxes of an object on image.

Parameters:
  • image (Tensor) – Tensor image (uint8 & RGB).

  • obj (BaseAnnotation) – Annotation to draw.

  • classes (List[str], optional) – Names of classes to draw, if no list passed classes names are not displayed. Defaults to [].

  • colors (List[Tuple[int, int, int]], optional) – List of RGB colors for visualisations. Defaults to COLORS.

  • color_objects (bool, optional) – If True one random color/object, if False one color/class. Defaults to False.

Returns:

  • Image with annotations drawed.

Return type:

Tensor

Data management:

detectools.data_management.merge_jsons(jsonfiles: List[str], output_json: str, categories: List[Dict[str, Any]])[source]

Take a list of json files paths and merge them in one respecting the images/annotations correspondance id.

Parameters:
  • jsonfiles (List[str]) – List of paths of jsons to merge.

  • output_json (str) – Path to store merged json.

  • categories (List[Dict[str, Any]]) – List of categories as COCO format.

detectools.data_management.split_dataset(source_datasets: str | List[str], destination: str, proportions: Tuple[float] = (0.8, 0.2, 0.0)) None[source]

Split one or multiple dataset folder according to split proportions and write a new dataset with the fusion same split for each datqset (train, valid, test).

Parameters:
  • source_datasets (Union[str, List[str]]) – Path to ad dataset or list of dataset.

  • destination (str) – Path tostore subsets.

  • proportions (Tuple[float], optional) – Proportions for train, valid & test. Defaults to (0.8, 0.2, 0.0).