Name: watson-waste-sorter
Owner: International Business Machines
Description: Create an iOS phone application that sorts waste into three categories (landfill, recycling, compost) using a Watson Visual Recognition custom classifier
Created: 2017-10-20 18:59:26.0
Updated: 2018-05-21 15:44:59.0
Pushed: 2018-04-27 13:34:25.0
Homepage: https://developer.ibm.com/code/patterns/recycle-with-watson/
Size: 54588
Language: Swift
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
In this developer code pattern, we will create a mobile app, Python Server with Flask, and Watson Visual Recognition. This mobile app sends pictures of waste and garbage to be analyzed by a server app, using Watson Visual Recognition. The server application will use pictures of common trash to train Watson Visual Recognition to identify various categories of waste, e.g. recycle, compost, or landfill. A developer can leverage this to create their own custom Visual Recognition classifiers for their use cases.
When the reader has completed this Code Pattern, they will understand how to:
Create an IBM Cloud account and install the Cloud Foundry CLI on your machine.
You can either go through Step 1 and 2 to create your application server, or
You can simply click the Deploy to IBM Cloud
button and Create
the toolchain to provision, train, and run your visual recognition server.
Then, go to the IBM Cloud Dashboard to verify your server is running and take note of your
server application's endpoint. Once you done that, you can move on to Step 3
and deploy your mobile application.
First, we need to clone this repository
clone https://github.com/IBM/watson-waste-sorter
atson-waste-sorter
Then, we need to login to the Cloud Foundry CLI.
ogin -a https://api.ng.bluemix.net # Please use a different API endpoint if your IBM Cloud account is not in US-South
Next, provision a Free tier Visual Recognition
Service and name it visual-recognition-wws
. You can provision it using the above link or the command below.
reate-service watson_vision_combined free visual-recognition-wws
Then, either use the Visual Recognition Web UI or Command Line to create your custom model.
After you provision the Visual Recognition service, create a new credential under the Service credentials
tab on the left side of the Web UI. Now, you should see the api_key
for the service. Use it to access the Visual Recognition Tool Web UI and create your own custom visual recognition model.
In the Visual Recognition Tool, click Create classifier
. Then, upload the zipped image files from server/resources
to the corresponding class as shown below. Make sure you name your classifier waste
and the three classes should be Landfill
, Recycle
, and Compost
. (All the names should be case sensitive).
Click Create
after you uploaded all the files to the corresponding class. Now the visual recognition should start training the new custom model. The training process should take about 20 to 30 minutes, so you can start deploying the server and mobile app while waiting for it.
After you provision the Visual Recognition service, run the following command to create your Visual Recognition API KEY
reate-service-key visual-recognition-wws waste-sorter
KEY=$(cf service-key visual-recognition-wws waste-sorter | awk ' /api_key/ {print $2;exit}' | tr -d "\",")
Now go to the server directory. Let's create our custom model using the sample zipped image files we have under server/resources
erver
$API_KEY # Make sure your API_KEY is not empty
-X POST -F "Landfill_positive_examples=@resources/landfill.zip" -F "Recycle_positive_examples=@resources/recycle.zip" -F "Compost_positive_examples=@resources/compost.zip" -F "negative_examples=@resources/negative.zip" -F "name=waste" "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers?api_key=$API_KEY&version=2016-05-20"
You can run the following commands to check your model status.
is command will retrieve all your custom models
-X GET "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers?api_key={$API_KEY}&version=2016-05-20"
place <classifier_id> with the model classifier_id to view its status
-X GET "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers/<classifier_id>?api_key={$API_KEY}&version=2016-05-20"
Now in the server repository, push your server application to Cloud Foundry
ush
Once the deployment succeeds, your backend server will be running in the cloud and be able to classify the different kinds of waste once the model finishes training. Please take note of your server application's endpoint as you will need it in the next step. Now let's go ahead and create our mobile app to use this classifier.
In order to test the full features for this application, you need to have Xcode 8.0 or above installed and an IOS device to deploy the application.
Now Open your Xcode and select Open another project...
, then select the mobile-app/WatsonWasteSorter.xcworkspace
file and click Open
.
Next, you need to modify the WatsonWasteSorter/Info.plist
with the endpoint of the API server you just deployed. Replace the SERVER_API_ENDPOINT
's value section
with your server endpoint with extension /api/sort
.
Next, you will need to sign your application with your Apple account. Go to the mobile app's General
section, under Signing
's Team select your team or add an account. Now your mobile app is signed and you are ready to deploy your Waste Sorter app.
Note: If you have trouble signing your Mobile app, please refer to https://help.apple.com/xcode/mac/current/#/dev60b6fbbc7
Now, connect your IOS device to your machine and select your device in Xcode. Click the run icon and your mobile app will be installed on your device.
Congratulations, at this point you should have a mobile app that can classify waste using your camera. Now you can just simply point your camera to any waste and click the camera icon to take a picture. Then the application should tell you where the waste should go like this.
Now you should have a better idea on how to sort your trash. Note that if you have a result that said unclassified
, it means your image is either too blurry or the
waste is too far. In that case just simply point your camera closer and retake a new picture.
If you want to classify another waste item, simply click the center of the screen.