MCPcopy
hub / github.com/tensorflow/tfjs-examples / loadModel

Method loadModel

chrome-extension/src/service_worker.js:77–92  ·  view source on GitHub ↗

* Loads mobilenet from URL and keeps a reference to it in the object.

()

Source from the content-addressed store, hash-verified

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

Callers 1

constructorMethod · 0.95

Calls 2

classifyMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected