-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as React from "react"; | ||
import { Text, View } from "react-native"; | ||
import * as tensorflow from "@tensorflow/tfjs"; | ||
import styles from "./styles"; | ||
|
||
// TODO: Make this an env variable | ||
const ORIGIN = | ||
"https://tfhub.dev/tensorflow/tfjs-model/ssd_mobilenet_v2/1/default/1"; | ||
|
||
interface Props { | ||
setGraph: (graph: tensorflow.GraphModel) => void; | ||
} | ||
|
||
export default function LoadGraph(props: Props): JSX.Element { | ||
const { setGraph } = props; | ||
const [progress, setProgress] = React.useState(0); | ||
|
||
React.useEffect(() => { | ||
const loadGraph = async () => { | ||
await tensorflow.ready(); | ||
|
||
const options = { | ||
fromTFHub: true, | ||
onProgress: (loading: number) => { | ||
setProgress(Math.round(loading * 100)); | ||
} | ||
}; | ||
|
||
const graph = await tensorflow.loadGraphModel(ORIGIN, options); | ||
|
||
setGraph(graph); | ||
}; | ||
|
||
loadGraph().catch((error) => { | ||
console.info(`Error!: ${error}`); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<View style={styles.loading}> | ||
<Text style={styles.loadingHeader}>Loading model…</Text> | ||
<View style={styles.progressContainer}> | ||
<View style={styles.progressBar}> | ||
<View style={{ ...styles.progress, width: `${progress}%` }} /> | ||
</View> | ||
<Text>{progress}%</Text> | ||
</View> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { StyleSheet } from "react-native"; | ||
|
||
export default StyleSheet.create({ | ||
loading: { | ||
alignItems: "center", | ||
display: "flex", | ||
flexDirection: "column", | ||
height: "100%", | ||
justifyContent: "center", | ||
paddingHorizontal: 20 | ||
}, | ||
loadingHeader: { | ||
fontSize: 20, | ||
marginBottom: 4, | ||
textAlign: "center" | ||
}, | ||
progressContainer: { | ||
display: "flex", | ||
justifyContent: "space-between", | ||
overflow: "hidden", | ||
width: "100%" | ||
}, | ||
progressBar: { | ||
backgroundColor: "white", | ||
borderColor: "black", | ||
borderRadius: 4, | ||
borderWidth: 2, | ||
// flex: 1, | ||
height: 12, | ||
marginBottom: 4 | ||
}, | ||
progress: { | ||
backgroundColor: "black", | ||
height: "100%" | ||
} | ||
}); |