@@ -102,7 +102,10 @@ internal static Operation[] _CheckAtLeast3DImage(Tensor image, bool require_stat
102
102
{
103
103
throw new ValueError ( "\' image\' must be fully defined." ) ;
104
104
}
105
- var dims = image_shape [ "-3:" ] ;
105
+ var dims = new Shape ( new [ ] {
106
+ image_shape . dims [ image_shape . dims . Length - 3 ] ,
107
+ image_shape . dims [ image_shape . dims . Length - 2 ] ,
108
+ image_shape . dims [ image_shape . dims . Length - 1 ] } ) ;
106
109
foreach ( var dim in dims . dims )
107
110
{
108
111
if ( dim == 0 )
@@ -112,16 +115,18 @@ internal static Operation[] _CheckAtLeast3DImage(Tensor image, bool require_stat
112
115
}
113
116
114
117
var image_shape_last_three_elements = new Shape ( new [ ] {
115
- image_shape . dims [ image_shape . dims . Length - 1 ] ,
118
+ image_shape . dims [ image_shape . dims . Length - 3 ] ,
116
119
image_shape . dims [ image_shape . dims . Length - 2 ] ,
117
- image_shape . dims [ image_shape . dims . Length - 3 ] } ) ;
120
+ image_shape . dims [ image_shape . dims . Length - 1 ] } ) ;
118
121
if ( ! image_shape_last_three_elements . IsFullyDefined )
119
122
{
120
123
Tensor image_shape_ = array_ops . shape ( image ) ;
121
- var image_shape_return = tf . constant ( new [ ] {
122
- image_shape_ . dims [ image_shape . dims . Length - 1 ] ,
123
- image_shape_ . dims [ image_shape . dims . Length - 2 ] ,
124
- image_shape_ . dims [ image_shape . dims . Length - 3 ] } ) ;
124
+ var image_shape_return = tf . slice ( image_shape_ , new [ ] { Math . Max ( image_shape . dims . Length - 3 , 0 ) } , new [ ] { 3 } ) ;
125
+
126
+ //var image_shape_return = tf.constant(new[] {
127
+ // image_shape_.dims[image_shape_.dims.Length - 3],
128
+ // image_shape_.dims[image_shape_.dims.Length - 2],
129
+ // image_shape_.dims[image_shape_.dims.Length - 1]});
125
130
126
131
return new Operation [ ] {
127
132
check_ops . assert_positive (
@@ -209,10 +214,10 @@ internal static Tensor _random_flip(Tensor image, int flip_index, int seed, stri
209
214
}
210
215
211
216
public static Tensor flip_left_right ( Tensor image )
212
- => _flip ( image , 0 , "flip_left_right" ) ;
217
+ => _flip ( image , 1 , "flip_left_right" ) ;
213
218
214
219
public static Tensor flip_up_down ( Tensor image )
215
- => _flip ( image , 1 , "flip_up_down" ) ;
220
+ => _flip ( image , 0 , "flip_up_down" ) ;
216
221
217
222
internal static Tensor _flip ( Tensor image , int flip_index , string scope_name )
218
223
{
@@ -223,11 +228,11 @@ internal static Tensor _flip(Tensor image, int flip_index, string scope_name)
223
228
Shape shape = image . shape ;
224
229
if ( shape . ndim == 3 || shape . ndim == Unknown )
225
230
{
226
- return fix_image_flip_shape ( image , gen_array_ops . reverse ( image , ops . convert_to_tensor ( new int [ ] { flip_index } ) ) ) ;
231
+ return fix_image_flip_shape ( image , gen_array_ops . reverse_v2 ( image , ops . convert_to_tensor ( new int [ ] { flip_index } ) ) ) ;
227
232
}
228
233
else if ( shape . ndim == 4 )
229
234
{
230
- return gen_array_ops . reverse_v2 ( image , ops . convert_to_tensor ( new [ ] { ( flip_index + 1 ) % 2 } ) ) ;
235
+ return gen_array_ops . reverse_v2 ( image , ops . convert_to_tensor ( new [ ] { flip_index + 1 } ) ) ;
231
236
}
232
237
else
233
238
{
@@ -2047,6 +2052,22 @@ internal static (Tensor, Tensor) non_max_suppression_padded_v1(Tensor boxes, Ten
2047
2052
} ) ;
2048
2053
}
2049
2054
2055
+ public static Tensor encode_jpeg ( Tensor contents , string name = null )
2056
+ {
2057
+ return tf_with ( ops . name_scope ( name , "encode_jpeg" ) , scope =>
2058
+ {
2059
+ return gen_ops . encode_jpeg ( contents , name : name ) ;
2060
+ } ) ;
2061
+ }
2062
+
2063
+ public static Tensor encode_png ( Tensor contents , string name = null )
2064
+ {
2065
+ return tf_with ( ops . name_scope ( name , "encode_png" ) , scope =>
2066
+ {
2067
+ return gen_ops . encode_png ( contents , name : name ) ;
2068
+ } ) ;
2069
+ }
2070
+
2050
2071
public static Tensor is_jpeg ( Tensor contents , string name = null )
2051
2072
{
2052
2073
return tf_with ( ops . name_scope ( name , "is_jpeg" ) , scope =>
0 commit comments