最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

react native - TypeError: Cannot read property 'prototype' of undefined, when creating faceDetection using @tens

programmeradmin0浏览0评论

I am developing a simple face detection in react native. i used tensorflow. and using mediapipe runtime. but its not creating or invoking the createDetector function.

i tried using both runtimes tfjs and mediapipe, tried with and without solutionPath, tried localPath instead of CDN in solutionPath.

but its just not calling that function. and below is what the catch block logged [TypeError: Cannot read property 'prototype' of undefined].

import '@tensorflow/tfjs-react-native';
import * as tf from '@tensorflow/tfjs';
import '@tensorflow/tfjs-backend-webgl';
import '@mediapipe/face_detection';
import * as faceDetection from '@tensorflow-models/face-detection';


  useEffect(() => {
    (async () => {
      try {

        const status = await Camera.requestCameraPermission();
        console.log('status', status);
        setHasPermission(status === 'granted');
  
        console.log('initialized');
        await tf.ready();
        console.log('tf is ready');
        
        const model = faceDetection.SupportedModels.MediaPipeFaceDetector;
        const detectorConfig = {
          runtime: 'mediapipe',
          solutionPath: "/@mediapipe/face_detection",
        };
        console.log('model fetched', model);

        console.log('FaceDetection Module:', faceDetection);

        if (!faceDetection.createDetector) {
          throw new Error('faceDetection.createDetector is undefined! Check imports.');
        }
  
        const faceDetector = await faceDetection.createDetector(model, detectorConfig);
        console.log('detector initialized', faceDetector);
        setDetector(faceDetector);
        setLoading(false);
        console.log('loading set to false');
      } catch (error) {
        console.log('error creating detector', error);
      }
    })();
  }, []);```



``` (NOBRIDGE) LOG  status granted
 (NOBRIDGE) LOG  initialized
 (NOBRIDGE) LOG  tf is ready
 (NOBRIDGE) LOG  model fetched MediaPipeFaceDetector

 (NOBRIDGE) LOG  FaceDetection Module: {"MediaPipeFaceDetectorMediaPipe": [Function MediaPipeFaceDetectorMediaPipe], "MediaPipeFaceDetectorTfjs": [Function MediaPipeFaceDetectorTfjs], "SupportedModels": {"MediaPipeFaceDetector": "MediaPipeFaceDetector"}, "createDetector": [Function createDetector]}

 (NOBRIDGE) LOG  error creating detector [TypeError: Cannot read property 'prototype' of undefined]```

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论