ml5.js styleTransfer only works with 1:1 aspect ratio?









up vote
0
down vote

favorite












I'm experimenting with the styleTransfer method in ml5.js. It works well, but I've run into a problem where it only seems to work with square images as the input source — any other aspect ratio results in garbled output where the x/y coordinates appear interpolated.



This seems like a bug, but I'm wondering if I'm doing something wrong?



I'm using the starter code found in the ml5-examples repository, specifically here:
https://github.com/ml5js/ml5-examples



You can see a functional demonstration of that code here:
https://ml5js.org/docs/style-transfer-image-example



The only thing I've changed from the original source code is that my input image is a non-square aspect ratio. This is the image I'm using, though I've scaled it down to about 300x225 pixels.



To recreate the problem I'm trying to describe:



  • Go to the demo page. Click the "Transfer" button once to see how it's intended to work.

  • Use the browser inspector (I'm using Chrome) and make the height and width of the input image (#inputImg) something like 300 by 200 pixels.

  • Click "Transfer" and notice the clearly garbled result.

In contrast, an almost identical demo is setup for Deeplearn.js:



https://reiinakano.github.io/fast-style-transfer-deeplearnjs/assets/scripts/example-style-transfer-image.js



If you take similar steps and skew the aspect ratio of the input image to something other than a square the results work as expected — the output image is a style-transferred version of the input image with the same aspect ratio as the input.



DeepLearn.js is deprecated now but actually served as the base code for ml5.js as I understand it, so it' curious to me this bug doesn't exist in the original implementation.



Is there something I'm overlooking? Or is this a bug with ml5.js?



Apologies for not linking to a CodePen demo or something — it's a little tricky with the need to load models. I can try to host my code somewhere for all to see if it helps clarify the problem.










share|improve this question





















  • Deeplearning.js is no longer supported. tensorflow.js can be used instead
    – edkeveked
    Nov 12 at 19:22










  • @edkeveked Thanks. I know DeepLearn.js is deprecated — I'm linking to it because the DeepLearn example works "correctly" whereas the ml5.js one does not. I double-checked and my understanding is ml5.js is built on top of tensorflow.js, for what it's worth. I'm not sure how any of this addresses my question about the image aspect ratio issue though.
    – George Mandis
    Nov 12 at 20:04














up vote
0
down vote

favorite












I'm experimenting with the styleTransfer method in ml5.js. It works well, but I've run into a problem where it only seems to work with square images as the input source — any other aspect ratio results in garbled output where the x/y coordinates appear interpolated.



This seems like a bug, but I'm wondering if I'm doing something wrong?



I'm using the starter code found in the ml5-examples repository, specifically here:
https://github.com/ml5js/ml5-examples



You can see a functional demonstration of that code here:
https://ml5js.org/docs/style-transfer-image-example



The only thing I've changed from the original source code is that my input image is a non-square aspect ratio. This is the image I'm using, though I've scaled it down to about 300x225 pixels.



To recreate the problem I'm trying to describe:



  • Go to the demo page. Click the "Transfer" button once to see how it's intended to work.

  • Use the browser inspector (I'm using Chrome) and make the height and width of the input image (#inputImg) something like 300 by 200 pixels.

  • Click "Transfer" and notice the clearly garbled result.

In contrast, an almost identical demo is setup for Deeplearn.js:



https://reiinakano.github.io/fast-style-transfer-deeplearnjs/assets/scripts/example-style-transfer-image.js



If you take similar steps and skew the aspect ratio of the input image to something other than a square the results work as expected — the output image is a style-transferred version of the input image with the same aspect ratio as the input.



DeepLearn.js is deprecated now but actually served as the base code for ml5.js as I understand it, so it' curious to me this bug doesn't exist in the original implementation.



Is there something I'm overlooking? Or is this a bug with ml5.js?



Apologies for not linking to a CodePen demo or something — it's a little tricky with the need to load models. I can try to host my code somewhere for all to see if it helps clarify the problem.










share|improve this question





















  • Deeplearning.js is no longer supported. tensorflow.js can be used instead
    – edkeveked
    Nov 12 at 19:22










  • @edkeveked Thanks. I know DeepLearn.js is deprecated — I'm linking to it because the DeepLearn example works "correctly" whereas the ml5.js one does not. I double-checked and my understanding is ml5.js is built on top of tensorflow.js, for what it's worth. I'm not sure how any of this addresses my question about the image aspect ratio issue though.
    – George Mandis
    Nov 12 at 20:04












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm experimenting with the styleTransfer method in ml5.js. It works well, but I've run into a problem where it only seems to work with square images as the input source — any other aspect ratio results in garbled output where the x/y coordinates appear interpolated.



This seems like a bug, but I'm wondering if I'm doing something wrong?



I'm using the starter code found in the ml5-examples repository, specifically here:
https://github.com/ml5js/ml5-examples



You can see a functional demonstration of that code here:
https://ml5js.org/docs/style-transfer-image-example



The only thing I've changed from the original source code is that my input image is a non-square aspect ratio. This is the image I'm using, though I've scaled it down to about 300x225 pixels.



To recreate the problem I'm trying to describe:



  • Go to the demo page. Click the "Transfer" button once to see how it's intended to work.

  • Use the browser inspector (I'm using Chrome) and make the height and width of the input image (#inputImg) something like 300 by 200 pixels.

  • Click "Transfer" and notice the clearly garbled result.

In contrast, an almost identical demo is setup for Deeplearn.js:



https://reiinakano.github.io/fast-style-transfer-deeplearnjs/assets/scripts/example-style-transfer-image.js



If you take similar steps and skew the aspect ratio of the input image to something other than a square the results work as expected — the output image is a style-transferred version of the input image with the same aspect ratio as the input.



DeepLearn.js is deprecated now but actually served as the base code for ml5.js as I understand it, so it' curious to me this bug doesn't exist in the original implementation.



Is there something I'm overlooking? Or is this a bug with ml5.js?



Apologies for not linking to a CodePen demo or something — it's a little tricky with the need to load models. I can try to host my code somewhere for all to see if it helps clarify the problem.










share|improve this question













I'm experimenting with the styleTransfer method in ml5.js. It works well, but I've run into a problem where it only seems to work with square images as the input source — any other aspect ratio results in garbled output where the x/y coordinates appear interpolated.



This seems like a bug, but I'm wondering if I'm doing something wrong?



I'm using the starter code found in the ml5-examples repository, specifically here:
https://github.com/ml5js/ml5-examples



You can see a functional demonstration of that code here:
https://ml5js.org/docs/style-transfer-image-example



The only thing I've changed from the original source code is that my input image is a non-square aspect ratio. This is the image I'm using, though I've scaled it down to about 300x225 pixels.



To recreate the problem I'm trying to describe:



  • Go to the demo page. Click the "Transfer" button once to see how it's intended to work.

  • Use the browser inspector (I'm using Chrome) and make the height and width of the input image (#inputImg) something like 300 by 200 pixels.

  • Click "Transfer" and notice the clearly garbled result.

In contrast, an almost identical demo is setup for Deeplearn.js:



https://reiinakano.github.io/fast-style-transfer-deeplearnjs/assets/scripts/example-style-transfer-image.js



If you take similar steps and skew the aspect ratio of the input image to something other than a square the results work as expected — the output image is a style-transferred version of the input image with the same aspect ratio as the input.



DeepLearn.js is deprecated now but actually served as the base code for ml5.js as I understand it, so it' curious to me this bug doesn't exist in the original implementation.



Is there something I'm overlooking? Or is this a bug with ml5.js?



Apologies for not linking to a CodePen demo or something — it's a little tricky with the need to load models. I can try to host my code somewhere for all to see if it helps clarify the problem.







javascript tensorflow.js style-transfer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 20:24









George Mandis

681418




681418











  • Deeplearning.js is no longer supported. tensorflow.js can be used instead
    – edkeveked
    Nov 12 at 19:22










  • @edkeveked Thanks. I know DeepLearn.js is deprecated — I'm linking to it because the DeepLearn example works "correctly" whereas the ml5.js one does not. I double-checked and my understanding is ml5.js is built on top of tensorflow.js, for what it's worth. I'm not sure how any of this addresses my question about the image aspect ratio issue though.
    – George Mandis
    Nov 12 at 20:04
















  • Deeplearning.js is no longer supported. tensorflow.js can be used instead
    – edkeveked
    Nov 12 at 19:22










  • @edkeveked Thanks. I know DeepLearn.js is deprecated — I'm linking to it because the DeepLearn example works "correctly" whereas the ml5.js one does not. I double-checked and my understanding is ml5.js is built on top of tensorflow.js, for what it's worth. I'm not sure how any of this addresses my question about the image aspect ratio issue though.
    – George Mandis
    Nov 12 at 20:04















Deeplearning.js is no longer supported. tensorflow.js can be used instead
– edkeveked
Nov 12 at 19:22




Deeplearning.js is no longer supported. tensorflow.js can be used instead
– edkeveked
Nov 12 at 19:22












@edkeveked Thanks. I know DeepLearn.js is deprecated — I'm linking to it because the DeepLearn example works "correctly" whereas the ml5.js one does not. I double-checked and my understanding is ml5.js is built on top of tensorflow.js, for what it's worth. I'm not sure how any of this addresses my question about the image aspect ratio issue though.
– George Mandis
Nov 12 at 20:04




@edkeveked Thanks. I know DeepLearn.js is deprecated — I'm linking to it because the DeepLearn example works "correctly" whereas the ml5.js one does not. I double-checked and my understanding is ml5.js is built on top of tensorflow.js, for what it's worth. I'm not sure how any of this addresses my question about the image aspect ratio issue though.
– George Mandis
Nov 12 at 20:04

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232822%2fml5-js-styletransfer-only-works-with-11-aspect-ratio%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232822%2fml5-js-styletransfer-only-works-with-11-aspect-ratio%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kleinkühnau

Makov (Slowakei)

Deutsches Schauspielhaus