Skip to content

Commit c6601f9

Browse files
hcurOceania2018
authored andcommitted
implement more of tf.image
^
1 parent 32a0f58 commit c6601f9

File tree

6 files changed

+2320
-18
lines changed

6 files changed

+2320
-18
lines changed

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

Lines changed: 157 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*****************************************************************************
1+
/*****************************************************************************
22
Copyright 2018 The TensorFlow.NET Authors. All Rights Reserved.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,6 +25,136 @@ public partial class tensorflow
2525

2626
public class image_internal
2727
{
28+
public Tensor random_flip_up_down(Tensor image, int seed = 0)
29+
=> image_ops_impl.random_flip_up_down(image, seed);
30+
31+
public Tensor random_flip_left_right(Tensor image, int seed = 0)
32+
=> image_ops_impl.random_flip_left_right(image, seed);
33+
34+
public Tensor flip_left_right(Tensor image)
35+
=> image_ops_impl.flip_left_right(image);
36+
37+
public Tensor flip_up_down(Tensor image)
38+
=> image_ops_impl.flip_up_down(image);
39+
40+
public Tensor rot90(Tensor image, int k = 1, string name = null)
41+
=> image_ops_impl.rot90(image, k, name);
42+
43+
public Tensor transpose(Tensor image, string name = null)
44+
=> image_ops_impl.transpose(image, name);
45+
46+
public Tensor central_crop(Tensor image, float central_fraction)
47+
=> image_ops_impl.central_crop(image, central_fraction);
48+
49+
public Tensor pad_to_bounding_box(Tensor image, int offset_height, int offset_width, int target_height, int target_width)
50+
=> image_ops_impl.pad_to_bounding_box(image, offset_height, offset_width, target_height, target_width);
51+
52+
public Tensor crop_to_bounding_box(Tensor image, int offset_height, int offset_width, int target_height, int target_width)
53+
=> image_ops_impl.crop_to_bounding_box(image, offset_height, offset_width, target_height, target_width);
54+
55+
public Tensor resize_image_with_crop_or_pad(Tensor image, object target_height, object target_width)
56+
=> image_ops_impl.resize_image_with_crop_or_pad(image, target_height, target_width);
57+
58+
public Tensor resize_images(Tensor images, Tensor size, string method = ResizeMethod.BILINEAR, bool preserve_aspect_ratio = false, bool antialias = false,
59+
string name = null)
60+
=> image_ops_impl.resize_images(images, size, method, preserve_aspect_ratio, antialias, name);
61+
62+
public Tensor resize_images_with_pad(Tensor image, int target_height, int target_width, string method, bool antialias)
63+
=> image_ops_impl.resize_images_with_pad(image, target_height, target_width, method, antialias);
64+
65+
public Tensor per_image_standardization(Tensor image)
66+
=> image_ops_impl.per_image_standardization(image);
67+
68+
public Tensor random_brightness(Tensor image, float max_delta, int seed = 0)
69+
=> image_ops_impl.random_brightness(image, max_delta, seed);
70+
71+
public Tensor random_contrast(Tensor image, float lower, float upper, int seed = 0)
72+
=> image_ops_impl.random_contrast(image, lower, upper, seed);
73+
74+
public Tensor adjust_brightness(Tensor image, Tensor delta)
75+
=> image_ops_impl.adjust_brightness(image, delta);
76+
77+
public Tensor adjust_contrast(Tensor images, Tensor contrast_factor)
78+
=> image_ops_impl.adjust_contrast(images, contrast_factor);
79+
80+
public Tensor adjust_gamma(Tensor image, int gamma = 1, int gain = 1)
81+
=> image_ops_impl.adjust_gamma(image, gamma, gain);
82+
83+
public Tensor rgb_to_grayscale(Tensor images, string name = null)
84+
=> image_ops_impl.rgb_to_grayscale(images, name);
85+
86+
public Tensor grayscale_to_rgb(Tensor images, string name = null)
87+
=> image_ops_impl.grayscale_to_rgb(images, name);
88+
89+
public Tensor random_hue(Tensor image, float max_delta, int seed = 0)
90+
=> image_ops_impl.random_hue(image, max_delta, seed);
91+
92+
public Tensor adjust_hue(Tensor image, Tensor delta, string name = null)
93+
=> image_ops_impl.adjust_hue(image, delta, name);
94+
95+
public Tensor random_jpeg_quality(Tensor image, float min_jpeg_quality, float max_jpeg_quality, int seed = 0)
96+
=> image_ops_impl.random_jpeg_quality(image, min_jpeg_quality, max_jpeg_quality, seed);
97+
98+
public Tensor adjust_jpeg_quality(Tensor image, Tensor jpeg_quality, string name = null)
99+
=> image_ops_impl.adjust_jpeg_quality(image, jpeg_quality, name);
100+
101+
public Tensor random_saturation(Tensor image, float lower, float upper, int seed = 0)
102+
=> image_ops_impl.random_saturation(image, lower, upper, seed);
103+
104+
public Tensor adjust_saturation(Tensor image, Tensor saturation_factor, string name = null)
105+
=> image_ops_impl.adjust_saturation(image, saturation_factor, name);
106+
107+
public Tensor total_variation(Tensor images, string name = null)
108+
=> image_ops_impl.total_variation(images, name);
109+
110+
public (Tensor, Tensor, Tensor) sample_distorted_bounding_box(Tensor image_size, Tensor bounding_boxes,
111+
int seed = 0,
112+
Tensor min_object_covered = null,
113+
float[] aspect_ratio_range = null,
114+
float[] area_range = null,
115+
int max_attempts = 100,
116+
bool use_image_if_no_bounding_boxes = false,
117+
string name = null)
118+
=> image_ops_impl.sample_distorted_bounding_box_v2(image_size, bounding_boxes, seed, min_object_covered, aspect_ratio_range,
119+
area_range, max_attempts, use_image_if_no_bounding_boxes, name);
120+
121+
public Tensor non_max_suppression(Tensor boxes, Tensor scores, Tensor max_output_size, float iou_threshold = 0.5f,
122+
float score_threshold = -1f / 0f, /*float soft_nms_sigma = 0.0f,*/ string name = null)
123+
=> image_ops_impl.non_max_suppression(boxes, scores, max_output_size, iou_threshold, score_threshold, name);
124+
125+
public Tensor non_max_suppression_with_overlaps(Tensor overlaps, Tensor scores, Tensor max_output_size,
126+
float overlap_threshold = 0.5f, float score_threshold = -1 / 0f, string name = null)
127+
=> image_ops_impl.non_max_suppression_with_overlaps(overlaps, scores, max_output_size, overlap_threshold, score_threshold, name);
128+
129+
public Tensor rgb_to_yiq(Tensor images)
130+
=> image_ops_impl.rgb_to_yiq(images);
131+
132+
public Tensor yiq_to_rgb(Tensor images)
133+
=> image_ops_impl.yiq_to_rgb(images);
134+
135+
public Tensor rgb_to_yuv(Tensor images)
136+
=> image_ops_impl.rgb_to_yuv(images);
137+
138+
public Tensor yuv_to_rgb(Tensor images)
139+
=> image_ops_impl.yuv_to_rgb(images);
140+
141+
public Tensor psnr(Tensor a, Tensor b, Tensor max_val, string name = null)
142+
=> image_ops_impl.psnr(a, b, max_val, name);
143+
144+
public Tensor ssim(Tensor img1, Tensor img2, float max_val = 1f, float filter_size = 11f, float filter_sigma = 1.5f,
145+
float k1 = 0.01f, float k2 = 0.03f)
146+
=> image_ops_impl.ssim(img1, img2, max_val, filter_size, filter_sigma, k1, k2);
147+
148+
public Tensor ssim_multiscale(Tensor img1, Tensor img2, float max_val, float[] power_factors = null, float filter_size = 11f,
149+
float filter_sigma = 1.5f, float k1 = 0.01f, float k2 = 0.03f)
150+
=> image_ops_impl.ssim_multiscale(img1, img2, max_val, power_factors, filter_size, filter_sigma, k1, k2);
151+
152+
public (Tensor, Tensor) image_gradients(Tensor image)
153+
=> image_ops_impl.image_gradients(image);
154+
155+
public Tensor sobel_edges(Tensor image)
156+
=> image_ops_impl.sobel_edges(image);
157+
28158
public Tensor decode_jpeg(Tensor contents,
29159
int channels = 0,
30160
int ratio = 1,
@@ -52,14 +182,34 @@ public Tensor decode_jpeg(Tensor contents,
52182
public Tensor crop_and_resize(Tensor image, Tensor boxes, Tensor box_ind, Tensor crop_size, string method = "bilinear", float extrapolation_value = 0f, string name = null) =>
53183
image_ops_impl.crop_and_resize(image, boxes, box_ind, crop_size, method, extrapolation_value, name);
54184

185+
public Tensor extract_glimpse(Tensor input, Tensor size, Tensor offsets, bool centered = true, bool normalized = true,
186+
bool uniform_noise, string name = null)
187+
=> image_ops_impl.extract_glimpse(input, size, offsets, centered, normalized, uniform_noise, name);
188+
189+
public (Tensor, Tensor, Tensor, Tensor) combined_non_max_suppression(Tensor boxes, Tensor scores, Tensor max_output_size_per_class,
190+
Tensor max_total_size, float iou_threshold = 0.5f, float score_threshold = -1f / 0f, bool pad_per_class = false, bool clip_boxes = true,
191+
string name = null)
192+
=> image_ops_impl.combined_non_max_suppression(boxes, scores, max_output_size_per_class, max_total_size, iou_threshold, score_threshold,
193+
pad_per_class, clip_boxes, name);
194+
195+
public (Tensor, Tensor) non_max_suppression_padded(Tensor boxes, Tensor scores, Tensor max_output_size,
196+
float iou_threshold = 0.5f,
197+
float score_threshold = -1f / 0f,
198+
bool pad_to_max_output_size = false,
199+
string name = null,
200+
bool sorted_input = false,
201+
bool canonicalized_coordinates = false,
202+
int tile_size = 512)
203+
=> image_ops_impl.non_max_suppression_padded(boxes, scores, max_output_size, iou_threshold, score_threshold, pad_to_max_output_size,
204+
name, sorted_input, canonicalized_coordinates, tile_size);
55205

56206
public Tensor resize_bilinear(Tensor images, Tensor size, bool align_corners = false, string name = null)
57207
=> gen_image_ops.resize_bilinear(images, size, align_corners: align_corners, name: name);
58208

59-
public Tensor resize_images(Tensor images, Tensor size, ResizeMethod method = ResizeMethod.BILINEAR,
60-
bool align_corners = false, bool preserve_aspect_ratio = false, string name = null)
209+
public Tensor resize_images(Tensor images, Tensor size, string method = ResizeMethod.BILINEAR,
210+
bool preserve_aspect_ratio = false, string name = null)
61211
=> image_ops_impl.resize_images(images, size, method: method,
62-
align_corners: align_corners, preserve_aspect_ratio: preserve_aspect_ratio, name: name);
212+
preserve_aspect_ratio: preserve_aspect_ratio, name: name);
63213

64214
public Tensor convert_image_dtype(Tensor image, TF_DataType dtype, bool saturate = false, string name = null)
65215
=> gen_image_ops.convert_image_dtype(image, dtype, saturate: saturate, name: name);
@@ -91,6 +241,9 @@ public Tensor resize_nearest_neighbor<Tsize>(Tensor images, Tsize size, bool ali
91241
string name = null, bool half_pixel_centers = false)
92242
=> image_ops_impl.resize_nearest_neighbor(images, size, align_corners: align_corners,
93243
name: name, half_pixel_centers: half_pixel_centers);
244+
245+
public Tensor draw_bounding_boxes(Tensor images, Tensor boxes, Tensor colors = null, string name = null)
246+
=> image_ops_impl.draw_bounding_boxes(images, boxes, colors, name);
94247
}
95248
}
96249
}

src/TensorFlowNET.Core/Operations/array_ops.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,11 @@ private static Tensor size_internal(Tensor input, string name = null, bool optim
534534
return gen_array_ops.size(input, name: name, out_type: out_type);
535535
});
536536
}
537+
538+
public static Tensor tile(Tensor input, Tensor multiples, string name = null)
539+
{
540+
throw new NotImplementedException("tile");
541+
}
537542

538543
public static Tensor zeros_like(Tensor tensor, TF_DataType dtype = TF_DataType.DtInvalid, string name = null, bool optimize = true)
539544
{

src/TensorFlowNET.Core/Operations/gen_math_ops.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,23 @@ public static Tensor _min<Tx, Ty>(Tx input, Ty axis, bool keep_dims = false, str
10831083

10841084
return _op.outputs[0];
10851085
}
1086+
1087+
public static Tensor pow<Tx, Ty>(Tx x, Ty y, string name = null)
1088+
{
1089+
if (tf.context.executing_eagerly())
1090+
{
1091+
var results = tf.Runner.TFE_FastPathExecute(tf.context, tf.context.device_name,
1092+
"Pow", name,
1093+
null,
1094+
x, y);
1095+
1096+
return results[0];
1097+
}
1098+
1099+
var _op = tf._op_def_lib._apply_op_helper("Pow", name, args: new { x, y });
1100+
1101+
return _op.outputs[0];
1102+
}
10861103

10871104
public static Tensor _sum<Tx, Ty>(Tx input, Ty axis = default, bool keep_dims = false, string name = null)
10881105
{

0 commit comments

Comments
 (0)