├── LICENSE ├── README.md ├── images ├── README.md └── exchange-landing-page.png ├── modules ├── module1 │ ├── README.md │ └── images │ │ ├── max-asset-components.png │ │ └── model-landing-page.png └── module2 │ ├── README.md │ └── images │ ├── annotated_objects.png │ └── architecture.png └── setup └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction to the Model Asset eXchange on IBM Developer 2 | 3 | The [Model Asset eXchange](https://developer.ibm.com/exchanges/models/) (MAX) on IBM Developer is a place where you can find and use free open source deep learning models for text, image, audio, and video processing and much more. The curated list includes _deployable_ models, which you can run as a microservice locally or in the cloud on Docker or Kubernetes, and _trainable_ models where you can use your own data to train the models. 4 | 5 | ![Model Asset Exchange landing page](images/exchange-landing-page.png) 6 | 7 | By completing this introductory tutorial you will learn how to deploy a model microservice and consume it in a basic web application. 8 | 9 | Tutorial modules: 10 | - [**Setup**](setup/) (Estimated time: 10 minutes) 11 | - [**Module 1: Run a deep learning microservice on Docker**](modules/module1) (Estimated time: 30 minutes) 12 | - Run a microservice using a pre-built Docker image 13 | - Run a microservice using a custom-built Docker image 14 | - [**Module 2: Consume a deep learning microservice**](modules/module2/) (Estimated time: 20 minutes) 15 | - Customize a sample Node.js or Python web app to consume a microservice 16 | 17 | 18 | Related links: 19 | - [Tutorial on IBM Developer](https://developer.ibm.com/tutorials/getting-started-with-the-ibm-code-model-asset-exchange/). 20 | - [MAX code patterns](http://ibm.biz/max-developers): Explore official sample applications that utilize MAX models, such as the [image caption generator](https://developer.ibm.com/patterns/create-a-web-app-to-interact-with-machine-learning-generated-image-captions/) or the [age estimator](https://developer.ibm.com/patterns/estimate-ages-for-detected-human-faces/). 21 | 22 | If you have any questions or feedback please [join the MAX community on Slack](https://join.slack.com/t/model-asset-exchange/shared_invite/enQtNDQ4OTQxODUyMTYwLWU2NTc4YTYxNjBhMWRlYWZkNTM5MjlkMDI4ZDI3YzQwMTYyZjk5YjU5NWU3MmNmN2FiNjg1MWFkYzQyODk3OTM). 23 | 24 | --- 25 | License: [Apache-2.0](LICENSE) 26 | -------------------------------------------------------------------------------- /images/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /images/exchange-landing-page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/max-developer-tutorial/0a2a9b94188579d09acfc2d438e00998b47e520f/images/exchange-landing-page.png -------------------------------------------------------------------------------- /modules/module1/README.md: -------------------------------------------------------------------------------- 1 | # Run a MAX model asset on Docker 2 | 3 | Deployable MAX model assets implement microservices that you can run on Docker or Kubernetes. 4 | 5 | ![Components of a MAX asset](images/max-asset-components.png) 6 | 7 | In this module you will learn how to: 8 | * run a model microservice on Docker using a pre-built Docker image from Docker Hub 9 | * run a model microservice on Docker using a custom-built Docker image 10 | * explore the model microservice 11 | 12 | If you just want to explore the functionality of a MAX model microservice in a local environment, you can run it by pulling the corresponding Docker image from [Docker Hub](https://hub.docker.com/u/codait/). 13 | 14 | ## Running the pre-built Docker image 15 | 16 | The pre-built Docker images provide an easy way to explore a model microservice without the need to install any software (aside from Docker) on your machine. However, since the image is pre-built you cannot customize the microservice or review its implementation. 17 | 18 | 1. Open the [Object Detector model page](https://developer.ibm.com/exchanges/models/all/max-object-detector/). 19 | 20 | ![Object Detector model landing page](images/model-landing-page.png) 21 | 22 | > Note: You can explore the model service API of some models by clicking the _Try the API_ button. 23 | 24 | 2. Locate the instructions to deploy the pre-built Docker image from Docker Hub and execute the listed [`docker run`](https://docs.docker.com/engine/reference/commandline/run/) command in a terminal window to start the microservice on your local machine. 25 | ``` 26 | $ docker run -it -p 5000:5000 codait/max-object-detector 27 | ... 28 | ``` 29 | 30 | > A status message is displayed once the container has started and the service is available, identifying the URL where the service can be accessed. 31 | 32 | 3. Open the displayed URL in a web browser. 33 | ``` 34 | ... 35 | Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) 36 | ... 37 | ``` 38 | 4. Explore the microservice specification. 39 | 40 | Each running microservice exposes at least the following three endpoints: 41 | 42 | * `GET /` - Returns the microservice's [Swagger](https://swagger.io/) specification. 43 | * `GET /model/metadata` - Returns information about the model that the microservice is serving, such as `name`, `description`, and `license`. 44 | * `POST /model/predict` - Returns the results of a prediction, given the provided input data. Supported input data types and formats vary by model. Refer to the service's Swagger endpoint description for details. 45 | 46 | Whenever a prediction is performed, the microservice takes care of 47 | 48 | * transforming the input (e.g. an image, text or a sound file) into a format that can be consumed by the deep learning model, 49 | * invoking the deep-learning framework API that the model was implemented in, and 50 | * filtering the model output and transforming it into an application-friendly format. 51 | 52 | 5. Try out the prediction endpoint. 53 | 54 | You can try out the model's prediction capability by invoking its `POST /model/predict` endpoint from the Swagger UI or by sending a request using any API client. You can find model specific example inputs in the models' GitHub repository. 55 | 56 | A simple curl-based example request for the Object Detector model might look as follows: 57 | 58 | ``` 59 | $ curl -F "image=@assets/dog-human.jpg" -XPOST http://localhost:5000/model/predict 60 | { 61 | "status": "ok", 62 | "predictions": [ 63 | { 64 | "label_id": "1", 65 | "label": "person", 66 | "probability": 0.944034993648529, 67 | "detection_box": [ 68 | 0.1242099404335022, 69 | 0.12507188320159912, 70 | 0.8423267006874084, 71 | 0.5974075794219971 72 | ] 73 | }, 74 | ... 75 | ``` 76 | 77 | 6. Stop the microservice. 78 | 79 | * Use the [`docker ps`](https://docs.docker.com/engine/reference/commandline/ps/) command to list running containers. 80 | 81 | ``` 82 | $ docker ps 83 | CONTAINER ID IMAGE 84 | 53... codait/max-object-detector 85 | ``` 86 | * Take note of the _CONTAINER ID_. 87 | * Run the [`docker stop`](https://docs.docker.com/engine/reference/commandline/stop/) command to stop the microservice. 88 | 89 | ``` 90 | $ docker stop 53... 91 | ``` 92 | 93 | --- 94 | ## Running a customizable Docker image 95 | 96 | You can review the Docker image content, such as the model serving code implementation, or customize the Docker image by cloning the Model asset's GitHub repository. 97 | 98 | 1. On the [Object Detector model page](https://developer.ibm.com/exchanges/models/all/max-object-detector/) click the **Get this model** button to navigate to the model's [GitHub repository](https://github.com/IBM/MAX-Object-Detector#run-locally). 99 | 100 | 2. Follow the instructions to build the model. The build process typically comprises of two steps: 101 | * Clone the source to your local machine. 102 | * Build the Docker image. 103 | 104 | To build the Object Detector Docker image you'd run the following commands in a terminal window: 105 | ``` 106 | $ git clone https://github.com/IBM/MAX-Object-Detector.git 107 | ... 108 | $ cd MAX-Object-Detector 109 | ``` 110 | 111 | The model serving code is typically implemented in Python using [Flask](http://flask.pocoo.org/) and a deep learning framework library, such as [TensorFlow](http://tensorflow.org/) or [PyTorch](https://pytorch.org/). 112 | 113 | > Note that the consumer of this service does not need to know which deep learning framework was used because the service API is framework agnostic. 114 | 115 | When you are ready to build the image, run the following command: 116 | 117 | ``` 118 | $ docker build -t max-object-detector . 119 | ... 120 | ``` 121 | 122 | During the build process the required dependencies are downloaded. 123 | > Note that this might take some time depending on the image you are building. 124 | 125 | Once the build process has completed it's time to deploy. 126 | 127 | 3. Execute the listed [`docker run`](https://docs.docker.com/engine/reference/commandline/run/) command in a terminal window to start the microservice: 128 | 129 | ``` 130 | $ docker run -it -p 5000:5000 max-object-detector 131 | ... 132 | ``` 133 | 134 | > A status message is displayed once the container has started and the service is available, identifying the URL where the service can be accessed. 135 | 136 | 4. Open the displayed URL in a web browser: 137 | 138 | ``` 139 | ... 140 | Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) 141 | ... 142 | ``` 143 | 144 | 5. Do not stop the container and do not terminate the terminal window. You will use the container in the next lab module. 145 | 146 | ## Summary 147 | 148 | In this module you 149 | * ran a model microservice on Docker using a pre-built Docker image from Docker Hub, 150 | * ran a model microservice on Docker using a custom-built Docker image, and 151 | * explored the model serving microservice. 152 | 153 | Continue to the [next module](/modules/module2). 154 | -------------------------------------------------------------------------------- /modules/module1/images/max-asset-components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/max-developer-tutorial/0a2a9b94188579d09acfc2d438e00998b47e520f/modules/module1/images/max-asset-components.png -------------------------------------------------------------------------------- /modules/module1/images/model-landing-page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/max-developer-tutorial/0a2a9b94188579d09acfc2d438e00998b47e520f/modules/module1/images/model-landing-page.png -------------------------------------------------------------------------------- /modules/module2/README.md: -------------------------------------------------------------------------------- 1 | # Consume a MAX model asset 2 | 3 | In the [previous module](/modules/module1) you've deployed a model serving microservice on Docker in a local environment and explored the service's API endpoints. 4 | 5 | In this module you will learn how to: 6 | * invoke the prediction endpoint of a model microservice, and 7 | * process and visualize the results using a simple web application. 8 | 9 | The following chart depicts the data flow between our sample web aplication (on the left) and the Object Detector model serving microservice: 10 | 11 | ![architecture](images/architecture.png) 12 | 13 | 14 | ## Setup 15 | 16 | 1. Ensure the model microservice is running by executing the following command in a terminal window. 17 | 18 | ``` 19 | $ curl -i http://localhost:5000/model/metadata 20 | ``` 21 | 22 | > If the command returns an error, start the microservice: 23 | 24 | > ```$ docker run -it -p 5000:5000 codait/max-object-detector``` 25 | 26 | In preparation for this tutorial we have created simple Node.js and Python web application stubs that you will complete by adding the code required to invoke the model microservice's prediction endpoint and process and visualize the results. 27 | 28 | Continue with the instructions for the programming language of your choice: 29 | * [Node.js](#consuming-using-nodejs) 30 | * [Python](#consuming-using-python) 31 | 32 | --- 33 | ## Consuming using Node.js 34 | --- 35 | 36 | 1. Clone the Node.js sample application repository https://github.com/IBM/max-tutorial-app-nodejs in a terminal window. 37 | 38 | ``` 39 | $ git clone https://github.com/IBM/max-tutorial-app-nodejs.git 40 | ... 41 | $ cd max-tutorial-app-nodejs 42 | ``` 43 | 44 | > Note: If you'd like to review the finished sample application (instead of completing the steps listed below), checkout the `solution` branch by running `git checkout solution` in the terminal window. 45 | 46 | 2. Open `static/index.html`, `static/js/webapp.js`, and `app.js` in your favorite editor. 47 | 48 | * `static/index.html` implements a simple web UI, providing users with the ability to select a PNG/JPG image from their local file system. 49 | * `static/js/webapp.js` contains Javascript code that invokes the model microservice's prediction endpoint `/model/predict`, parses the results, and draws annotated bounding boxes around detected objects. 50 | 51 | * `app.js` implements a simple [Express](https://expressjs.com)-based web server that serves the static application content (web pages, javascript, style sheets, etc) and redirects requests to the model microservice. 52 | 53 | 3. In `static/js/webapp.js` 54 | * Locate `TODO R1` and review the prediction request payload. The model you are using requires a PNG/JPG encoded _image_ file as input and accepts a threshold as optional input. The _threshold_ acts as a filter, removing detected objects from the result set that the model is less certain about. In this sample application we are overriding the default (0.7) for illustrative purposes with a lower value. 55 | * Locate `TODO T1` and replace the `**TODO**` placeholder with your microservice's prediction endpoint `/model/predict`. 56 | * Locate `TODO T2` and replace the `**TODO**` placeholder with your microservice's prediction request method `POST`. 57 | * Save your changes. 58 | 59 | > Note: Remember you can always review the Swagger specification for the supported model endpoints by opening the microservice URL (e.g. `http://localhost:5000/`) in a web browser. 60 | 61 | 4. Install the prerequisites and launch the application. 62 | 63 | ``` 64 | $ npm install 65 | $ npm start 66 | ``` 67 | 68 | 5. Open http://localhost:8090/ in your web browser. 69 | * In Safari: Open the _Network_ tab in the _Web Inspector_ (MacOS: <option><command><i>). 70 | * In Google Chrome: Open the _Network_ tab in the _Developer Tools_ (MacOS: <option><command><i>). 71 | * In Mozilla Firefox: Open the _Network_ tab in the _Web Developer Tools_ (MacOS: <option><command><i>). 72 | 73 | 6. Choose a sample image from the `assets/` directory (or any other PNG/JPG image you might have stored on your machine) and click **Detect Objects**. 74 | 75 | If you've defined the endpoint URL and request method properly, a message is displayed indicating that no objects were detected. This is expected because you have not yet customized the code that processes the microservice response. 76 | 77 | 7. In your browser's _Network_ tab inspect the response of your prediction request. It should look similar to this: 78 | ``` 79 | { 80 | "status": "ok", 81 | "predictions": [ 82 | { 83 | "label_id": "88", 84 | "label": "teddy bear", 85 | "probability": 0.9896332025527954, 86 | "detection_box": [ 87 | 0.27832502126693726, 88 | 0.5611844062805176, 89 | 0.643224835395813, 90 | 0.8432191610336304 91 | ] 92 | }, 93 | { 94 | "label_id": "1", 95 | "label": "person", 96 | "probability": 0.9879012107849121, 97 | "detection_box": [ 98 | 0.24251864850521088, 99 | 0.26926863193511963, 100 | 0.6558930277824402, 101 | 0.5768759846687317 102 | ] 103 | } 104 | ] 105 | } 106 | ``` 107 | 108 | The `predictions` array contains an entry for each detected object, identifying: 109 | 110 | * the object `label` (e.g. _person_, _dog_, _cat_), 111 | * the confidence (`probability`) that the detected object represents the specified label (1 = high confidence, 0 = low confidence), and 112 | * the coordinates (y_1, x_1, y_2, x_2) of a rectangle that encloses the detected object. 113 | 114 | 8. In `static/js/webapp.js` 115 | * Locate `TODO T3` and replace the `**TODO**` placeholder with `predictions`. 116 | * Save your changes. 117 | 118 | 9. Reload http://localhost:8090/ in your web browser and try to detect objects again. 119 | 120 | The application should display bounding boxes around detected objects along with the label. 121 | 122 | ![annotated_objects](images/annotated_objects.png) 123 | 124 | --- 125 | ## Consuming using Python 126 | --- 127 | 128 | 1. Clone the Python sample application repository https://github.com/IBM/max-tutorial-app-python in a terminal window. 129 | 130 | ``` 131 | $ git clone https://github.com/IBM/max-tutorial-app-python.git 132 | ... 133 | $ cd max-tutorial-app-python 134 | ``` 135 | 136 | > Note: If you'd like to review the finished sample application (instead of completing the steps listed below), checkout the `solution` branch by running `git checkout solution` in the terminal window. 137 | 138 | 2. Open `app.py` in your favorite editor. 139 | 140 | The application implements a simple [Flask](http://flask.pocoo.org)-based web server that serves the static application content (web pages, style sheets, etc) and invokes the model microservice's prediction endpoint. 141 | 142 | 3. In `app.py` 143 | * Locate `TODO R1` and review the prediction request payload. The model you are using requires a PNG/JPG encoded _image_ file as input and accepts a _threshold_ as optional input. The threshold acts as a filter, removing detected objects from the result set that the model is less certain about. In this sample application we are overriding the default (0.7) for illustrative purposes with a lower value. 144 | * Locate `TODO T1` and replace the `**TODO**` placeholder with your microservice's prediction endpoint `/model/predict`. 145 | * Save your changes. 146 | 147 | > Note: Remember you can always review the Swagger specification for the supported model endpoints by opening the microservice URL (e.g. `http://localhost:5000/`) in a web browser. 148 | 149 | 4. Install the prerequisites and launch the application in the terminal window. 150 | 151 | ``` 152 | $ pip install -r requirements.txt 153 | $ python app.py 154 | ``` 155 | 156 | 5. Open http://localhost:8090/ in your web browser. 157 | 158 | 6. Choose a sample image from the `assets/` directory (or any other PNG/JPG image you might have stored on your machine) and click **Detect Objects**. 159 | 160 | If you've defined the endpoint URL and request method properly, a message is displayed indicating that no objects were detected. This is expected because you have not yet customized the code that processes the microservice response. 161 | 162 | 7. Inspect the application's debug output. It should look similar to this: 163 | ``` 164 | { 165 | "status": "ok", 166 | "predictions": [ 167 | { 168 | "label_id": "88", 169 | "label": "teddy bear", 170 | "probability": 0.9896332025527954, 171 | "detection_box": [ 172 | 0.27832502126693726, 173 | 0.5611844062805176, 174 | 0.643224835395813, 175 | 0.8432191610336304 176 | ] 177 | }, 178 | { 179 | "label_id": "1", 180 | "label": "person", 181 | "probability": 0.9879012107849121, 182 | "detection_box": [ 183 | 0.24251864850521088, 184 | 0.26926863193511963, 185 | 0.6558930277824402, 186 | 0.5768759846687317 187 | ] 188 | } 189 | ] 190 | } 191 | ``` 192 | 193 | The `predictions` array contains an entry for each detected object, identifying: 194 | 195 | * the object `label` (e.g. _person_, _dog_, _cat_), 196 | * the confidence (`probability`) that the detected object represents the specified label (1 = high confidence, 0 = low confidence), and 197 | * the coordinates (y_1, x_1, y_2, x_2) of a rectangle that encloses the detected object. 198 | 199 | 8. In `app.py` 200 | * Locate `TODO T2`, uncomment the next line and replace the `**TODO**` placeholder with `predictions`. 201 | * Save your changes. 202 | 203 | 9. Reload http://localhost:8090/ in your web browser and try to detect objects again. 204 | 205 | The application should display bounding boxes around detected objects along with the label. 206 | 207 | ![annotated_objects](images/annotated_objects.png) 208 | 209 | 210 | ## Summary 211 | 212 | In this module you 213 | * added code to invoke a deep learning model prediction endpoint, and 214 | * processed and visualized the response. 215 | 216 | End of module 217 | -------------------------------------------------------------------------------- /modules/module2/images/annotated_objects.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/max-developer-tutorial/0a2a9b94188579d09acfc2d438e00998b47e520f/modules/module2/images/annotated_objects.png -------------------------------------------------------------------------------- /modules/module2/images/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IBM/max-developer-tutorial/0a2a9b94188579d09acfc2d438e00998b47e520f/modules/module2/images/architecture.png -------------------------------------------------------------------------------- /setup/README.md: -------------------------------------------------------------------------------- 1 | # Tutorial setup 2 | 3 | Time required: 10 minutes 4 | 5 | 1. [Download](https://www.docker.com/products/docker-desktop), install, and launch Docker Desktop on your local machine. 6 | 2. [Download](https://git-scm.com/downloads) and install git. 7 | 3. If you want to complete tutorial module 2 (instead of just reviewing the solution) make sure [Node.js](https://nodejs.org/en/) or [Python](https://www.python.org/) is installed. 8 | 9 | You are ready to [start the tutorial](/modules/module1). 10 | --------------------------------------------------------------------------------