├── modules ├── imageRecognition.js └── returnImageByExtent.js ├── README.md ├── index.html └── main.js /modules/imageRecognition.js: -------------------------------------------------------------------------------- 1 | // Tensorflow.js code! 2 | 3 | define([], 4 | function() { 5 | return { 6 | getPredictions: function(imageElement) { 7 | async function init() { 8 | let model = await tmImage.load("./models/model.json", "./models/metadata.json"); 9 | const prediction = await model.predict(imageElement); 10 | console.table(prediction); // returns predictions as a table. 11 | }; 12 | 13 | init(); 14 | } 15 | }; 16 | }) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Machine Learning Mapping sample 2 | 3 | This is a quick demo/showcase of the workflow of getting Tensorflow.js working with an image service in the ArcGIS API for JavaScript. 4 | 5 | 6 | ## The Tech 7 | 1. Models trained using [https://teachablemachine.withgoogle.com/train](https://teachablemachine.withgoogle.com/train). 8 | 2. Machine Learning Library is [TensorFlow.js](https://www.tensorflow.org/js) 9 | 3. Mapping API used is the ArcGIS API for JavaScript 10 | 11 | 12 | ## Getting Started 13 | 14 | If you don't know what image service to use... You'd need a [developer subscription](https://pip.pypa.io/en/stable/) to use the following image service - https://tiledbasemaps.arcgis.com/arcgis/rest/services/World_Imagery/MapServer. 15 | 16 | This sample is built to be using the code exported from [Google's Teachable Machine](https://teachablemachine.withgoogle.com/). Simply place the files in the .models/ folder. 17 | -------------------------------------------------------------------------------- /modules/returnImageByExtent.js: -------------------------------------------------------------------------------- 1 | // Fetching image from image service. 2 | 3 | define([ 4 | "esri/layers/MapImageLayer", 5 | "dojo/Deferred" 6 | ], 7 | function(MapImageLayer, Deferred) { 8 | let dataImageObject; 9 | return { 10 | getimageData: function(url, extent) { 11 | dataImageObject = new Deferred(); 12 | 13 | // Imagery layer (/mapserver) 14 | // Note, export needs to be enabled on the REST service for this to work. 15 | const layer = new MapImageLayer({ 16 | url: url 17 | }); 18 | 19 | const height = "500"; 20 | const width = "500"; 21 | 22 | layer.fetchImage(extent, height, width).then(function(data) { 23 | dataImageObject.resolve(data); 24 | }); 25 | 26 | return dataImageObject.promise; 27 | } 28 | }; 29 | }) -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 |