Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Memory Leak #231

Merged
merged 8 commits into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions apps/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ function camicStopDraw(e) {
if (args) {
runPredict(args.status);
}
var memory = tf.memory();
console.log(memory);
$UI.modelPanel.setPosition(box.rect.x,box.rect.y,box.rect.width,box.rect.height);
$UI.modelPanel.open(args);

Expand Down Expand Up @@ -471,10 +473,11 @@ function runPredict(key) {
self.showProgress("Model loaded...");

// Warmup the model before using real data.
tf.tidy(()=>{
const warmupResult = model.predict(tf.zeros([1, image_size, image_size, input_channels]));
warmupResult.dataSync();
Copy link
Contributor

@Insiyaa Insiyaa Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise the line 478 isn't required to get the values, could you remove it?

warmupResult.dispose();
console.log("Model ready");
});

let temp = document.querySelector('#dummy');
temp.height = step;
Expand Down Expand Up @@ -509,7 +512,7 @@ function runPredict(key) {
fullResCvs.getContext('2d').drawImage(l_img, 0, 0);

let imgData = fullResCvs.getContext('2d').getImageData(0,0,fullResCvs.width,fullResCvs.height);

tf.tidy(()=>{
const img = tf.browser.fromPixels(imgData).toFloat();
let img2;
if (input_channels == 1) {
Expand Down Expand Up @@ -544,7 +547,7 @@ function runPredict(key) {
normalized = img2.sub(mean).div(std);
}
let batched = normalized.reshape([1, image_size, image_size, input_channels]);
let values = await model.predict(batched).data();
let values =model.predict(batched).dataSync();

values.forEach((e) => {
csvContent += e.toString() + ",";
Expand All @@ -555,6 +558,7 @@ function runPredict(key) {
// Retrieving the top class

dx += step;
});
}
dy += step;
}
Expand Down
8 changes: 4 additions & 4 deletions dist/packages.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/packages.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.