Skip to content

Commit e9feec4

Browse files
committed
Resize images to size using nearest neighbor interpolation.
1 parent ca3a775 commit e9feec4

4 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎src/TensorFlowNET.Core/APIs/tf.image.cs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,22 @@ public Tensor decode_image(Tensor contents, int channels = 0, TF_DataType dtype
5454
/// <param name="contents"></param>
5555
/// <param name="name"></param>
5656
/// <returns></returns>
57-
public static Tensor is_jpeg(Tensor contents, string name = null)
57+
public Tensor is_jpeg(Tensor contents, string name = null)
5858
=> image_ops_impl.is_jpeg(contents, name: name);
59+
60+
/// <summary>
61+
/// Resize `images` to `size` using nearest neighbor interpolation.
62+
/// </summary>
63+
/// <param name="images"></param>
64+
/// <param name="size"></param>
65+
/// <param name="align_corners"></param>
66+
/// <param name="name"></param>
67+
/// <param name="half_pixel_centers"></param>
68+
/// <returns></returns>
69+
public Tensor resize_nearest_neighbor<Tsize>(Tensor images, Tsize size, bool align_corners = false,
70+
string name = null, bool half_pixel_centers = false)
71+
=> image_ops_impl.resize_nearest_neighbor(images, size, align_corners: align_corners,
72+
name: name, half_pixel_centers: half_pixel_centers);
5973
}
6074
}
6175
}

‎src/TensorFlowNET.Core/Operations/gen_image_ops.py.cs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,19 @@ public static Tensor resize_bilinear(Tensor images, Tensor size, bool align_corn
169169
return _op.outputs[0];
170170
}
171171
}
172+
173+
public static Tensor resize_nearest_neighbor<Tsize>(Tensor images, Tsize size, bool align_corners = false,
174+
bool half_pixel_centers = false, string name = null)
175+
{
176+
var op = _op_def_lib._apply_op_helper("ResizeNearestNeighbor", name: name, args: new
177+
{
178+
images,
179+
size,
180+
align_corners,
181+
half_pixel_centers
182+
});
183+
184+
return op.output;
185+
}
172186
}
173187
}

‎src/TensorFlowNET.Core/Operations/image_ops_impl.cs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,22 @@ public static Tensor convert_image_dtype(Tensor image, TF_DataType dtype, bool s
128128

129129
throw new NotImplementedException("");
130130
}
131+
132+
/// <summary>
133+
/// Resize `images` to `size` using nearest neighbor interpolation.
134+
/// </summary>
135+
/// <param name="images"></param>
136+
/// <param name="size"></param>
137+
/// <param name="align_corners"></param>
138+
/// <param name="name"></param>
139+
/// <param name="half_pixel_centers"></param>
140+
/// <returns></returns>
141+
public static Tensor resize_nearest_neighbor<Tsize>(Tensor images, Tsize size, bool align_corners = false,
142+
string name = null, bool half_pixel_centers = false)
143+
=> gen_image_ops.resize_nearest_neighbor(images: images,
144+
size: size,
145+
align_corners: align_corners,
146+
half_pixel_centers: half_pixel_centers,
147+
name: name);
131148
}
132149
}

‎src/TensorFlowNET.Core/TensorFlowNET.Core.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Docs: https://tensorflownet.readthedocs.io</Description>
2626
5. Overload session.run(), make syntax simpler.
2727
6. Add Local Response Normalization.
2828
7. Add tf.image related APIs.
29-
8. Add tf.random_normal, tf.constant, tf.pad, tf.shape.
29+
8. Add tf.random_normal, tf.constant, tf.pad, tf.shape, tf.image.resize_nearest_neighbor.
3030
9. MultiThread is safe.</PackageReleaseNotes>
3131
<LangVersion>7.3</LangVersion>
3232
<FileVersion>0.11.2.0</FileVersion>

0 commit comments

Comments
 (0)