提问人:Jasir ullah Khan 提问时间:7/27/2023 更新时间:7/27/2023 访问量:86
加载“@tensorflow-models/coco-ssd”时收到“无法读取未定义的属性'fetch'”
Getting "Cannot read property 'fetch' of undefined", while loading "@tensorflow-models/coco-ssd"
问:
我正在 React Native 中开发一个应用程序,其主要目的是从图库中选择一个视频并在其上运行对象检测模型。我目前正在使用一个名为“coco-ssd”的 TensorFlow 模型。
根据他们的文档,我首先需要加载模型,然后再继续。但是,我在这里遇到了一个问题:当我尝试加载模型时,它会抛出错误“无法读取未定义的属性'fetch'”。这是我的代码: -
import React, {useEffect, useState} from 'react';
import {Button, SafeAreaView, View} from 'react-native';
import {launchImageLibrary} from 'react-native-image-picker';
import * as cocossd from '@tensorflow-models/coco-ssd';
import * as tf from '@tensorflow/tfjs';
import '@tensorflow/tfjs-react-native';
function App(): JSX.Element {
const [videoUri, setVideoUri] = useState(null);
const loadCocoModel = async () => {
try {
await tf.ready();
console.log('Tensorflow ready');
const model = await cocossd.load();
console.log('Handpose model loaded.');
detect(model);
} catch (error) {
console.log(error);
}
};
useEffect(() => {
loadCocoModel();
}, []);
const detect = (model: cocossd.ObjectDetection) => {
console.log('TODO: implement detect');
};
const selectVideo = async () => {
try {
const response: any = await launchImageLibrary({
mediaType: 'video',
});
if (!response.didCancel && response.assets.length > 0) {
setVideoUri(response.assets[0].uri);
}
} catch (error) {
console.log(error);
}
};
return (
<SafeAreaView>
<View
style={{
justifyContent: 'center',
alignItems: 'center',
height: '100%',
}}>
<Button title="Select Video" onPress={selectVideo} />
</View>
</SafeAreaView>
);
}
export default App;
我希望有解决此问题的解决方案或建议。提前感谢您的帮助。
答: 暂无答案
评论