mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 02:15:10 +02:00
Fix
This commit is contained in:
@@ -73,8 +73,14 @@ module.exports = class Tensorflow {
|
|||||||
|
|
||||||
async stylizeImage(image, styleImg) {
|
async stylizeImage(image, styleImg) {
|
||||||
const imageTensor = await tf.node.decodeImage(image, 3);
|
const imageTensor = await tf.node.decodeImage(image, 3);
|
||||||
const loadedImage = imageTensor.toFloat().div(tf.scalar(255)).expandDims();
|
const [originalHeight, originalWidth] = imageTensor.shape.slice(0, 2);
|
||||||
|
const desiredWidth = 400;
|
||||||
|
const aspectRatio = originalWidth / originalHeight;
|
||||||
|
const newHeight = Math.round(desiredWidth / aspectRatio);
|
||||||
|
const resizedImage = tf.image.resizeBilinear(imageTensor, [newHeight, desiredWidth]);
|
||||||
imageTensor.dispose();
|
imageTensor.dispose();
|
||||||
|
const loadedImage = resizedImage.toFloat().div(tf.scalar(255)).expandDims();
|
||||||
|
resizedImage.dispose();
|
||||||
const styleTensor = tf.node.decodeImage(styleImg, 3);
|
const styleTensor = tf.node.decodeImage(styleImg, 3);
|
||||||
const loadedStyle = styleTensor.toFloat().div(tf.scalar(255)).expandDims();
|
const loadedStyle = styleTensor.toFloat().div(tf.scalar(255)).expandDims();
|
||||||
styleTensor.dispose();
|
styleTensor.dispose();
|
||||||
|
|||||||
Reference in New Issue
Block a user