Update index.js
Browse files
index.js
CHANGED
@@ -494,9 +494,9 @@ async function upscaleImage(images) {
|
|
494 |
return new Promise(async (resolve, reject) => {
|
495 |
try {
|
496 |
const upscaler = new Upscaler();
|
497 |
-
const
|
498 |
|
499 |
-
const
|
500 |
scale: 4, // upscale by a factor of 4
|
501 |
sharpen: true, // apply sharpening
|
502 |
denoise: true, // apply denoising
|
@@ -504,15 +504,12 @@ async function upscaleImage(images) {
|
|
504 |
colorEnhance: true, // enhance colors
|
505 |
});
|
506 |
|
507 |
-
const
|
508 |
-
//const typedArray = await upscaledTensor.data();
|
509 |
-
const arrayBuffer = Buffer.from(upscaledTensor);
|
510 |
|
511 |
// dispose the tensors!
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
resolve(arrayBuffer);
|
516 |
} catch (error) {
|
517 |
reject(error);
|
518 |
}
|
|
|
494 |
return new Promise(async (resolve, reject) => {
|
495 |
try {
|
496 |
const upscaler = new Upscaler();
|
497 |
+
const imageTensor = tf.tensor3d(imageBuffer, [imageBuffer.height, imageBuffer.width, 3]);
|
498 |
|
499 |
+
const upscaledTensor = await upscaler.upscale(imageTensor, {
|
500 |
scale: 4, // upscale by a factor of 4
|
501 |
sharpen: true, // apply sharpening
|
502 |
denoise: true, // apply denoising
|
|
|
504 |
colorEnhance: true, // enhance colors
|
505 |
});
|
506 |
|
507 |
+
const upscaledImageBuffer = await tf.tensor3dToBuffer(upscaledTensor);
|
|
|
|
|
508 |
|
509 |
// dispose the tensors!
|
510 |
+
imageTensor.dispose();
|
511 |
+
upscaledTensor.dispose();
|
512 |
+
resolve(upscaledImageBuffer);
|
|
|
513 |
} catch (error) {
|
514 |
reject(error);
|
515 |
}
|