apple/coreml-detr-semantic-segmentation

Model

34

stars

24

commits

2

linked in READMEs

Aug 9, 2024

updated

coreml
image-segmentation

README

DETR-Resnet50 (semantic segmentation) Core ML Models

See the Files tab for converted models.

DEtection TRansformer (DETR) model trained end-to-end on COCO 2017 object detection (118k annotated images). It was introduced in the paper End-to-End Object Detection with Transformers by Carion et al. and first released in this repository.

Model description

The DETR model is an encoder-decoder transformer with a convolutional backbone. Two heads are added on top of the decoder outputs in order to perform object detection: a linear layer for the class labels and a MLP (multi-layer perceptron) for the bounding boxes. The model uses so-called object queries to detect objects in an image. Each object query looks for a particular object in the image. For COCO, the number of object queries is set to 100.

The model is trained using a "bipartite matching loss": one compares the predicted classes + bounding boxes of each of the N = 100 object queries to the ground truth annotations, padded up to the same length N (so if an image only contains 4 objects, 96 annotations will just have a "no object" as class and "no bounding box" as bounding box). The Hungarian matching algorithm is used to create an optimal one-to-one mapping between each of the N queries and each of the N annotations. Next, standard cross-entropy (for the classes) and a linear combination of the L1 and generalized IoU loss (for the bounding boxes) are used to optimize the parameters of the model.

model image

Evaluation - Variants

VariantParametersSize (MB)Weight PrecisionAct. PrecisionIoUPixel accuracy
facebook/detr-resnet-50-panoptic (PyTorch)43M172Float32Float320.3930.746
DETRResnet50SemanticSegmentationF3243M171Float32Float320.3930.746
DETRResnet50SemanticSegmentationF1643M86Float16Float160.3950.746

IoU and Pixel accuracy measured on 512 images from the COCO dataset. The ground truth labels were extracted from the panoptic segmentation annotations, transformed to semantic segmentation masks. Input images were resized so that the smaller edge equals 448, then center-cropped.

Inference time

The following results refer to DETRResnet50SemanticSegmentationF16. The compute units for MacBook Pro (M1 Max) were manually selected to "CPU and Neural Engine".

DeviceOSInference time (ms)Dominant compute unit
iPhone 15 Pro Max17.540Neural Engine
MacBook Pro (M1 Max)14.543Neural Engine
iPhone 12 Pro Max18.052Neural Engine
MacBook Pro (M3 Max)15.029Neural Engine

Download

Install huggingface-cli

brew install huggingface-cli

To download one of the .mlpackage folders to the models directory:

huggingface-cli download \
  --local-dir models --local-dir-use-symlinks False \
  apple/coreml-detr-semantic-segmentation \
  --include "DETRResnet50SemanticSegmentationF16.mlpackage/*"

To download everything, skip the --include argument. This will retrieve float32 and float16 variants, as well as quantized versions of the float16 variant.

Integrate in Swift apps

The huggingface/coreml-examples repository contains sample Swift code for coreml-detr-semantic-segmentation and other models. See the instructions there to build the demo app, which shows how to use the model in your own Swift apps.

Contributors

pcuenq

20 commits

reach-vb

4 commits

apple/coreml-detr-semantic-segmentation

Model

34

stars

24

commits

2

linked in READMEs

Aug 9, 2024

updated

coreml
image-segmentation

README

DETR-Resnet50 (semantic segmentation) Core ML Models

See the Files tab for converted models.

DEtection TRansformer (DETR) model trained end-to-end on COCO 2017 object detection (118k annotated images). It was introduced in the paper End-to-End Object Detection with Transformers by Carion et al. and first released in this repository.

Model description

The DETR model is an encoder-decoder transformer with a convolutional backbone. Two heads are added on top of the decoder outputs in order to perform object detection: a linear layer for the class labels and a MLP (multi-layer perceptron) for the bounding boxes. The model uses so-called object queries to detect objects in an image. Each object query looks for a particular object in the image. For COCO, the number of object queries is set to 100.

The model is trained using a "bipartite matching loss": one compares the predicted classes + bounding boxes of each of the N = 100 object queries to the ground truth annotations, padded up to the same length N (so if an image only contains 4 objects, 96 annotations will just have a "no object" as class and "no bounding box" as bounding box). The Hungarian matching algorithm is used to create an optimal one-to-one mapping between each of the N queries and each of the N annotations. Next, standard cross-entropy (for the classes) and a linear combination of the L1 and generalized IoU loss (for the bounding boxes) are used to optimize the parameters of the model.

model image

Evaluation - Variants

VariantParametersSize (MB)Weight PrecisionAct. PrecisionIoUPixel accuracy
facebook/detr-resnet-50-panoptic (PyTorch)43M172Float32Float320.3930.746
DETRResnet50SemanticSegmentationF3243M171Float32Float320.3930.746
DETRResnet50SemanticSegmentationF1643M86Float16Float160.3950.746

IoU and Pixel accuracy measured on 512 images from the COCO dataset. The ground truth labels were extracted from the panoptic segmentation annotations, transformed to semantic segmentation masks. Input images were resized so that the smaller edge equals 448, then center-cropped.

Inference time

The following results refer to DETRResnet50SemanticSegmentationF16. The compute units for MacBook Pro (M1 Max) were manually selected to "CPU and Neural Engine".

DeviceOSInference time (ms)Dominant compute unit
iPhone 15 Pro Max17.540Neural Engine
MacBook Pro (M1 Max)14.543Neural Engine
iPhone 12 Pro Max18.052Neural Engine
MacBook Pro (M3 Max)15.029Neural Engine

Download

Install huggingface-cli

brew install huggingface-cli

To download one of the .mlpackage folders to the models directory:

huggingface-cli download \
  --local-dir models --local-dir-use-symlinks False \
  apple/coreml-detr-semantic-segmentation \
  --include "DETRResnet50SemanticSegmentationF16.mlpackage/*"

To download everything, skip the --include argument. This will retrieve float32 and float16 variants, as well as quantized versions of the float16 variant.

Integrate in Swift apps

The huggingface/coreml-examples repository contains sample Swift code for coreml-detr-semantic-segmentation and other models. See the instructions there to build the demo app, which shows how to use the model in your own Swift apps.

Contributors

pcuenq

20 commits

reach-vb

4 commits