cameraWithTensors Error: Argument 'x' passed to 'cast' must be a Tensor or TensorLike, but got 'Tensor'
See original GitHub issueI’m trying to run TensorCamera with React Native. Follwing the example code but I get an error that says the ImageTensors are ‘Tensor’ not Tensor or TensorLike
import React from 'react'
import { Camera } from 'expo-camera'
import { cameraWithTensors } from '@tensorflow/tfjs-react-native'
import * as tf from '@tensorflow/tfjs'
import '@tensorflow/tfjs-react-native'
const TensorCamera = cameraWithTensors(Camera)
function CameraView() {
handleCameraStream(images, updatePreview, gl) {
const loop = async () => {
const nextImageTensor = images.next().value;
nextImageTensor.toFloat();
// throws [Error: Argument 'x' passed to 'cast' must be a Tensor or TensorLike, but got 'Tensor']
nextImageTensor.expandDims(0);
// throws [Error: Argument 'x' passed to 'expandDims' must be a Tensor or TensorLike, but got 'Tensor']
// Solved both of it using tf.func but my model is giving a similar error now
model.predict( tf.expandDims( tf.cast(nextImageTensor, 'float32'), 0) );
// throws [Error: Argument 'x' passed to 'stridedSlice' must be a Tensor or TensorLike, but got 'Tensor']
}
loop();
}
return (
<View>
<TensorCamera
// Standard Camera props
style={styles.camera}
type={Camera.Constants.Type.back}
// Tensor related props
cameraTextureHeight={textureDims.height}
cameraTextureWidth={textureDims.width}
resizeHeight={640}
resizeWidth={640}
resizeDepth={3}
onReady={handleCameraStream}
autorender={true}
/>
</View>
)
}
I’m tried front & back camera, same issue with both. Tried printing out the image tensor and it looks alright
console.log(tf.tensor4d([[
[[1, 3], [2, 8]],
[[3, 9], [4, 2]]
]]))
// {"dataId": {"id": 247}, "dtype": "float32", "id": 253, "isDisposedInternal": false, "kept": false, "rankType": "4", "shape": [1, 2, 2, 2], "size": 8, "strides": [8, 4, 2]}
console.log( tf.expandDims( tf.cast(nextImageTensor, 'float32'), 0))
// {"dataId": {"id": 246}, "dtype": "float32", "id": 255, "isDisposedInternal": false, "kept": false, "rankType": "4", "scopeId": 14, "shape": [1, 640, 640, 3], "size": 1228800, "strides": [1228800, 1920, 3]}
Am I missing something? Seems like a simple usecase for cameraWithTensors. Please help
Issue Analytics
- State:
- Created 2 years ago
- Comments:26
Top Results From Across the Web
Argument 'x' passed to 'cast' must be a Tensor or TensorLike ...
I wonder if tensorflow/qna is suitable for mobile applications? Error screen. Error: Argument 'x' passed to 'cast' must be a Tensor or ...
Read more >Error: Argument "x" passed to 'conv2d' must be a Tensor or ...
Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): no; OS Platform for development: Windows 10,...
Read more >Argument 'x' passed to 'slice' must be a Tensor, but got object.
Error : Argument 'x' passed to 'slice' must be a Tensor, but got object. ... While I if I use tf = require('@tensorflow/tfjs-node');...
Read more >Creates a tf.Tensor with the provided values, shape and dtype.
Pass an array of values to create a vector. tf.tensor([1, 2, 3, 4]).print(); ... The input tensors real and imag must have the...
Read more >50 TensorFlow.js API Explained in 5 Minutes
I know this article should be 5 minutes long but don't worry it ... Tensor [1, 2, 3, 4]// Pass a flat array...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the update @sarons. Sorry for this tedious process… Hope you find the root cause soon.
I found this working example for mobile. I’ll try to downgrade all the packages to what this example uses, maybe that will work 🤞