Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[MXNET-116] Inference - ObjectDetector and SSDObjectDetectorExample #10229

Merged
merged 6 commits into from
Mar 24, 2018

Conversation

lanking520
Copy link
Member

@lanking520 lanking520 commented Mar 23, 2018

Description

Add Object Detection Class for MXNet Inference API, also add test and example to it. This code is fully tested with SSD model.
@Roshrini @nswamy @aaronmarkham

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

@@ -0,0 +1,116 @@
# Single Shot Multi Object Detection using Scala Inference API

In this example, you will learn how to use Scala Inference API to import pre-trained Single Shot Multi Object Detection (SSD) MXNet model.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this example, you will learn how to use Scala Inference API to run Inference on pre-trained Single Shot Multi Object Detection (SSD) MXNet model.


In this example, you will learn how to use Scala Inference API to import pre-trained Single Shot Multi Object Detection (SSD) MXNet model.

The pre-trained model is trained on the [Pascal VOC 2012 dataset](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/index.html). The network is a SSD model built on Resnet50 as base network to extract image features. The model is trained to detect the following entities (classes): ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']. For more details about the model, you can refer to the [MXNet SSD example](https://github.com/apache/incubator-mxnet/tree/master/example/ssd).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The model is trained on the [Pascal VOC 2012 dataset]

./get_resnet_data.sh
```

**Note**: You may need to run `chmod +x get_resnet_data.sh` before running this script.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need this if the file already is set to be a executable?
Also you do not need to chmod+x if you running the script as bash ./get_resnet_data.sh

In the pre-trained model, the `input_name` is `data` and shape is `(1, 3, 512, 512)`.
This shape translates to: a batch of `1` image, the image has color and uses `3` channels (RGB), and the image has the dimensions of `512` pixels in height by `512` pixels in width.

The signature also specifies `image/jpeg` as the expected input type, since this example's image pre-processor only supports the handling of binary JPEG images.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this? copy paste error?


The signature also specifies `image/jpeg` as the expected input type, since this example's image pre-processor only supports the handling of binary JPEG images.

The signature specifies the output shape is `(1, 6132, 6)`. As with the input, the `1` is the number of images. `6132` is the number of prediction results, and `6` is for the size of each prediction. Each prediction contains the following components:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is signature?



## Infer API Details
This example uses ObjectDetector class provided by MXNet's scala package Infer APIs. It provides methods to load the images, create NDArray out of BufferedImage and run prediction using Classifier and Predictor APIs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BufferedImage-> Java BufferedImage

import java.nio.file.{Files, Paths}

class SSDClassifierExample {
@Option(name = "--model-dir", usage = "the input model directory and prefix of the model")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--model-path-prefix

class ObjectDetector(modelPathPrefix: String,
inputDescriptors: IndexedSeq[DataDesc]) {

val classifier: Classifier = getClassifier(modelPathPrefix, inputDescriptors)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ImageClassifier instead?


// Considering 'NCHW' as default layout when not provided
// Else get axis according to the layout
val height = inputShape(if (inputLayout.indexOf('H')<0) 2 else inputLayout.indexOf('H'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use these variables from the ImageClassifier.


val result = objectDetectWithNDArray(IndexedSeq(op), topK)
handler.execute(op.dispose())
for (ele <- imageBatch) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imageBatch.foreach(_.dispose())

@nswamy nswamy merged commit 4950f66 into apache:master Mar 24, 2018
ashokei pushed a commit to ashokei/incubator-mxnet that referenced this pull request Mar 27, 2018
…pache#10229)

* Inference - ObjectDetector and SSDObjectDetectorExample
jinhuang415 pushed a commit to jinhuang415/incubator-mxnet that referenced this pull request Mar 30, 2018
…pache#10229)

* Inference - ObjectDetector and SSDObjectDetectorExample
@lanking520 lanking520 deleted the scala-package branch April 4, 2018 18:26
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
…pache#10229)

* Inference - ObjectDetector and SSDObjectDetectorExample
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
…pache#10229)

* Inference - ObjectDetector and SSDObjectDetectorExample
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants