Skip to main content

Utils for Computer Vision Deep Learning research

Project description

DOI CodeFactor PyPI

LAPiX DL - Utils for Computer Vision Deep Learning research

This package contains utilitary functions to support train and evaluation of Deep Learning models applied to images.

Three computer vision approaches are covered: Segmentation, Detection and Classification.

How to use

For Model Evaluation

This module exports the following functions for model evaluation:

from lapixdl.evaluation.evaluate import evaluate_segmentation
from lapixdl.evaluation.evaluate import evaluate_detection
from lapixdl.evaluation.evaluate import evaluate_classification

All model evaluation methods need two iterators: one for the ground truth itens and one for the predictions.

These iterators must be sorted equaly, assuring that the ground truth and the prediction of the same sample are at the same position.

Example of segmentation model evaluation using PyTorch:

from lapixdl.evaluation.evaluate import evaluate_segmentation

classes = ['background', 'object']

# Iterator for GT masks
# `dl` is a PyTorch DataLoader
def gt_mask_iterator_from_dl(dl):
  for imgs, masks in iter(dl):
    for mask in masks:
      yield mask

# Iterator for prediction masks
# `predict` a function that, given an image, predicts the mask.
def pred_mask_iterator_from_dl(dl, predict):
  for imgs, masks in iter(dl):
    for img in imgs:
      yield predict(img)

gt_masks = gt_mask_iterator_from_dl(validation_dl)
pred_masks = pred_mask_iterator_from_dl(validation_dl, prediction_function)

# Calculates and shows metrics
eval = evaluate_segmentation(gt_masks, pred_masks, classes)

# Shows confusion matrix and returns its Figure and Axes
fig, axes = eval.show_confusion_matrix()

Example of how to log the results of LAPiX DL evaluations in the Weights & Biases platform

About Weights & Biases.

from lapixdl.evaluation.evaluate import evaluate_segmentation
import wandb

# init wandb ...
...

eval_test = evaluate_segmentation(gt_masks, pred_masks, categories)

...

# If you want to log everything
wandb.log({'test_evaluation':  eval_test.to_dict()['By Class']})

# If you want to choose specific categories to log
selected_cats = ['A', 'B', 'C']
metrics_by_cat = {k: v for k, v in eval_test.to_dict()['By Class'].items() if k in selected_cats}
wandb.log({'test_evaluation': metrics_by_cat})

For Results Visualization

This module exports the following functions for results visualization:

from lapixdl.evaluation.visualize import show_segmentations
from lapixdl.evaluation.visualize import show_classifications
from lapixdl.evaluation.visualize import show_detections

The available color maps are the ones from matplotlib.

For Data Conversion

This module exports the functions for data conversion.

from lapixdl.convert import labelbox_to_lapix
from lapixdl.convert import labelbox_to_coco

Example of conversion from Labelbox to COCO labels format:

import json

from lapixdl.formats import labelbox_to_coco

# convert it to a intermediary format
map_categories = {
  '<schematic id from labelbox>': 1 # category id
}

# convert it
categories_coco = [{
  'supercategory': None,
  'name': 'example_category',
  'id': 1
}]

# create the full COCO OD file
coco_dict = labelbox_to_coco(
  'labelbox_export_file.json',
  map_categories,
  categories_coco,
  target = 'object detection',
  image_shape = (1200, 1600)
)

# Saves converted json
with open('./coco.json', 'w') as out_file:
    json.dump(coco_dict, out_file)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lapixdl-0.9.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

lapixdl-0.9.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file lapixdl-0.9.0.tar.gz.

File metadata

  • Download URL: lapixdl-0.9.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for lapixdl-0.9.0.tar.gz
Algorithm Hash digest
SHA256 ceb70ec86ee37dedd7df66cf0d0d29a5d6cff6006aec6b114985ca28ef86a491
MD5 6100d4d26665b1c3e4b5636b5d0d289f
BLAKE2b-256 c51ba41d98db5654307b7e0d584e7c635a58097a1ee8c64dbc29c05ff279ef6d

See more details on using hashes here.

File details

Details for the file lapixdl-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: lapixdl-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for lapixdl-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c36403f88e85f6cd2f3728fe4715baf830d43052f2d70db7a9bcd28a744260b
MD5 2b64702cae5ab2bfb7f7eae3e9c0903d
BLAKE2b-256 3141ac0ee31761fbb04c68dbd7b1c72ac4db495d04391115fd0be74f3bad2814

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page