Tfjs: undefined is not an object (evaluating 'environment_1.env().platform.fetch')

Created on 21 May 2020  路  21Comments  路  Source: tensorflow/tfjs

TensorFlow.js version

"@tensorflow-models/handpose": "0.0.3"
"@tensorflow/tfjs": "^1.7.4"

Browser version

React Native 37.0.1
Expo 37.0.3

Describe the problem or feature request

I tried to use Handpose model on React Native but it gives an error:

undefined is not an object (evaluating 'environment_1.env().platform.fetch')
others

Most helpful comment

@subodha I think this may be related to something in your expo setup (potentially related to typescript support), similarish issues are described here https://forums.expo.io/t/sdk-33-error-unable-to-resolve-module-node-modules-expo-appentry/24470.

I made fresh managed expo app (https://github.com/tafsiri/tfjs-expo-managed-example) and could not reproduce.

All 21 comments

The same issue with the mobilenet as well

"@tensorflow/tfjs": "^1.7.4",
"@tensorflow-models/mobilenet": "^2.0.4",
"expo": "~37.0.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",

what version of tfjs-react-native are you using?

0.2.3

I looked this problem a little bit closer and right now I know that it's not recognizing the app as browser or node. This is why it's not setting any platform. When I modified @tensorflow/tfjs-core/dist/platforms/platform_browser.js to not check if is browser but anyways set the platform as browser, the problem changed a little bit. It's now complaining [Unhandled promise rejection: Error: FileReader.readAsArrayBuffer is not implemented] I found some ways to get past this but I'm not getting them work yet. I believe that there should be a new platform for this purpose but I try to find what kind of stuff it should contain.

I used
"@tensorflow/tfjs-react-native": "^0.2.3",

Actualy I did clone
your code that @tafsiri you did for posenet and it works fine.
Then I rename the app.js and start to use imagenet.

Could it be a modal file type importing issue

What code are you talking about? Can you link it here?

I got mobilenet work with this code https://github.com/RealLankinen/tfjs/commit/24869f0fabea05ebdaaebd4062aea81513d66629 but as I commented there, it's not the final version but just a way around it. I'm not sure if it's even a good way around it. I tried handpose on iphone 6s but it said out of memory.

Really sorry if I confuse you @RealLankinen .
I mean the code from @tafsiri
https://github.com/tensorflow/tfjs/blob/master/tfjs-react-native/integration_rn59/components/webcam/realtime_demo.tsx. I have run locally this code without any issue. but the issue occurs when I tried to use the mobilenet for simple image classifications

What is the value of navigator.product in your app. The platform should be neither browser nor node (there is a specific ReactNative 'platform' defined here). I could relax the test but was able to get stuff working with expo 37 earlier this week, so would be curious to know why this is happening.

Also could you push some sample code that reproduces this in a repo or gist?

@subodha are you getting the same error or something different? undefined is not an object (evaluating 'environment_1.env().platform.fetch') I'm a bit confused from your last message.

import React from 'react'
import { Text, View, Button, TouchableHighlightBase } from 'react-native'
import * as tf from '@tensorflow/tfjs'
import * as mobilenet from '@tensorflow-models/mobilenet';
import * as handtrack from '@tensorflow-models/handpose'

class App extends React.Component {
  state = {
    isTfReady: false,
    model: false,
    prediction: '',
  }

  async componentDidMount() {
    await tf.ready()
    console.log('ready')
    this.setState({ isTfReady: true })

    console.log('load handtrack')
    const model = await handtrack.load();
    console.log('model ready')
  }
  render() {
    if(!this.state.isTfReady) return <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}><Text>Loading TF...</Text></View>
    if(!this.state.model) return <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}><Text>Loading model...</Text></View>
    console.log('this.state.model:',this.state.model)
    return (
      <View style={{flex: 1}}>
      </View>
    )
  }
}

export default App

hi @tafsiri , @RealLankinen , I have uploaded my initial code to
https://github.com/subodha/Tensorflow-RN-Lab/blob/master/App.tsx

And here is the error that I'm getting
image

Thanks @RealLankinen I'll try with your code :)

Any update @subodha or @tafsiri ?

Hi @RealLankinen,
I couldn't check the issue I was stuck with my thesis writing work. But hope to check the issue very soon. Thanks for jumping into this.
Thanks again

@RealLankinen could you tell the value of navigator.product in your app?

@RealLankinen in your code snippet you are not importing tfjs-react-native. Thus the proper platform adapter is not registered. That should fix your problem.

@subodha I think this may be related to something in your expo setup (potentially related to typescript support), similarish issues are described here https://forums.expo.io/t/sdk-33-error-unable-to-resolve-module-node-modules-expo-appentry/24470.

I made fresh managed expo app (https://github.com/tafsiri/tfjs-expo-managed-example) and could not reproduce.

@tafsiri Thanks for the update. Let me check and get back to you. :)

Hi @tafsiri ,
I cloned your repo and it works really well. As you mention it seems an issue with my expo setup.
I really appreciate your help with this.
Now I can continue my research work this.

One small question Do you think that I can get the trained model from https://victordibia.github.io/handtrack.js/#/ and integrate with tfjs-react-native ?

Thanks again.

Sorry for not being available for a week. Thanks @tafsiri and @subodha for solving this!

@subodha I think this may be related to something in your expo setup (potentially related to typescript support), similarish issues are described here https://forums.expo.io/t/sdk-33-error-unable-to-resolve-module-node-modules-expo-appentry/24470.

I made fresh managed expo app (https://github.com/tafsiri/tfjs-expo-managed-example) and could not reproduce.

i cloned your repo and it works as a charm, and i'm going to continue develop this to get face recognition / face match and store the data to database, do you think its possible ?

@subodha I think this may be related to something in your expo setup (potentially related to typescript support), similarish issues are described here https://forums.expo.io/t/sdk-33-error-unable-to-resolve-module-node-modules-expo-appentry/24470.
I made fresh managed expo app (https://github.com/tafsiri/tfjs-expo-managed-example) and could not reproduce.

i cloned your repo and it works as a charm, and i'm going to continue develop this to get face recognition / face match and store the data to database, do you think its possible ?

Yes, it will work! you will have to change some sections. but you can use my code to make the base of your work
Just let me know if you need anything else

@subodha i've done some improvement, but getting confused about what im doing here.

recently im storing the raw data from landmarks, TL, BR to database, with only 1 data,
and when camera detect the face, we need to snap the photo and send the raw data to being checked in database, but its different since the camera landmarks data is changing overtime,

currently im using MySQL, ill update new info if i get some improvement here,

if u get any idea, please let me know thank you..

Was this page helpful?
0 / 5 - 0 ratings