Reputation: 6809
I am trying to crop the faces from BlazeFaceModel based on the bounding boxes but I am getting the following error. It throws a huge error in my console with a lot of what looks like C++ code. I have not seen this before and am not sure what to do to fix it.
const tensorDims = { height: 224, width: 224, depth: 3 };
const returnTensors = true;
const faces = await bfModel
.estimateFaces(tensor, returnTensors)
.catch(e => console.log(e));
const tensorReshaped = tensor.reshape([1, 224, 224, 3]);
const scale = {
height: styles.camera.height / tensorDims.height,
width: styles.camera.width / tensorDims.width
};
// Faces is an array of objects
if (!isEmpty(faces)) {
setModelFaces({ faces });
faces.map((face, i) => {
const { topLeft, bottomRight } = face;
const boxes = tf.concat([topLeft, bottomRight]).reshape([-1, 4]);
const width =
(bottomRight.dataSync()[0] - topLeft.dataSync()[0]) * scale.width;
const height =
(bottomRight.dataSync()[1] - topLeft.dataSync()[1]) * scale.height;
const crop = tf.image.cropAndResize(
tensorReshaped,
boxes,
[0],
[height, width]
);
console.log(crop);
});
}
Boxes
Tensor {
"dataId": Object {},
"dtype": "float32",
"id": 63582,
"isDisposedInternal": false,
"kept": false,
"rankType": "2",
"scopeId": 119566,
"shape": Array [
1,
4,
],
"size": 4,
"strides": Array [
4,
],
}
Upvotes: 2
Views: 525
Reputation: 18381
The issue is coming from width and height that are scaled leading to float values. width and height are used for the shape of the crop tensor and should therefore be integers. You can either use Math.Round
or Math.floor
to get an integer value
Upvotes: 2