MCPcopy Create free account
hub / github.com/expo/examples / useTensorFlowModel

Function useTensorFlowModel

with-tfjs-camera/src/useTensorFlow.js:4–24  ·  view source on GitHub ↗
(modelKind)

Source from the content-addressed store, hash-verified

2import React from "react";
3
4export function useTensorFlowModel(modelKind) {
5 const [model, setModel] = React.useState(null);
6
7 const isMounted = React.useRef(true);
8
9 React.useEffect(() => {
10 isMounted.current = true;
11 return () => (isMounted.current = false);
12 }, []);
13
14 React.useEffect(() => {
15 setModel(null);
16 modelKind.load().then((model) => {
17 if (isMounted.current) {
18 setModel(model);
19 }
20 });
21 }, [modelKind]);
22
23 return model;
24}
25
26export function useTensorFlowLoaded() {
27 const [isLoaded, setLoaded] = React.useState(false);

Callers 1

ModelView.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected