This commit is contained in:
Dragon Fire
2024-05-09 15:14:04 -04:00
parent 458f545ff5
commit f2147f3d85
2 changed files with 3 additions and 3 deletions
+3 -3
View File
@@ -74,10 +74,10 @@ module.exports = class Tensorflow {
async stylizeImage(image, styleImg) {
const imageTensor = await tf.node.decodeImage(image, 3);
const [originalHeight, originalWidth] = imageTensor.shape.slice(0, 2);
const desiredWidth = 400;
const desiredHeight = 400;
const aspectRatio = originalWidth / originalHeight;
const newHeight = Math.round(desiredWidth / aspectRatio);
const resizedImage = tf.image.resizeBilinear(imageTensor, [newHeight, desiredWidth]);
const newWidth = Math.round(desiredHeight / aspectRatio);
const resizedImage = tf.image.resizeBilinear(imageTensor, [desiredHeight, newWidth]);
imageTensor.dispose();
const loadedImage = resizedImage.toFloat().div(tf.scalar(255)).expandDims();
resizedImage.dispose();