[tfjs-react-native] Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'a.substr')
See original GitHub issueSystem information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
Ubuntu 20.04
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
Pixel_3a_API_30_x86.avd
- TensorFlow.js installed from (npm or script link):
- TensorFlow.js version:
npm install @tensorflow/tfjs
, - CUDA/cuDNN version:
Describe the problem
I’m trying to run some sample function found in your documentation https://js.tensorflow.org/api/latest/#tf.LayersModel.fit in a react-native-app.
if i run this example on the web executing npm run web
and check the browser window it loads, it works fine.
If however i run the same example by running npm run web
then scan the QR code using my android phone, or if i hit a
to run a android emulator, in both cases i get the following error. [Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'a.substr')]
What is it about the function do_training_example
that ive introduced that it does not like when running via the QR code on my phone or via the emulator. If i remove this function the error goes.
[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'a.substr')]
at node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:3754:8 in isMobile
at node_modules/@tensorflow/tfjs-backend-webgl/dist/tf-backend-webgl.node.js:1043:17 in <global>
at http://192.168.1.104:19001/index.bundle?platform=android&dev=true&hot=false&minify=false:161631:39 in get
at http://192.168.1.104:19001/index.bundle?platform=android&dev=true&hot=false&minify=false:249141:41 in runWebGLProgram
at node_modules/@tensorflow/tfjs-backend-webgl/dist/tf-backend-webgl.node.js:5217:12 in MathBackendWebGL.prototype.uploadToGPU
at http://192.168.1.104:19001/index.bundle?platform=android&dev=true&hot=false&minify=false:249103:25 in <unknown>
at [native code]:null in map
at node_modules/@tensorflow/tfjs-backend-webgl/dist/tf-backend-webgl.node.js:5016:8 in MathBackendWebGL.prototype.runWebGLProgram
at node_modules/@tensorflow/tfjs-backend-webgl/dist/tf-backend-webgl.node.js:8060:37 in int
at http://192.168.1.104:19001/index.bundle?platform=android&dev=true&hot=false&minify=false:163816:35 in kernelFunc
at node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:3199:17 in scopedRun$argument_2
at node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:3011:12 in Engine.prototype.scopedRun
at node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:3195:12 in Engine.prototype.runKernelFunc
at node_modules/@tensorflow/tfjs/dist/tf.node.js:3548:12 in f2
at node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:24702:13 in tfc.tidy$argument_0
at node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:3001:126 in scopedRun$argument_2
at node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:3011:12 in Engine.prototype.scopedRun
at [native code]:null in map
at node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:3001:126 in scopedRun$argument_2
at node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:3011:12 in Engine.prototype.scopedRun
at node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:24838:87 in tfc.tidy$argument_0
at node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:3001:126 in scopedRun$argument_2
at node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:3011:12 in Engine.prototype.scopedRun
at http://192.168.1.104:19001/index.bundle?platform=android&dev=true&hot=false&minify=false:206783:36 in <unknown>
at http://192.168.1.104:19001/index.bundle?platform=android&dev=true&hot=false&minify=false:199674:24 in step
at node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:16694:22 in step
at node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:16694:22 in step
at node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:16681:40 in fulfilled
at node_modules/react-native/node_modules/promise/setimmediate/core.js:37:13 in tryCallOne
at node_modules/react-native/node_modules/promise/setimmediate/core.js:123:24 in setImmediate$argument_0
at [native code]:null in flushedQueue
at [native code]:null in invokeCallbackAndReturnFlushedQueue
Any other info / logs
You can see ive only added the function do_training_example
and executing that within the componentDidMount
App.tsc
import * as tf from '@tensorflow/tfjs';
import '@tensorflow/tfjs-react-native';
import React, { Component } from 'react';
import { Text, View } from 'react-native';
export default class App extends React.Component {
constructor(props: any) {
super(props);
this.state = {
isTfReady: false,
};
}
async componentDidMount() {
// Wait for tf to be ready.
await tf.ready();
// Signal to the app that tensorflow.js can now be used.
this.setState({
isTfReady: true,
});
await this.do_training_example();
}
do_training_example = async () => {
const model = tf.sequential({
layers: [tf.layers.dense({ units: 1, inputShape: [10] })]
});
model.compile({ optimizer: 'sgd', loss: 'meanSquaredError' });
for (let i = 1; i < 5; ++i) {
const h = await model.fit(tf.ones([8, 10]), tf.ones([8, 1]), {
batchSize: 4,
epochs: 3
});
console.log("Loss after Epoch " + i + " : " + h.history.loss[0]);
}
}
render() {
return (
<View style={{
flex: 1,
justifyContent: "center",
alignItems: "center"
}}>
<Text>Hello, world!</Text>
</View>
);
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (4 by maintainers)
Top GitHub Comments
Choosing a backend with
tf.setBackend('cpu')
solved the problem for me.
Yes true this is bug , Version issue
On Sun, 14 Mar 2021, 20:38 Ralf Gutkowski, @.***> wrote: