Comments (4)
Update:
Switch to tfjs works.
const detectorConfig = {
runtime: "tfjs",
maxHands: 2,
solutionPath: "https://cdn.jsdelivr.net/npm/@tensorflow-models/hand-pose-detection"
//solutionPath: "https://cdn.jsdelivr.net/npm/@mediapipe/hands/",
};
Reference: https://discuss.tensorflow.org/t/typeerror-when-attempting-to-create-mediapipehands-detector/7602
from tfjs.
Hi, @thiagodegan
I apologize for the delayed response and Good to hear that your issue has been resolved after changing the runtime to tfjs
instead of mediapipe
and if I'm not wrong it seems like this issue is happening from mediapipe end so internally we will discuss this issue with mediapipe team to fix this issue soon if possible.
If your issue got resolved then please feel free to close this issue. Thank you for your understanding and patience.
from tfjs.
import React, { useRef, useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import * as handpose from '@tensorflow-models/handpose';
import * as tf from '@tensorflow/tfjs';
import Webcam from 'react-webcam';
import RockImage from './assets/images/rock.png';
import PaperImage from './assets/images/paper.png';
import ScissorsImage from './assets/images/scissors.png';
import * as fp from 'fingerpose';
import { victoryDescription } from './assets/models/scissor';
import {Rock} from './assets/models/rock';
import {PaperGesture} from './assets/models/paper';
function Singleplayer() {
const location = useLocation();
const { selectedAvatar = '', username = '' } = location.state || {};
const choices = ['rock', 'paper', 'scissors'];
const choiceImages = { rock: RockImage, paper: PaperImage, scissors: ScissorsImage };
const [userScore, setUserScore] = useState(0);
const [botScore, setBotScore] = useState(0);
const [userChoice, setUserChoice] = useState(null);
const [botChoice, setBotChoice] = useState(null);
const webcamRef = useRef(null);
const canvasRef = useRef(null);
useEffect(() => {
const runHandpose = async () => {
await tf.setBackend('webgl');
const net = await handpose.load();
setInterval(() => {
detect(net);
}, 100);
};
runHandpose();
}, []);
const detect = async (net) => {
if (
typeof webcamRef.current !== 'undefined' &&
webcamRef.current !== null &&
webcamRef.current.video.readyState === 4
) {
const video = webcamRef.current.video;
const videoWidth = webcamRef.current.video.videoWidth;
const videoHeight = webcamRef.current.video.videoHeight;
webcamRef.current.video.width = videoWidth;
webcamRef.current.video.height = videoHeight;
const hand = await net.estimateHands(video);
if (hand.length > 0) {
const GE = new fp.GestureEstimator([
Rock, PaperGesture, victoryDescription
]);
const gesture = await GE.estimate(hand[0].landmarks, 7.5);
if (gesture.gestures !== undefined && gesture.gestures.length > 0) {
const maxConfidence = gesture.gestures.reduce((maxIndex, currentGesture, index, array) => {
return currentGesture.confidence > array[maxIndex].confidence ? index : maxIndex;
}, 0);
handleUserChoice(gesture.gestures[maxConfidence].name);
}
}
}
};
const handleUserChoice = (choice) => {
const botChoice = choices[Math.floor(Math.random() * choices.length)];
setUserChoice(choice);
setBotChoice(botChoice);
if ((choice === 'rock' && botChoice === 'scissors') ||
(choice === 'scissors' && botChoice === 'paper') ||
(choice === 'paper' && botChoice === 'rock')) {
setUserScore(userScore + 1);
} else if (choice !== botChoice) {
setBotScore(botScore + 1);
}
};
return (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%', maxWidth: '800px' }}>
Score: {userScore} - {botScore}
<button onClick={() => handleUserChoice('rock')}>Rock
<button onClick={() => handleUserChoice('paper')}>Paper
<button onClick={() => handleUserChoice('scissors')}>Scissors
<Webcam ref={webcamRef} style={{ marginTop: '20px', width: 320, height: 240 }} />
<canvas ref={canvasRef} style={{ position: 'absolute', marginLeft: 'auto', marginRight: 'auto', left: 0, right: 0, textAlign: 'center', zindex: 9, width: 320, height: 240 }} />
);
}
export default Singleplayer;
for this code i am getting this error
Cannot read properties of undefined (reading 'matchAgainst')
TypeError: Cannot read properties of undefined (reading 'matchAgainst')
at t.value (http://localhost:3000/static/js/bundle.js:140458:23)
at detect (http://localhost:3000/static/js/bundle.js:664:34)
arising due to this line how to fix plzz help
const gesture = await GE.estimate(hand[0].landmarks, 7.5);
from tfjs.
Are you satisfied with the resolution of your issue?
Yes
No
from tfjs.
Related Issues (20)
- Docs/readme left unfinished for model "face-landmarks-detection" HOT 4
- Error dumping weights duplicate weight name kernel HOT 9
- Loading movenet gives Uncaught (in promise) TypeError: Failed to fetch HOT 15
- Next.js Cannot get final name for export 'transposeImplCPU' error HOT 2
- Tensors are leaked when `model.save()` includes the optimizer HOT 3
- Load and save model issue HOT 5
- [Codelab]: Making Predictions from 2D Data HOT 4
- Duplicate weight problem HOT 7
- The if statement refers to `bias.shape.length`, but the error message refers to `kernel.shape.length` HOT 6
- Question: is the Windows tensorflow binary / dll used in tfjs-node compiled with support for zenDNN optimisations? HOT 2
- Standard layers (like `tf.layers.dense`) fail to report their trainable weights, when used from within a custom layer HOT 2
- Error installing @tensorflow/tfjs-node at WSL Ubuntu HOT 3
- Bug when stacking LSTM HOT 4
- Tensor construction fails for the majority of TypedArray types HOT 1
- Trouble loading a saved model in tfjs-node, "Op type not registered 'DisableCopyOnRead'" HOT 1
- tfjs-node - upgrade tar >=6.2.1 HOT 3
- Undefined variable tensorflow-library-target in binding.gyp HOT 4
- tensorflowjs_converter: NotImplementedError: numpy() is only available when eager execution is enabled HOT 6
- tensorflowjs_converter on .keras file messes up weights HOT 3
- Safari webworker `Error when getting WebGL Context`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tfjs.