'TensorFlow.js TensorCamera Error: Argument 'x' passed to 'cast' must be a Tensor or TensorLike, but got 'Tensor'
I'm following the cameraWithTensors example code with React Native but getting a weird error that the camera tensors are 'Tensor' not Tensor or TensoreLike
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']
//requestAnimation(loop);
}
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>
Not sure what this error means. I tried printing out a basic tensor and the camera tensor, they both look similar
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]}
Does anyone know what's going on here?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
