@@ -1698,80 +1698,16 @@ public static Tensor sobel_edges(Tensor image)
1698
1698
public static Tensor decode_image ( Tensor contents , int channels = 0 , TF_DataType dtype = TF_DataType . TF_UINT8 ,
1699
1699
string name = null , bool expand_animations = true )
1700
1700
{
1701
- return tf_with ( ops . name_scope ( name , "decode_image" ) , scope =>
1702
- {
1703
- var substr = tf . strings . substr ( contents , 0 , 3 ) ;
1704
-
1705
- Func < ITensorOrOperation > _jpeg = ( ) =>
1706
- {
1707
- int jpeg_channels = channels ;
1708
- var good_channels = math_ops . not_equal ( jpeg_channels , 4 , name : "check_jpeg_channels" ) ;
1709
- string channels_msg = "Channels must be in (None, 0, 1, 3) when decoding JPEG 'images'" ;
1710
- var assert_channels = control_flow_ops . Assert ( good_channels , new string [ ] { channels_msg } ) ;
1711
- return tf_with ( ops . control_dependencies ( new [ ] { assert_channels } ) , delegate
1712
- {
1713
- return convert_image_dtype ( gen_image_ops . decode_jpeg ( contents , channels ) , dtype ) ;
1714
- } ) ;
1715
- } ;
1701
+ var scope = ops . name_scope ( name , "decode_image" ) ;
1702
+ scope . __enter__ ( ) ;
1716
1703
1717
- /*Func<ITensorOrOperation> _gif = () =>
1718
- {
1719
- int gif_channels = channels;
1720
- var good_channels = math_ops.logical_and(
1721
- math_ops.not_equal(gif_channels, 1, name: "check_gif_channels"),
1722
- math_ops.not_equal(gif_channels, 4, name: "check_gif_channels"));
1723
-
1724
- string channels_msg = "Channels must be in (None, 0, 3) when decoding GIF images";
1725
- var assert_channels = control_flow_ops.Assert(good_channels, new string[] { channels_msg });
1726
- return tf_with(ops.control_dependencies(new[] { assert_channels }), delegate
1727
- {
1728
- var result = convert_image_dtype(gen_image_ops.decode_gif(contents), dtype);
1729
- if (!expand_animations)
1730
- result = array_ops.gather(result, 0);
1731
- return result;
1732
- });
1733
- };
1704
+ var result = gen_image_ops . decode_image ( contents ,
1705
+ channels : channels ,
1706
+ dtype : dtype ,
1707
+ expand_animations : expand_animations ) ;
1734
1708
1735
- Func<ITensorOrOperation> _bmp = () =>
1736
- {
1737
- int bmp_channels = channels;
1738
- var signature = tf.strings.substr(contents, 0, 2);
1739
- var is_bmp = math_ops.equal(signature, "BM", name: "is_bmp");
1740
- string decode_msg = "Unable to decode bytes as JPEG, PNG, GIF, or BMP";
1741
- var assert_decode = control_flow_ops.Assert(is_bmp, new string[] { decode_msg });
1742
- var good_channels = math_ops.not_equal(bmp_channels, 1, name: "check_channels");
1743
- string channels_msg = "Channels must be in (None, 0, 3) when decoding BMP images";
1744
- var assert_channels = control_flow_ops.Assert(good_channels, new string[] { channels_msg });
1745
- return tf_with(ops.control_dependencies(new[] { assert_decode, assert_channels }), delegate
1746
- {
1747
- return convert_image_dtype(gen_image_ops.decode_bmp(contents), dtype);
1748
- });
1749
- };
1750
-
1751
- Func<ITensorOrOperation> _png = () =>
1752
- {
1753
- return convert_image_dtype(gen_image_ops.decode_png(
1754
- contents,
1755
- channels,
1756
- dtype: dtype),
1757
- dtype);
1758
- };
1759
-
1760
- Func<ITensorOrOperation> check_gif = () =>
1761
- {
1762
- var gif = tf.constant(new byte[] { 0x47, 0x49, 0x46 }, TF_DataType.TF_STRING);
1763
- var is_gif = math_ops.equal(substr, gif, name: name);
1764
- return control_flow_ops.cond(is_gif, _gif, _bmp, name: "cond_gif");
1765
- };
1766
-
1767
- Func<ITensorOrOperation> check_png = () =>
1768
- {
1769
- return control_flow_ops.cond(is_png(contents), _png, check_gif, name: "cond_png");
1770
- };*/
1771
-
1772
- // return control_flow_ops.cond(is_jpeg(contents), _jpeg, check_png, name: "cond_jpeg");
1773
- return _jpeg ( ) as Tensor ;
1774
- } ) ;
1709
+ scope . __exit__ ( ) ;
1710
+ return result ;
1775
1711
}
1776
1712
1777
1713
public static Tensor crop_and_resize ( Tensor image , Tensor boxes , Tensor box_ind , Tensor crop_size , string method , float extrapolation_value , string name )
0 commit comments