@@ -401,8 +401,18 @@ def __init__(self,
401
401
self .bns = []
402
402
self .grad_checkpoint = grad_checkpoint
403
403
self .feature_only = feature_only
404
-
405
- conv2d_layer = self .conv2d_layer (separable_conv , data_format )
404
+ if separable_conv :
405
+ conv2d_layer = functools .partial (
406
+ tf .keras .layers .SeparableConv2D ,
407
+ depth_multiplier = 1 ,
408
+ data_format = data_format ,
409
+ pointwise_initializer = tf .initializers .variance_scaling (),
410
+ depthwise_initializer = tf .initializers .variance_scaling ())
411
+ else :
412
+ conv2d_layer = functools .partial (
413
+ tf .keras .layers .Conv2D ,
414
+ data_format = data_format ,
415
+ kernel_initializer = tf .random_normal_initializer (stddev = 0.01 ))
406
416
for i in range (self .repeats ):
407
417
# If using SeparableConv2D
408
418
self .conv_ops .append (
@@ -425,8 +435,12 @@ def __init__(self,
425
435
))
426
436
self .bns .append (bn_per_level )
427
437
428
- self .classes = self .classes_layer (
429
- conv2d_layer , num_classes , num_anchors , name = 'class-predict' )
438
+ self .classes = conv2d_layer (
439
+ num_classes * num_anchors ,
440
+ kernel_size = 3 ,
441
+ bias_initializer = tf .constant_initializer (- np .log ((1 - 0.01 ) / 0.01 )),
442
+ padding = 'same' ,
443
+ name = 'class-predict' )
430
444
431
445
@tf .autograph .experimental .do_not_convert
432
446
def _conv_bn_act (self , image , i , level_id , training ):
@@ -462,33 +476,6 @@ def call(self, inputs, training, **kwargs):
462
476
463
477
return class_outputs
464
478
465
- @classmethod
466
- def conv2d_layer (cls , separable_conv , data_format ):
467
- """Gets the conv2d layer in ClassNet class."""
468
- if separable_conv :
469
- conv2d_layer = functools .partial (
470
- tf .keras .layers .SeparableConv2D ,
471
- depth_multiplier = 1 ,
472
- data_format = data_format ,
473
- pointwise_initializer = tf .initializers .variance_scaling (),
474
- depthwise_initializer = tf .initializers .variance_scaling ())
475
- else :
476
- conv2d_layer = functools .partial (
477
- tf .keras .layers .Conv2D ,
478
- data_format = data_format ,
479
- kernel_initializer = tf .random_normal_initializer (stddev = 0.01 ))
480
- return conv2d_layer
481
-
482
- @classmethod
483
- def classes_layer (cls , conv2d_layer , num_classes , num_anchors , name ):
484
- """Gets the classes layer in ClassNet class."""
485
- return conv2d_layer (
486
- num_classes * num_anchors ,
487
- kernel_size = 3 ,
488
- bias_initializer = tf .constant_initializer (- np .log ((1 - 0.01 ) / 0.01 )),
489
- padding = 'same' ,
490
- name = name )
491
-
492
479
493
480
class BoxNet (tf .keras .layers .Layer ):
494
481
"""Box regression network."""
@@ -587,8 +574,28 @@ def __init__(self,
587
574
name = 'box-%d-bn-%d' % (i , level )))
588
575
self .bns .append (bn_per_level )
589
576
590
- self .boxes = self .boxes_layer (
591
- separable_conv , num_anchors , data_format , name = 'box-predict' )
577
+ if self .separable_conv :
578
+ self .boxes = tf .keras .layers .SeparableConv2D (
579
+ filters = 4 * self .num_anchors ,
580
+ depth_multiplier = 1 ,
581
+ pointwise_initializer = tf .initializers .variance_scaling (),
582
+ depthwise_initializer = tf .initializers .variance_scaling (),
583
+ data_format = self .data_format ,
584
+ kernel_size = 3 ,
585
+ activation = None ,
586
+ bias_initializer = tf .zeros_initializer (),
587
+ padding = 'same' ,
588
+ name = 'box-predict' )
589
+ else :
590
+ self .boxes = tf .keras .layers .Conv2D (
591
+ filters = 4 * self .num_anchors ,
592
+ kernel_initializer = tf .random_normal_initializer (stddev = 0.01 ),
593
+ data_format = self .data_format ,
594
+ kernel_size = 3 ,
595
+ activation = None ,
596
+ bias_initializer = tf .zeros_initializer (),
597
+ padding = 'same' ,
598
+ name = 'box-predict' )
592
599
593
600
@tf .autograph .experimental .do_not_convert
594
601
def _conv_bn_act (self , image , i , level_id , training ):
@@ -625,32 +632,6 @@ def call(self, inputs, training):
625
632
626
633
return box_outputs
627
634
628
- @classmethod
629
- def boxes_layer (cls , separable_conv , num_anchors , data_format , name ):
630
- """Gets the conv2d layer in BoxNet class."""
631
- if separable_conv :
632
- return tf .keras .layers .SeparableConv2D (
633
- filters = 4 * num_anchors ,
634
- depth_multiplier = 1 ,
635
- pointwise_initializer = tf .initializers .variance_scaling (),
636
- depthwise_initializer = tf .initializers .variance_scaling (),
637
- data_format = data_format ,
638
- kernel_size = 3 ,
639
- activation = None ,
640
- bias_initializer = tf .zeros_initializer (),
641
- padding = 'same' ,
642
- name = name )
643
- else :
644
- return tf .keras .layers .Conv2D (
645
- filters = 4 * num_anchors ,
646
- kernel_initializer = tf .random_normal_initializer (stddev = 0.01 ),
647
- data_format = data_format ,
648
- kernel_size = 3 ,
649
- activation = None ,
650
- bias_initializer = tf .zeros_initializer (),
651
- padding = 'same' ,
652
- name = name )
653
-
654
635
655
636
class SegmentationHead (tf .keras .layers .Layer ):
656
637
"""Keras layer for semantic segmentation head."""
0 commit comments