From e9feec45a5979819f2c2938ea39c120c829e94ea Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Sat, 31 Aug 2019 12:12:47 -0500 Subject: [PATCH] Resize images to size using nearest neighbor interpolation. --- src/TensorFlowNET.Core/APIs/tf.image.cs | 16 +++++++++++++++- .../Operations/gen_image_ops.py.cs | 14 ++++++++++++++ .../Operations/image_ops_impl.cs | 17 +++++++++++++++++ .../TensorFlowNET.Core.csproj | 2 +- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/TensorFlowNET.Core/APIs/tf.image.cs b/src/TensorFlowNET.Core/APIs/tf.image.cs index e2e3206b..832010e5 100644 --- a/src/TensorFlowNET.Core/APIs/tf.image.cs +++ b/src/TensorFlowNET.Core/APIs/tf.image.cs @@ -54,8 +54,22 @@ namespace Tensorflow /// /// /// - public static Tensor is_jpeg(Tensor contents, string name = null) + public Tensor is_jpeg(Tensor contents, string name = null) => image_ops_impl.is_jpeg(contents, name: name); + + /// + /// Resize `images` to `size` using nearest neighbor interpolation. + /// + /// + /// + /// + /// + /// + /// + public Tensor resize_nearest_neighbor(Tensor images, Tsize size, bool align_corners = false, + string name = null, bool half_pixel_centers = false) + => image_ops_impl.resize_nearest_neighbor(images, size, align_corners: align_corners, + name: name, half_pixel_centers: half_pixel_centers); } } } diff --git a/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs b/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs index 90893815..b052d9d6 100644 --- a/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs +++ b/src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs @@ -169,5 +169,19 @@ namespace Tensorflow return _op.outputs[0]; } } + + public static Tensor resize_nearest_neighbor(Tensor images, Tsize size, bool align_corners = false, + bool half_pixel_centers = false, string name = null) + { + var op = _op_def_lib._apply_op_helper("ResizeNearestNeighbor", name: name, args: new + { + images, + size, + align_corners, + half_pixel_centers + }); + + return op.output; + } } } diff --git a/src/TensorFlowNET.Core/Operations/image_ops_impl.cs b/src/TensorFlowNET.Core/Operations/image_ops_impl.cs index 65ed8eb1..6cf9f77e 100644 --- a/src/TensorFlowNET.Core/Operations/image_ops_impl.cs +++ b/src/TensorFlowNET.Core/Operations/image_ops_impl.cs @@ -128,5 +128,22 @@ namespace Tensorflow throw new NotImplementedException(""); } + + /// + /// Resize `images` to `size` using nearest neighbor interpolation. + /// + /// + /// + /// + /// + /// + /// + public static Tensor resize_nearest_neighbor(Tensor images, Tsize size, bool align_corners = false, + string name = null, bool half_pixel_centers = false) + => gen_image_ops.resize_nearest_neighbor(images: images, + size: size, + align_corners: align_corners, + half_pixel_centers: half_pixel_centers, + name: name); } } diff --git a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj index c3576350..526ccb8d 100644 --- a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj +++ b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj @@ -26,7 +26,7 @@ Docs: https://tensorflownet.readthedocs.io 5. Overload session.run(), make syntax simpler. 6. Add Local Response Normalization. 7. Add tf.image related APIs. -8. Add tf.random_normal, tf.constant, tf.pad, tf.shape. +8. Add tf.random_normal, tf.constant, tf.pad, tf.shape, tf.image.resize_nearest_neighbor. 9. MultiThread is safe. 7.3 0.11.2.0