Reputation: 544
Currently building a ReactNative App to detect Objects using the TensorFlow React Native Library.
Not having any experience with TensorFlow, I followed the examples and Guides, setting up the Expo Camera with the HOC of tfjs-reactnative. (https://js.tensorflow.org/api_react_native/latest/#cameraWithTensors)
<TensorCamera
// Standard Camera props
style={styles.camera}
type={Camera.Constants.Type.back}
// Tensor related props
cameraTextureHeight={textureDims.height}
cameraTextureWidth={textureDims.width}
resizeHeight={200}
resizeWidth={150}
resizeDepth={3}
onReady={handleCameraStream}
autorender={true}
/>
I check if TensorFlow is ready and load my Model from a Webserver
await tf.ready();
const model = await tf.loadGraphModel(
'https://MODEL-DOMAIN.com/model.json'
);
Camera is working and calling the handling function as a callback.
const handleCameraStream = (images, updatePreview, gl) => {
const loop = async () => {
const nextImageTensor = images.next().value;
if (detectionModel) {
try {
console.log(nextImageTensor);
const prediction = await detectionModel.predict(nextImageTensor);
if (prediction) {
console.log(prediction);
}
} catch (e) {
console.log(e);
}
}
requestAnimationFrame(loop);
};
loop();
};
Neither predict(), execute(), executeAsync() function on the model succeed to deliver any Result, instead I get this error
[Error: The shape of dict['ToFloat'] provided in model.execute(dict) must be [-1,-1,-1,3], but was [200,150,3]]
Like I said, I'm not really into TensorFlow but a Shape with negative Vector sizes does not seem quite right.
Would appreciate if someone has informations on whats wrong or missing.
Upvotes: 0
Views: 690
Reputation: 11631
-1
for a dimension indicates that this dimension can vary. In your case ([-1,-1,-1,3]
), the only constraints are the following:
Your input only has 3 dimensions. You need to add a dimension to your input (presumably the batch dimension). You can use the expandDims
function for that.
const prediction = await detectionModel.predict(nextImageTensor.expandDims(0));
Upvotes: 2