|
|
@@ -1698,80 +1698,16 @@ new_height, new_width"); |
|
|
|
public static Tensor decode_image(Tensor contents, int channels = 0, TF_DataType dtype = TF_DataType.TF_UINT8, |
|
|
|
string name = null, bool expand_animations = true) |
|
|
|
{ |
|
|
|
return tf_with(ops.name_scope(name, "decode_image"), scope => |
|
|
|
{ |
|
|
|
var substr = tf.strings.substr(contents, 0, 3); |
|
|
|
|
|
|
|
Func<ITensorOrOperation> _jpeg = () => |
|
|
|
{ |
|
|
|
int jpeg_channels = channels; |
|
|
|
var good_channels = math_ops.not_equal(jpeg_channels, 4, name: "check_jpeg_channels"); |
|
|
|
string channels_msg = "Channels must be in (None, 0, 1, 3) when decoding JPEG 'images'"; |
|
|
|
var assert_channels = control_flow_ops.Assert(good_channels, new string[] { channels_msg }); |
|
|
|
return tf_with(ops.control_dependencies(new[] { assert_channels }), delegate |
|
|
|
{ |
|
|
|
return convert_image_dtype(gen_image_ops.decode_jpeg(contents, channels), dtype); |
|
|
|
}); |
|
|
|
}; |
|
|
|
var scope = ops.name_scope(name, "decode_image"); |
|
|
|
scope.__enter__(); |
|
|
|
|
|
|
|
/*Func<ITensorOrOperation> _gif = () => |
|
|
|
{ |
|
|
|
int gif_channels = channels; |
|
|
|
var good_channels = math_ops.logical_and( |
|
|
|
math_ops.not_equal(gif_channels, 1, name: "check_gif_channels"), |
|
|
|
math_ops.not_equal(gif_channels, 4, name: "check_gif_channels")); |
|
|
|
|
|
|
|
string channels_msg = "Channels must be in (None, 0, 3) when decoding GIF images"; |
|
|
|
var assert_channels = control_flow_ops.Assert(good_channels, new string[] { channels_msg }); |
|
|
|
return tf_with(ops.control_dependencies(new[] { assert_channels }), delegate |
|
|
|
{ |
|
|
|
var result = convert_image_dtype(gen_image_ops.decode_gif(contents), dtype); |
|
|
|
if (!expand_animations) |
|
|
|
result = array_ops.gather(result, 0); |
|
|
|
return result; |
|
|
|
}); |
|
|
|
}; |
|
|
|
var result = gen_image_ops.decode_image(contents, |
|
|
|
channels: channels, |
|
|
|
dtype: dtype, |
|
|
|
expand_animations: expand_animations); |
|
|
|
|
|
|
|
Func<ITensorOrOperation> _bmp = () => |
|
|
|
{ |
|
|
|
int bmp_channels = channels; |
|
|
|
var signature = tf.strings.substr(contents, 0, 2); |
|
|
|
var is_bmp = math_ops.equal(signature, "BM", name: "is_bmp"); |
|
|
|
string decode_msg = "Unable to decode bytes as JPEG, PNG, GIF, or BMP"; |
|
|
|
var assert_decode = control_flow_ops.Assert(is_bmp, new string[] { decode_msg }); |
|
|
|
var good_channels = math_ops.not_equal(bmp_channels, 1, name: "check_channels"); |
|
|
|
string channels_msg = "Channels must be in (None, 0, 3) when decoding BMP images"; |
|
|
|
var assert_channels = control_flow_ops.Assert(good_channels, new string[] { channels_msg }); |
|
|
|
return tf_with(ops.control_dependencies(new[] { assert_decode, assert_channels }), delegate |
|
|
|
{ |
|
|
|
return convert_image_dtype(gen_image_ops.decode_bmp(contents), dtype); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
Func<ITensorOrOperation> _png = () => |
|
|
|
{ |
|
|
|
return convert_image_dtype(gen_image_ops.decode_png( |
|
|
|
contents, |
|
|
|
channels, |
|
|
|
dtype: dtype), |
|
|
|
dtype); |
|
|
|
}; |
|
|
|
|
|
|
|
Func<ITensorOrOperation> check_gif = () => |
|
|
|
{ |
|
|
|
var gif = tf.constant(new byte[] { 0x47, 0x49, 0x46 }, TF_DataType.TF_STRING); |
|
|
|
var is_gif = math_ops.equal(substr, gif, name: name); |
|
|
|
return control_flow_ops.cond(is_gif, _gif, _bmp, name: "cond_gif"); |
|
|
|
}; |
|
|
|
|
|
|
|
Func<ITensorOrOperation> check_png = () => |
|
|
|
{ |
|
|
|
return control_flow_ops.cond(is_png(contents), _png, check_gif, name: "cond_png"); |
|
|
|
};*/ |
|
|
|
|
|
|
|
// return control_flow_ops.cond(is_jpeg(contents), _jpeg, check_png, name: "cond_jpeg"); |
|
|
|
return _jpeg() as Tensor; |
|
|
|
}); |
|
|
|
scope.__exit__(); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public static Tensor crop_and_resize(Tensor image, Tensor boxes, Tensor box_ind, Tensor crop_size, string method, float extrapolation_value, string name) |
|
|
|