Skip to content

Commit

Permalink
Turn off page console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinscott committed Mar 4, 2022
1 parent ab094d5 commit 1515f0c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
12 changes: 0 additions & 12 deletions packages/upscalerjs/src/upscale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ export async function* predict<P extends Progress<O, PO>, O extends ResultFormat
modelDefinition,
}: UpscaleInternalArgs
): AsyncGenerator<YieldedIntermediaryValue, tf.Tensor3D> {
// console.log('predict 1', JSON.stringify(tf.memory()));
const scale = modelDefinition.scale;

if (originalPatchSize && padding === undefined) {
Expand All @@ -259,7 +258,6 @@ export async function* predict<P extends Progress<O, PO>, O extends ResultFormat
const [height, width,] = pixels.shape.slice(1);
const { rows, columns, } = getRowsAndColumns(pixels, patchSize);
yield;
// console.log('predict 2', JSON.stringify(tf.memory()));
const { size: originalSize, } = getTensorDimensions({
row: 0,
col: 0,
Expand All @@ -275,7 +273,6 @@ export async function* predict<P extends Progress<O, PO>, O extends ResultFormat
channels,
]);
yield upscaledTensor;
// console.log('predict 3', JSON.stringify(tf.memory()));
const total = rows * columns;
for (let row = 0; row < rows; row++) {
let colTensor: tf.Tensor4D = tf.zeros([
Expand All @@ -285,7 +282,6 @@ export async function* predict<P extends Progress<O, PO>, O extends ResultFormat
channels,
]);
yield [colTensor, upscaledTensor];
console.log(`predict.rows 1 | ${row}`, JSON.stringify(tf.memory()));
for (let col = 0; col < columns; col++) {
const { origin, size, sliceOrigin, sliceSize, } = getTensorDimensions({
row,
Expand All @@ -296,24 +292,20 @@ export async function* predict<P extends Progress<O, PO>, O extends ResultFormat
width,
});
yield [upscaledTensor, colTensor];
// console.log(`predict.cols 1 | ${row} | ${col}`, JSON.stringify(tf.memory()));
const slicedPixels = pixels.slice(
[0, origin[0], origin[1],],
[-1, size[0], size[1],],
);
yield [upscaledTensor, colTensor, slicedPixels];
// console.log(`predict.cols 2 | ${row} | ${col}`, JSON.stringify(tf.memory()));
const prediction = model.predict(slicedPixels) as tf.Tensor4D;
slicedPixels.dispose();
yield [upscaledTensor, colTensor, prediction];
// console.log(`predict.cols 3 | ${row} | ${col}`, JSON.stringify(tf.memory()));
const slicedPrediction = prediction.slice(
[0, sliceOrigin[0] * scale, sliceOrigin[1] * scale,],
[-1, sliceSize[0] * scale, sliceSize[1] * scale,],
);
prediction.dispose();
yield [upscaledTensor, colTensor, slicedPrediction];
// console.log(`predict.cols 4 | ${row} | ${col}`, JSON.stringify(tf.memory()));

if (progress !== undefined && isProgress(progress)) {
const index = row * columns + col + 1;
Expand All @@ -333,20 +325,16 @@ export async function* predict<P extends Progress<O, PO>, O extends ResultFormat
}
}
}
console.log(`predict.cols 4.9 | ${row} | ${col}`, JSON.stringify(tf.memory()));
yield [upscaledTensor, colTensor, slicedPrediction];
console.log(`predict.cols 5 | ${row} | ${col}`, JSON.stringify(tf.memory()));

colTensor = concatTensors<tf.Tensor4D>([colTensor, slicedPrediction,], 2);
slicedPrediction.dispose();
yield [upscaledTensor, colTensor];
// console.log(`predict.cols 6 | ${row} | ${col}`, JSON.stringify(tf.memory()));
}

upscaledTensor = concatTensors<tf.Tensor4D>([upscaledTensor, colTensor,], 1);
colTensor.dispose();
yield [upscaledTensor];
console.log(`predict.rows 2 | ${row}`, JSON.stringify(tf.memory()));
}
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
const squeezedTensor = upscaledTensor.squeeze() as tf.Tensor3D;
Expand Down
9 changes: 3 additions & 6 deletions test/misc/memory/test.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,9 @@ describe('Memory Leaks', () => {
beforeEach(async () => {
context = await browser.createIncognitoBrowserContext();
page = await context.newPage();
page.on('console', message => {
// const type = message.type();
console.log('[PAGE]', message.text());
// console.log('type', type);
// console.log(`${type.substr(0, 3).toUpperCase()} ${message.text()}`);
});
// page.on('console', message => {
// console.log('[PAGE]', message.text());
// });
await page.goto(`http://localhost:${PORT}`)
})

Expand Down

0 comments on commit 1515f0c

Please sign in to comment.