Dynamic import for tfjs-core

99 views
Skip to first unread message

munrocket

unread,
Jun 28, 2020, 4:21:21 AM6/28/20
to TensorFlow.js Discussion
Hello! I am trying to reduce download size for my library and using dynamic import.

navigator.mediaDevices.getUserMedia({ video: true }).then((stream) => {
Promise.all[
].then((modules) => {
return new Promise((resolve) => {
video.srcObject = stream;
video.onloadedmetadata = () => {
video.play();
video.width = video.videoWidth;
video.height = video.videoHeight;
setBackend('wasm').finally(async () => {
model = await modules[0]();
model.scoreThreshold = options.threshold;
requestAnimationFrame(render);
resolve(true);
});
};
});
});
}).catch(() => {
return false;
});

But the problem that I can't find ESM build for `tfjs-core`, seems that it's not exist. It's intentionally or just missing?
How to use dynamic import with tfjs-core? Right now I'm importing this at the top level.

import { setBackend } from '@tensorflow/tfjs-core';

munrocket

unread,
Jun 28, 2020, 4:49:21 AM6/28/20
to TensorFlow.js Discussion
Ah ok, it's not obivious but tfjs-core placed here:

Nikhil Thorat

unread,
Jun 29, 2020, 10:10:35 AM6/29/20
to munrocket, TensorFlow.js Discussion, Yannick Assogba
+Yannick Assogba for visibility

On Sun, Jun 28, 2020 at 4:49 AM munrocket <apif...@gmail.com> wrote:
Ah ok, it's not obivious but tfjs-core placed here:

--
You received this message because you are subscribed to the Google Groups "TensorFlow.js Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tfjs+uns...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tfjs/3f35fccb-6444-48e9-b441-a225ed35fa9co%40tensorflow.org.

Yannick Assogba

unread,
Jun 29, 2020, 11:25:01 AM6/29/20
to Nikhil Thorat, munrocket, TensorFlow.js Discussion
Hi,

The esm entry point can be found here https://cdn.jsdelivr.net/npm/@tensorflow/tfjs...@2.0.1/dist/index.js. This is the file referenced by our 'module' entry in our package.json.

Best
Yannick
Reply all
Reply to author
Forward
0 new messages