@@ -542,45 +542,49 @@ public static Tensor crop_to_bounding_box(Tensor image, int offset_height, int o
542
542
image_shape ) ) ;
543
543
}
544
544
545
- var assert_ops = _CheckAtLeast3DImage ( image , require_static : false ) ;
545
+ var assert_ops = _CheckAtLeast3DImage ( image , require_static : false ) . ToList ( ) ;
546
546
547
547
// batch: [0], height: [1], width: [2], depth: [3]
548
548
var bhwd = _ImageDimensions ( image , rank : 4 ) ;
549
549
550
- assert_ops [ assert_ops . Length ] = _assert ( check_ops . assert_greater_equal ( tf . constant ( offset_height ) ,
550
+ assert_ops . Add ( _assert ( check_ops . assert_greater_equal ( tf . constant ( offset_height ) ,
551
551
tf . constant ( 0 ) ) , typeof ( ValueError ) ,
552
- "offset_height must be >= 0." ) ;
553
- assert_ops [ assert_ops . Length ] = _assert ( check_ops . assert_greater_equal ( tf . constant ( offset_width ) ,
552
+ "offset_height must be >= 0." ) ) ;
553
+ assert_ops . Add ( _assert ( check_ops . assert_greater_equal ( tf . constant ( offset_width ) ,
554
554
tf . constant ( 0 ) ) , typeof ( ValueError ) ,
555
- "offset_width must be >= 0." ) ;
556
- assert_ops [ assert_ops . Length ] = _assert ( check_ops . assert_less ( tf . constant ( 0 ) ,
555
+ "offset_width must be >= 0." ) ) ;
556
+ assert_ops . Add ( _assert ( check_ops . assert_less ( tf . constant ( 0 ) ,
557
557
tf . constant ( target_width ) ) , typeof ( ValueError ) ,
558
- "target_width must be > 0." ) ;
559
- assert_ops [ assert_ops . Length ] = _assert ( check_ops . assert_less ( tf . constant ( 0 ) ,
558
+ "target_width must be > 0." ) ) ;
559
+ assert_ops . Add ( _assert ( check_ops . assert_less ( tf . constant ( 0 ) ,
560
560
tf . constant ( target_height ) ) , typeof ( ValueError ) ,
561
- "target_height must be > 0." ) ;
562
- assert_ops [ assert_ops . Length ] = _assert ( check_ops . assert_greater_equal ( tf . constant ( bhwd [ 2 ] ) ,
561
+ "target_height must be > 0." ) ) ;
562
+ assert_ops . Add ( _assert ( check_ops . assert_greater_equal ( tf . constant ( bhwd [ 2 ] ) ,
563
563
tf . constant ( target_width + offset_width ) ) ,
564
564
typeof ( ValueError ) ,
565
- "width must be >= target + offset." ) ;
566
- assert_ops [ assert_ops . Length ] = _assert ( check_ops . assert_greater_equal ( tf . constant ( bhwd [ 1 ] ) ,
565
+ "width must be >= target + offset." ) ) ;
566
+ assert_ops . Add ( _assert ( check_ops . assert_greater_equal ( tf . constant ( bhwd [ 1 ] ) ,
567
567
tf . constant ( target_height + offset_height ) ) ,
568
568
typeof ( ValueError ) ,
569
- "height must be >= target + offset." ) ;
570
- image = control_flow_ops . with_dependencies ( assert_ops , image ) ;
569
+ "height must be >= target + offset." ) ) ;
570
+ image = control_flow_ops . with_dependencies ( assert_ops . ToArray ( ) , image ) ;
571
571
572
572
var cropped = array_ops . slice (
573
573
image , array_ops . stack ( new [ ] { 0 , offset_height , offset_width , 0 } ) ,
574
574
array_ops . stack ( new [ ] { - 1 , target_height , target_width , - 1 } ) ) ;
575
575
576
576
Shape cropped_shape_result ( )
577
577
{
578
- long [ ] i_remnants = { } ;
578
+ long [ ] i_remnants = new long [ 4 ] ;
579
+ int idx = 0 ;
579
580
foreach ( var i in new [ ] { bhwd [ 0 ] , target_height , target_width , bhwd [ 3 ] } )
581
+ {
580
582
if ( _is_tensor ( i ) )
581
- return null ;
583
+ i_remnants [ idx ] = - 1 ;
582
584
else
583
- i_remnants [ i_remnants . Length ] = i ;
585
+ i_remnants [ idx ] = i ;
586
+ idx ++ ;
587
+ }
584
588
return new Shape ( i_remnants ) ;
585
589
} ;
586
590
var cropped_shape = cropped_shape_result ( ) ;
0 commit comments