I am trying to experiment tensorflow using javascript. I want to run the posenet model over a folder of images. With some googling I have written the HTML below. When I run the HTML shown below the system is running out of memory soon, indeed there is a memory leak. I don't know where and how the memory leak is happening. Can community please explain how the memory leak is happening and how to get around it
<html>
<head>
<script src="https://unpkg.com/@tensorflow/tfjs"></script>
<script src="https://unpkg.com/@tensorflow-models/posenet"</script>
</head>
<body>
<img id='faceImg' src='1.0.jpg'/>
<script>
var i = 1;
async function makeTensors(){
var psData;
var imageScaleFactor = 0.5;
var outputStride = 16;
var flipHorizontal = false;
var iterator;
var imageElements = document.getElementById('faceImg');
console.log(imageElements);
let result = await posenet.load().then(function(net){
return net.estimateSinglePose(imageElements, imageScaleFactor, flipHorizontal, outputStride)
}).then(function(pose){
console.log(pose);
psData = pose;
})
var im_tensor_pos = []
for (iter = 0; iter < 17; iter++) {
im_tensor_pos.push(psData.keypoints[iter].position.x);
im_tensor_pos.push(psData.keypoints[iter].position.y);
}
for (iter = 0; iter < 17; iter++) {
im_tensor_pos.push(psData.keypoints[iter].score);
}
im_tensor_pos.push(psData.score);
// tensor_vals.push(im_tensor_pos);
psData = null;
delete result;
// console.log(tensor_vals);
}
async function test(){
for (i = 1; i < 270; i++) {
var ImageSrc = 'results/' + i + ".0.jpg";
console.log(ImageSrc)
var imageElements = document.getElementById('faceImg');
imageElements.src = ImageSrc;
result = await makeTensors();
delete result;
}
}
test().then(console.log('done'));
</script>
</body>
</html>
This is my first attempt at js too. Please let me know if your thoughts on code too.
I had the exact same problem, but .dispose didn't work for me.
Don't know if you fixed it already, but for future references this worked:
tf.engine().startScope()
// do the Tensorflow / Posenet stuff
tf.engine().endScope()
This will destroy the tensor once finished
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With