* Loads mobilenet from URL and keeps a reference to it in the object.
()
| 75 | * Loads mobilenet from URL and keeps a reference to it in the object. |
| 76 | */ |
| 77 | async loadModel() { |
| 78 | console.log('Loading model...'); |
| 79 | const startTime = performance.now(); |
| 80 | try { |
| 81 | this.model = await mobilenet.load({ version: 2, alpha: 1.00 }); |
| 82 | // Warms up the model by causing intermediate tensor values |
| 83 | // to be built and pushed to GPU. |
| 84 | tf.tidy(() => { |
| 85 | this.model.classify(tf.zeros([1, IMAGE_SIZE, IMAGE_SIZE, 3])); |
| 86 | }); |
| 87 | const totalTime = Math.floor(performance.now() - startTime); |
| 88 | console.log(`Model loaded and initialized in ${totalTime} ms...`); |
| 89 | } catch (e) { |
| 90 | console.error('Unable to load model', e); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Triggers the model to make a prediction on the image referenced by the |
no test coverage detected