TensorFlow js, model.detect не определен - PullRequest
0 голосов
/ 04 августа 2020

Я sh Я могу четко объяснить свою проблему, я хочу создать настраиваемую модель обнаружения объектов с помощью Tensorflow js, я использовал https://cloud.annotations.ai/ платформу для ML, и я создал свою модель успешно, и я могу протестировать эту модель на этой платформе, но когда я пытаюсь загрузить эту модель в свой код (код реакции), у меня возникает эта проблема

Uncaught (в обещании) TypeError: model. обнаружение не является функцией в _callee $ (ObjectDetectionVideo. js: 16) в tryCatch (время выполнения. js: 63) в Generator.invoke [как _invoke] (время выполнения. js: 293) в Generator.next ( runtime. js: 118) в asyncGeneratorStep (asyncToGenerator. js: 3) в _next (asyncToGenerator. js: 25) в asyncToGenerator. js: 32 в новом Promise () в asyncToGenerator. js: 21 в ObjectDetectionVideo. js: 13 в HTMLVideoElement.videoRef.current.onloadedmetadata (useWebcam. js: 18) _callee $ @ ObjectDetectionVideo. js: 16 tryCatch @ runtime. js: 63 invoke @ runtime. js: 293 (анонимно) @ время выполнения. js: 118 как yncGeneratorStep @ asyncToGenerator. js: 3 _next @ asyncToGenerator. js: 25 (анонимно) @ asyncToGenerator. js: 32 (анонимно) @ asyncToGenerator. js: 21 (анонимно) @ ObjectDetection jsVideo. 13 videoRef.current.onloadedmetadata @ useWebcam. js: 18 это мой код

import React from 'react'
import ReactDOM from 'react-dom'
import { useEffect, useState } from 'react'

import useModel from './useModel'
import models from '@cloud-annotations/models'
import ObjectDetectionVideo from './object-detection-video/ObjectDetectionVideo'
import * as tf from '@tensorflow/tfjs';

import './index.css'

const handlePrediction = (predictions) => {
  console.timeEnd('detect')
  console.time('detect')
  console.log(predictions)
}

const render = (ctx, predictions) => {
  predictions.forEach((prediction) => {
    const x = prediction.bbox[0]
    const y = prediction.bbox[1]
    const width = prediction.bbox[2]
    const height = prediction.bbox[3]

    ctx.setStrokeStyle('#0062ff')
    ctx.setLineWidth(4)
    ctx.strokeRect(
      Math.round(x),
      Math.round(y),
      Math.round(width),
      Math.round(height)
    )
  })
}

const App = () => {
   const model = tf.loadLayersModel("Id_detector/model.json");//useModel(process.env.PUBLIC_URL + '/model_web')
 
console.log(process.env.PUBLIC_URL + '/model_web')

  return (
    <div className="fillPage">
      <ObjectDetectionVideo
        model={model}
         onPrediction={handlePrediction}
         render={render}
        // aspectFill: The option to scale the video to fill the size of the view.
        //             Some portion of the video may be clipped to fill the view's
        //             bounds.
        // aspectFit:  The option to scale the video to fit the size of the view
        //             by maintaining the aspect ratio. Any remaining area of the
        //             view's bounds is transparent.
        fit="aspectFill"
        // mirrored:   mirror the video about its vertical axis.
        mirrored
      />
    </div>
  )
}

const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...