edgeai
v1.0.38
Published
Library for EdgeAI from cnr.ai
Downloads
8
Readme
edgeai - Library for EdgeAI
edgeai is a library for interfacing EdgeAI. It uses the HTTP REST interface and provides a set of simple promised-based function calls to manage and operate the AI device. You must have access to the device before you can use this device.
Get Started
The library uses Promise interface. To get started, the edgeai context must be initialized.
const edgeai = require('edgeai');
edgeai.init({ hostname: 'localhost' })
.then(context => console.log(context));
Topics
Upload File
You can use uploadFile
to upload an existing file in the directory. The response is a boolean where true
means success. The destination directory is the root directory in the device. For simplicity, this API does not support upload to other directories.
const edgeai = require('edgeai');
edgeai.init({ hostname: 'localhost' })
.then(context => edgeai.uploadFile(context, 'apple.jpg'))
.then(response => console.log(response));
Activate Model
You can activate a mlmodel using load
. Before activating the model, the model file should have been uploaded to the device. To activate, the model name, filenames and type should be specified in the API as follows. The response is a boolean where true
means success.
const edgeai = require('edgeai');
edgeai.init({ hostname: 'localhost' })
.then(context => edgeai.uploadFile(context, 'fruit.mlmodel')
.then(() => edgeai.load(
context,
{
model: 'fruit',
filenames: {
model: 'fruit.mlmodel',
},
type: 'classifier',
}
))
.then(response => console.log(response)));
Predict Image
Once the image is uploaded and the model is activated, you can simply predict the image by using predict
. The API takes 2 parameters namely the image filename and the model name.
const edgeai = require('edgeai');
edgeai.init({ hostname: 'localhost' })
.then(context => edgeai.predict(context, 'apple.jpg', 'fruit')
.then(response => console.log(response)));
The response contains an array output
which lists the recognizied objects. In this case, only one apple is recognized. The coordinate x
and y
is the center point of the object. The left
value means the number of pixels from the left edge of the image to the left side of the bounding box. The top
value means the number of pixels from the top edge of the image to the top side of the bounding box.
{
"success": true,
"output": [
{
"confidence": 1,
"left": 0,
"x": 230,
"object": "apple",
"top": 0,
"width": 460,
"height": 460,
"y": 230
}
]
}
Acquire Demo Device
Please send an email [email protected] to request for a demo device. The request will be evaluated based on business criteria.
All HTTP APIs
Please refer to here.