Object Detection
Overview
A detection describes the object's position at one moment in time with a set of skeletal landmark points. Type of object depends on the model and dataset used to train it.
Install SDK
You can install our SDK for your device by following the guide at: Getting Started.
Downloading the Model
Download the Efficient Detector or you can use any object detection model from the EdgeStore.
Running Inference
Place the edgem file in your project or assets and run the following code:
let modelPath:String = Bundle.main.path(forResource: "efficientdet-d4-lite", ofType: "edgem")!
let model = EdgeModel(modelPath: modelPath)
// Preparing data for model
let image = // your input image
// Run the model on prepared inputs and get recognitions as output
let results: Results = model.run([image])
// Draw the results on your Image or UI
let drawnImage = results.draw(on:image)
// Use the results in your app logic:
for detection in results.recognitions{
let label:EEMLabel = detection.label!
// In this case it can be any COCO category
let name:String = label.name!
// Probability of detection between 0-1
let confidence:Float = detection.confidence
// location of object inside the input image
let location:CGRect = detection.location
}
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"model" ofType:@"edgem"];
EdgeModel* model = [[EdgeModel alloc] initWithModelPath:modelPath];
// Preparing data for model
CVPixelBufferRef image = // your input image
// Run the model on prepared inputs and get results as output
Results* results = [model run:@[ (__bridge id)image]];
// Draw the results on your Image or UI
[results drawOnPixelBuffer:image ];
// Use the results in your app logic:
for (Recognition* detection in results.recognitions) {
// name of detected object
NSString *name = detection.label.name;
// Probability of detection between 0-1
float confidence = detection.confidence;
// location of object inside the input image
CGRect location = detection.location;
}
val model = EdgeModel.fromAsset(context, "efficientdet-d4-lite.edgem")
// Preparing data for model
val image = // your input image
// Run the model on prepared inputs and get recognitions as output
val recognitions: Recognitions = model.run(listOf(image))
// Draw the recognitions on your Image or UI
val drawing: Bitmap = recognitions.drawOnBitmap(image)
// Use the recognitions in your app:
for (detection in recognitions) {
val id = detection.id!!
val displayName = detection.displayName!!
val confidence = detection.confidence!!
val location = detection.location!!
val color = detection.color!!
}
EdgeModel model = EdgeModel.fromAsset(context, "efficientdet-d4-lite.edgem");
// Preparing data for model
Bitmap image = // your input image
// Run the model on prepared inputs and get recognitions as output
Recognitions recognitions = model.run(Arrays.asList(image));
// Draw the recognitions on your Image or UI
Bitmap drawing = recognitions.drawOnBitmap(image);
// Use the recognitions in your app:
for (Recognition detection : recognitions) {
var id = detection.id;
var displayName = detection.displayName;
var confidence = detection.confidence;
var location = detection.location;
var color = detection.color;
}
from edgeengine import EdgeModel
import matplotlib.pyplot as plt
model = EdgeModel("efficientdet-d4-lite.edgem")
image = #your input np.ndarray image
results = model.run([image])
# draw results on input image
visualization = results.visualize(image)
# show results
plt.imshow(visualization)
plt.show()
# Use results
for detection in results.recognitions:
class_id = detection.id
display_name = detection.display_name
confidence = detection.confidence
location = detection.location
color = detection.color
Supported Image Formats
We support following input formats for images:
-
CvPixelBuffer (Recommended, iOS)
-
UIImage (Slow, iOS)
-
Bitmap (Android)
Interpreting and Using Results
The output results variable has type Recognitions that is a type of List. All the useful
information the model provides is compacted into this variable. Not matter your use case the output of model will always be Recognitions object. You can use location (inside the for loop) data to get coordinates of each object.
Coordinate System
Our coordinate system is same as used in UIKit. i.e. our origin is at top left corner of image, with x axis to the right and y axis to the bottom.
The recognitions object returned after model execution provides coordinates in image domain. i.e. 0 < x < Input Image Width and 0 < y < Input Image Height.
You can directly apply transformations on Recognitions object by using the Recognitions.map function in Android or Recogntitions.applying in iOS