Khrisna commited on
Commit
284e8b8
·
verified ·
1 Parent(s): 2ab2c8a

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +6 -9
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 image = tfjs.node.decodeImage(images, 3);
498
 
499
- const tensor = await upscaler.upscale(image, {
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 upscaledTensor = await tfjs.node.encodePng(tensor)
508
- //const typedArray = await upscaledTensor.data();
509
- const arrayBuffer = Buffer.from(upscaledTensor);
510
 
511
  // dispose the tensors!
512
- image.dispose();
513
- tensor.dispose();;
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
  }