Tensorflow: Does tf.image.resize still not align corners?What does ** (double star/asterisk) and * (star/asterisk) do for parameters?What does the “yield” keyword do?Does Python have a ternary conditional operator?What does if __name__ == “__main__”: do?Does Django scale?Why does comparing strings using either '==' or 'is' sometimes produce a different result?Does Python have a string 'contains' substring method?Tensorflow: how to save/restore a model?TensorFlow not found using pipInconsistency between image resizing with Keras (PIL) and TensorFlow?

Memory models for assembly libraries for Turbo C

Why should I invest so much in 401(k)?

Is Chika Ofili's method for checking divisibility for 7 a "new discovery" in math?

Why is it ethical for Ambassador Sondland to have been given an ambassadorship for campaign contributions?

Issues with the new Sitecore Support portal

Was Constantine The Great a Nicene Christian?

What is the best way to go about re-learning an instrument?

Is my friend from Egypt with a Schengen visa allowed to visit the UK?

A bob hanging in an accelerating train moves backward. What is the force moving it backward?

How to save custom label as parameter for a custom entity_reference field widget?

Miniseries in post-rapture US with good/evil conflict

How can I obtain a Cauchy distribution from two standard normal distributions?

"выше" - adverb or an adjective?

Someone said to me, "We basically literally did." What were they trying to express to me?

What's a good use case for SELECT * in production code?

Suppose I capture encrypted data that I want to decrypt. Could I use a server farm to decrypt?

Help me pair my socks

What will happen to a ball kept on a frictionless inclined plane?

Contacted by head of school regarding an issue - should I be worried?

Can Teflon thread tape be reused?

Why 401k contribution as % of salary vs. fixed amount per pay check?

Origin of Aliens in 'A Quiet Place'?

Is there a sonic boom when flying nearby?

Big equation writing in LaTeX



Tensorflow: Does tf.image.resize still not align corners?


What does ** (double star/asterisk) and * (star/asterisk) do for parameters?What does the “yield” keyword do?Does Python have a ternary conditional operator?What does if __name__ == “__main__”: do?Does Django scale?Why does comparing strings using either '==' or 'is' sometimes produce a different result?Does Python have a string 'contains' substring method?Tensorflow: how to save/restore a model?TensorFlow not found using pipInconsistency between image resizing with Keras (PIL) and TensorFlow?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0


















I was reading this blog post in Hackernoon about how Tensorflow's tf.image.resize_area() function is not reflection equivariant. So if I was going to resize an image in some data augmentation step, that this might really mess up the model training.



The author goes on to say that users should not use any of the tf.image.resize functions, because of potentially unpredictable behavior. The article is from Jan 2018, so not that long ago. I actually checked the article's comments section, and no one has mentioned that the problems were fixed.



I was just wondering if these problems are still true and what the workaround is? Any changes in subsequent versions of tensorflow. Like can I use tf.keras augmentation functions instead to avoid these problems?










share|improve this question































    0


















    I was reading this blog post in Hackernoon about how Tensorflow's tf.image.resize_area() function is not reflection equivariant. So if I was going to resize an image in some data augmentation step, that this might really mess up the model training.



    The author goes on to say that users should not use any of the tf.image.resize functions, because of potentially unpredictable behavior. The article is from Jan 2018, so not that long ago. I actually checked the article's comments section, and no one has mentioned that the problems were fixed.



    I was just wondering if these problems are still true and what the workaround is? Any changes in subsequent versions of tensorflow. Like can I use tf.keras augmentation functions instead to avoid these problems?










    share|improve this question



























      0













      0









      0








      I was reading this blog post in Hackernoon about how Tensorflow's tf.image.resize_area() function is not reflection equivariant. So if I was going to resize an image in some data augmentation step, that this might really mess up the model training.



      The author goes on to say that users should not use any of the tf.image.resize functions, because of potentially unpredictable behavior. The article is from Jan 2018, so not that long ago. I actually checked the article's comments section, and no one has mentioned that the problems were fixed.



      I was just wondering if these problems are still true and what the workaround is? Any changes in subsequent versions of tensorflow. Like can I use tf.keras augmentation functions instead to avoid these problems?










      share|improve this question














      I was reading this blog post in Hackernoon about how Tensorflow's tf.image.resize_area() function is not reflection equivariant. So if I was going to resize an image in some data augmentation step, that this might really mess up the model training.



      The author goes on to say that users should not use any of the tf.image.resize functions, because of potentially unpredictable behavior. The article is from Jan 2018, so not that long ago. I actually checked the article's comments section, and no one has mentioned that the problems were fixed.



      I was just wondering if these problems are still true and what the workaround is? Any changes in subsequent versions of tensorflow. Like can I use tf.keras augmentation functions instead to avoid these problems?







      python tensorflow






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 22:04









      krishnabkrishnab

      4,4944 gold badges31 silver badges63 bronze badges




      4,4944 gold badges31 silver badges63 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1



















          After I originally read the Hackernoon article that you've referenced, I also came across this article which provides a nice summary of the different implementations of bilinear interpolation across OpenCV, TF 1.X and some other DL frameworks.



          I couldn't find anything on this in the TF 2.0 docs, so I have reproduced the example given in that article to test the bilinear interpolation in 2.0.
          When I run the following code using TensorFlow 2.0, the test passes, so it looks like moving to TF2.0 will provide you with an implementation of bilinear interpolation that matches the OpenCV implementation (and therefore addresses the issues raised in the Hackernoon article):



          def test_tf2_resample_upsample_matches_opencv_methodology():
          """
          According to the article below, the Tensorflow 1.x implementation of bilinear interpolation for resizing images did
          not reproduce the pixel-area-based approach adopted by OpenCV. The `align_corners` option was set to False by
          default due to some questionable legacy reasons but users were advised to set it to True in order to get a
          'reasonable' output: https://jricheimer.github.io/tensorflow/2019/02/11/resize-confusion/
          This appears to have been fixed in TF 2.0 and this test confirms that we get the results one would expect from a
          pixel-area-based technique.

          We start with an input array whose values are equivalent to their column indices:
          input_arr = np.array([
          [[0], [1], [2], [3], [4], [5]],
          [[0], [1], [2], [3], [4], [5]],
          ])

          And then resize this (holding the rows dimension constant in size, but increasing the column dimnesion to 12) to
          reproduce the OpenCV example from the article. We expect this to produce the following output:
          expected_output = np.array([
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          ])

          """
          input_tensor = tf.convert_to_tensor(
          np.array([
          [[0], [1], [2], [3], [4], [5]],
          [[0], [1], [2], [3], [4], [5]],
          ]),
          dtype=tf.float32,
          )
          output_arr = tf.image.resize(
          images=input_tensor,
          size=(2,12),
          method=tf.image.ResizeMethod.BILINEAR).numpy()
          expected_output = np.array([
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          ])
          np.testing.assert_almost_equal(output_arr, expected_output, decimal=2)






          share|improve this answer


























          • Ahh very good that you were able to check this out. Glad that this seems to be fixed in Tensorflow 2.0. I will try out your code to see if it works for me as well.

            – krishnab
            Nov 6 at 19:04












          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',
          autoActivateHeartbeat: false,
          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/4.0/"u003ecc by-sa 4.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%2f55407551%2ftensorflow-does-tf-image-resize-still-not-align-corners%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown


























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1



















          After I originally read the Hackernoon article that you've referenced, I also came across this article which provides a nice summary of the different implementations of bilinear interpolation across OpenCV, TF 1.X and some other DL frameworks.



          I couldn't find anything on this in the TF 2.0 docs, so I have reproduced the example given in that article to test the bilinear interpolation in 2.0.
          When I run the following code using TensorFlow 2.0, the test passes, so it looks like moving to TF2.0 will provide you with an implementation of bilinear interpolation that matches the OpenCV implementation (and therefore addresses the issues raised in the Hackernoon article):



          def test_tf2_resample_upsample_matches_opencv_methodology():
          """
          According to the article below, the Tensorflow 1.x implementation of bilinear interpolation for resizing images did
          not reproduce the pixel-area-based approach adopted by OpenCV. The `align_corners` option was set to False by
          default due to some questionable legacy reasons but users were advised to set it to True in order to get a
          'reasonable' output: https://jricheimer.github.io/tensorflow/2019/02/11/resize-confusion/
          This appears to have been fixed in TF 2.0 and this test confirms that we get the results one would expect from a
          pixel-area-based technique.

          We start with an input array whose values are equivalent to their column indices:
          input_arr = np.array([
          [[0], [1], [2], [3], [4], [5]],
          [[0], [1], [2], [3], [4], [5]],
          ])

          And then resize this (holding the rows dimension constant in size, but increasing the column dimnesion to 12) to
          reproduce the OpenCV example from the article. We expect this to produce the following output:
          expected_output = np.array([
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          ])

          """
          input_tensor = tf.convert_to_tensor(
          np.array([
          [[0], [1], [2], [3], [4], [5]],
          [[0], [1], [2], [3], [4], [5]],
          ]),
          dtype=tf.float32,
          )
          output_arr = tf.image.resize(
          images=input_tensor,
          size=(2,12),
          method=tf.image.ResizeMethod.BILINEAR).numpy()
          expected_output = np.array([
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          ])
          np.testing.assert_almost_equal(output_arr, expected_output, decimal=2)






          share|improve this answer


























          • Ahh very good that you were able to check this out. Glad that this seems to be fixed in Tensorflow 2.0. I will try out your code to see if it works for me as well.

            – krishnab
            Nov 6 at 19:04















          1



















          After I originally read the Hackernoon article that you've referenced, I also came across this article which provides a nice summary of the different implementations of bilinear interpolation across OpenCV, TF 1.X and some other DL frameworks.



          I couldn't find anything on this in the TF 2.0 docs, so I have reproduced the example given in that article to test the bilinear interpolation in 2.0.
          When I run the following code using TensorFlow 2.0, the test passes, so it looks like moving to TF2.0 will provide you with an implementation of bilinear interpolation that matches the OpenCV implementation (and therefore addresses the issues raised in the Hackernoon article):



          def test_tf2_resample_upsample_matches_opencv_methodology():
          """
          According to the article below, the Tensorflow 1.x implementation of bilinear interpolation for resizing images did
          not reproduce the pixel-area-based approach adopted by OpenCV. The `align_corners` option was set to False by
          default due to some questionable legacy reasons but users were advised to set it to True in order to get a
          'reasonable' output: https://jricheimer.github.io/tensorflow/2019/02/11/resize-confusion/
          This appears to have been fixed in TF 2.0 and this test confirms that we get the results one would expect from a
          pixel-area-based technique.

          We start with an input array whose values are equivalent to their column indices:
          input_arr = np.array([
          [[0], [1], [2], [3], [4], [5]],
          [[0], [1], [2], [3], [4], [5]],
          ])

          And then resize this (holding the rows dimension constant in size, but increasing the column dimnesion to 12) to
          reproduce the OpenCV example from the article. We expect this to produce the following output:
          expected_output = np.array([
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          ])

          """
          input_tensor = tf.convert_to_tensor(
          np.array([
          [[0], [1], [2], [3], [4], [5]],
          [[0], [1], [2], [3], [4], [5]],
          ]),
          dtype=tf.float32,
          )
          output_arr = tf.image.resize(
          images=input_tensor,
          size=(2,12),
          method=tf.image.ResizeMethod.BILINEAR).numpy()
          expected_output = np.array([
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          ])
          np.testing.assert_almost_equal(output_arr, expected_output, decimal=2)






          share|improve this answer


























          • Ahh very good that you were able to check this out. Glad that this seems to be fixed in Tensorflow 2.0. I will try out your code to see if it works for me as well.

            – krishnab
            Nov 6 at 19:04













          1















          1











          1









          After I originally read the Hackernoon article that you've referenced, I also came across this article which provides a nice summary of the different implementations of bilinear interpolation across OpenCV, TF 1.X and some other DL frameworks.



          I couldn't find anything on this in the TF 2.0 docs, so I have reproduced the example given in that article to test the bilinear interpolation in 2.0.
          When I run the following code using TensorFlow 2.0, the test passes, so it looks like moving to TF2.0 will provide you with an implementation of bilinear interpolation that matches the OpenCV implementation (and therefore addresses the issues raised in the Hackernoon article):



          def test_tf2_resample_upsample_matches_opencv_methodology():
          """
          According to the article below, the Tensorflow 1.x implementation of bilinear interpolation for resizing images did
          not reproduce the pixel-area-based approach adopted by OpenCV. The `align_corners` option was set to False by
          default due to some questionable legacy reasons but users were advised to set it to True in order to get a
          'reasonable' output: https://jricheimer.github.io/tensorflow/2019/02/11/resize-confusion/
          This appears to have been fixed in TF 2.0 and this test confirms that we get the results one would expect from a
          pixel-area-based technique.

          We start with an input array whose values are equivalent to their column indices:
          input_arr = np.array([
          [[0], [1], [2], [3], [4], [5]],
          [[0], [1], [2], [3], [4], [5]],
          ])

          And then resize this (holding the rows dimension constant in size, but increasing the column dimnesion to 12) to
          reproduce the OpenCV example from the article. We expect this to produce the following output:
          expected_output = np.array([
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          ])

          """
          input_tensor = tf.convert_to_tensor(
          np.array([
          [[0], [1], [2], [3], [4], [5]],
          [[0], [1], [2], [3], [4], [5]],
          ]),
          dtype=tf.float32,
          )
          output_arr = tf.image.resize(
          images=input_tensor,
          size=(2,12),
          method=tf.image.ResizeMethod.BILINEAR).numpy()
          expected_output = np.array([
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          ])
          np.testing.assert_almost_equal(output_arr, expected_output, decimal=2)






          share|improve this answer














          After I originally read the Hackernoon article that you've referenced, I also came across this article which provides a nice summary of the different implementations of bilinear interpolation across OpenCV, TF 1.X and some other DL frameworks.



          I couldn't find anything on this in the TF 2.0 docs, so I have reproduced the example given in that article to test the bilinear interpolation in 2.0.
          When I run the following code using TensorFlow 2.0, the test passes, so it looks like moving to TF2.0 will provide you with an implementation of bilinear interpolation that matches the OpenCV implementation (and therefore addresses the issues raised in the Hackernoon article):



          def test_tf2_resample_upsample_matches_opencv_methodology():
          """
          According to the article below, the Tensorflow 1.x implementation of bilinear interpolation for resizing images did
          not reproduce the pixel-area-based approach adopted by OpenCV. The `align_corners` option was set to False by
          default due to some questionable legacy reasons but users were advised to set it to True in order to get a
          'reasonable' output: https://jricheimer.github.io/tensorflow/2019/02/11/resize-confusion/
          This appears to have been fixed in TF 2.0 and this test confirms that we get the results one would expect from a
          pixel-area-based technique.

          We start with an input array whose values are equivalent to their column indices:
          input_arr = np.array([
          [[0], [1], [2], [3], [4], [5]],
          [[0], [1], [2], [3], [4], [5]],
          ])

          And then resize this (holding the rows dimension constant in size, but increasing the column dimnesion to 12) to
          reproduce the OpenCV example from the article. We expect this to produce the following output:
          expected_output = np.array([
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          ])

          """
          input_tensor = tf.convert_to_tensor(
          np.array([
          [[0], [1], [2], [3], [4], [5]],
          [[0], [1], [2], [3], [4], [5]],
          ]),
          dtype=tf.float32,
          )
          output_arr = tf.image.resize(
          images=input_tensor,
          size=(2,12),
          method=tf.image.ResizeMethod.BILINEAR).numpy()
          expected_output = np.array([
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          [[0], [0.25], [0.75], [1.25], [1.75], [2.25], [2.75], [3.25], [3.75], [4.25], [4.75], [5]],
          ])
          np.testing.assert_almost_equal(output_arr, expected_output, decimal=2)







          share|improve this answer













          share|improve this answer




          share|improve this answer










          answered Nov 6 at 15:45









          UpstatePedroUpstatePedro

          836 bronze badges




          836 bronze badges















          • Ahh very good that you were able to check this out. Glad that this seems to be fixed in Tensorflow 2.0. I will try out your code to see if it works for me as well.

            – krishnab
            Nov 6 at 19:04

















          • Ahh very good that you were able to check this out. Glad that this seems to be fixed in Tensorflow 2.0. I will try out your code to see if it works for me as well.

            – krishnab
            Nov 6 at 19:04
















          Ahh very good that you were able to check this out. Glad that this seems to be fixed in Tensorflow 2.0. I will try out your code to see if it works for me as well.

          – krishnab
          Nov 6 at 19:04





          Ahh very good that you were able to check this out. Glad that this seems to be fixed in Tensorflow 2.0. I will try out your code to see if it works for me as well.

          – krishnab
          Nov 6 at 19:04




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407551%2ftensorflow-does-tf-image-resize-still-not-align-corners%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript