-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
63 lines (53 loc) · 1.89 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React, { useEffect, useMemo, useCallback, useState } from 'react'
import { useFonts, loadAsync } from 'expo-font'
import { SafeAreaView, Text } from 'react-native'
import LoadingIndicator from './src/components/Loading/LoadingView'
// import AppLoading from 'expo-app-loading'
import RootStack from './src/navigators/RootStack'
// import tensorflow model before app start
import * as tf from '@tensorflow/tfjs'
import * as poseDetection from '@tensorflow-models/pose-detection'
import '@tensorflow/tfjs-react-native'
/** constance variable */
// prettier-ignore
import { CANVAS_HEIGHT, CANVAS_WIDTH } from './src/feat/screenSize'
const detectorConfig: poseDetection.PosenetModelConfig = {
architecture: 'ResNet50',
outputStride: 16,
inputResolution: { width: CANVAS_WIDTH, height: CANVAS_HEIGHT },
quantBytes: 2,
}
export default function App() {
const [model, setModel] = useState<poseDetection.PoseDetector>()
let [fontsLoaded] = useFonts({
'Lato-Regular': require('./assets/fonts/Lato-Regular.ttf'),
'DancingScript-Regular': require('./assets/fonts/DancingScript-Regular.ttf'),
'NanumPenScript-Regular': require('./assets/fonts/NanumPenScript-Regular.ttf'),
})
const getModel = useMemo(
useCallback(async () => {
try {
console.log('try ... importing model')
await tf.ready()
const detector = await poseDetection.createDetector(
poseDetection.SupportedModels.PoseNet,
detectorConfig
)
setModel(detector)
} catch (e) {
console.log('error to import model the reason: ' + e)
}
}, []),
[]
)
// app mount시 실행.
useEffect(() => {
getModel
useFonts
}, [])
// font가 로드되지않았거나, model이 로드되지 않은 경우,
if (!fontsLoaded || !model) {
return <LoadingIndicator size={100} text={'Load to resource ...'} />
}
return <RootStack model={model} />
}