Name: powerai-vision-object-detection
Owner: International Business Machines
Description: Use deep learning to create a model and a REST endpoint to allow your app to detect, locate and count your product on store shelves
Created: 2017-12-09 01:53:30.0
Updated: 2018-05-22 22:15:57.0
Pushed: 2018-05-22 22:15:55.0
Homepage: https://developer.ibm.com/code/patterns/locate-and-count-items-with-object-detection/
Size: 41666
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
In this Code Pattern, we will use PowerAI Vision Object Detection to detect and label objects, within an image, based on customized training.
This example can easily be customized with your own datasets.
An example dataset has been provided with images of Coca-Cola bottles. Once we train and deploy a model, we'll have a REST endpoint that allows us locate and count Coke bottles in an image.
Deep learning training will be used to create a model for Object Detection. With PowerAI Vision, deep learning training is as easy as a few clicks of a mouse. Once the task has completed, the model can be deployed with another click.
PowerAI Vision presents REST APIs for inference operations. Object detection with your custom model can be used from any REST client and can also be tested in the PowerAI Vision UI.
When the reader has completed this Code Pattern, they will understand how to:
This Code Pattern was built with the PowerAI Vision Technology Preview v3.0.
To try the preview using the SuperVessel
cloud, login or register here.
If you have Power Systems and want to download an installer to deploy the preview on your own systems, register here.
NOTE: The steps and examples in this README assume you are using SuperVessel. For example, some URLs use ny1.ptopenlab.com.
Clone the powerai-vision-object-detection
locally. In a terminal, run:
clone https://github.com/IBM/powerai-vision-object-detection
If you are using SuperVessel, login here: https://ny1.ptopenlab.com/AIVision/index.html
PowerAI Vision Object Detection discovers and labels objects within an image, enabling users and developers to count instances of objects within an image based on customized training.
To create a new dataset for object detection training:
From the My Data Sets
view, click the Add Dataset
button and then select For Object Detection
in the pull-down.
Provide a DataSet Name and click Add Dataset
.
Upload one or more images using drag-and-drop or Select some
. You can use powerai-vision-object-detection/data/coke_bottles.zip from your cloned repo to upload many at once.
Note: If you are using your own zip file and do not see file thumbnails after the upload, then the upload failed. Use lowercase file names without special characters or spaces. You can also upload individual files or multi-select several at a time to determine which file caused the upload to fail.
Create one or more tags by clicking the +
icon to add a new tag. Each tag will represent the training objects within the image based on specific use cases (e.g., “Coca-Cola”, “Diet Coke”, “Coke Zero”).
Label the objects in each image by selecting a tag and dragging a bounding box around the object in the image. Press Save
when done with each image.
Repeat this process for all tags and all images.
Note: You can import powerai-vision-object-detection/data/coke_bottles_exported.zip which was already labeled and exported.
Tip: Use the
Only Show Unlabeled Files
pull-down to help you see when you are done.
You can use the Data Augmentation
button to expand your dataset. Label the original images first and be sure to consider whether mirror images (horizontal or vertical) are appropriate for your use case. If you use data augmentation, a new expanded dataset will be created for you.
Click Export As Zip File
to save a copy of your work. Now that you've spent some time labeling, this zip will let you start over without losing your work.
Click on My DL Tasks
under My Workspace and then click the Create New Task
button. Click on Object Detection
.
Give the Object Detector a name and make sure your dataset is selected, then click Build Model
.
A confirmation dialog will give you a time estimate. Click Create New Task
to get it started.
When the model is built, click on Deploy and Test
.
Test your model in the PowerAI Vision UI. Use Select some
to choose a test image. The result shows you how many objects were detected and the image is shown with bounding boxes, labels and confidence scores.
From a command-line, you can test your deployed REST endpoint using an image file and the curl
command. Notice the output JSON shows multiple bottles were detected and provides the confidence, label and location for each of them.
Warning: this example used
--insecure
for convenience.
rl --insecure -i -F files=@coke_bottle_23.png https://ny1.ptopenlab.com/AIVision/api/dlapis/9f9d6787-0183-4a1b-be49-751b6ca16724
/1.1 100 Continue
/1.1 200 OK
er: nginx/1.9.13
: Thu, 14 Dec 2017 21:58:26 GMT
ent-Type: application/json
ent-Length: 508
ection: keep-alive
ss-Control-Allow-Origin: *
ss-Control-Allow-Headers: origin, content-type, accept, authorization
ss-Control-Allow-Credentials: true
ss-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, HEAD
ss-Control-Allow-Origin: *
lassified" : [ { "confidence" : 0.9986369013786316 , "ymax" : 578 , "label" : "coca-cola" , "xmax" : 755 , "xmin" : 588 , "ymin" : 29} , { "confidence" : 0.9954010248184204 , "ymax" : 592 , "label" : "coca-cola" , "xmax" : 601 , "xmin" : 437 , "ymin" : 10} , { "confidence" : 0.8161203265190125 , "ymax" : 567 , "label" : "coca-cola" , "xmax" : 426 , "xmin" : 259 , "ymin" : 17}] , "imageUrl" : "http://ny1.ptopenlab.com:443/AIVision/temp/5a26dd3b-d8ba-4e01-8b93-5a43f28e97c7.png" , "result" : "success"}
An example web app demonstrates how to upload a picture, use the trained and deployed model, and display the detected objects by drawing bounding boxes and labels on the image. The functionality is similar to the above testing, but the code is provided for you to customize.
Use the Deploy to IBM Cloud button OR Run locally.
Press the above Deploy to IBM Cloud
button and then click on Deploy
.
In Toolchains, click on Delivery Pipeline to watch while the app is deployed. Once deployed, the app can be viewed by clicking 'View app'.
Use the IBM Cloud dashboard to manage the app. The app is named powerai-vision-object-detection
with a unique suffix.
Add your PowerAI Vision API endpoint:
Click on the app in the IBM Cloud dashboard.
Select Runtime
in the sidebar.
Hit Environment variables
in the middle button bar.
Hit the Add
button.
Add the name POWERAI_VISION_WEB_API_URL
and set the value to the web API that you deployed (above).
Hit the Save
button. The app will restart automatically.
Click on Visit App URL
to use the app.
Use your cloned repo to build and run the web app.
NOTE: These steps are only needed when running locally instead of using the
Deploy to IBM Cloud
button.
Copy the env.sample to .env. Edit the file to set the URL to point to the web API that you deployed (above).
Assuming you have pre-installed Node.js and npm, run the following commands:
owerai-vision-object-detection
install
start
Use a browser to go to the web UI. The default URL is http://localhost:8081.
Use the Choose File
button to choose a file. On a phone this should give you an option to use your camera. On a laptop, you choose an image file (JPG or PNG).
Press the Upload File
button to send the image to your web API and render the results.
The UI will show an error message, if you did not configure your POWERAI_VISION_WEB_API_URL or if your API is not deployed (in SuperVessel you can quickly redeploy every hour).