Naming every copied layer

This commit is contained in:
Kunyuk 2021-11-27 06:15:07 +07:00
parent 6ed4ec7c21
commit 5fe7001ed0
1 changed files with 17 additions and 17 deletions

View File

@ -168,7 +168,7 @@ def conv_block(input_tensor, kernel_size, filters, stage, block,
return x
def resnet_graph(input_image, architecture, stage5=False, train_bn=True):
def resnet_graph(input_image, architecture, stage5=False, train_bn=True, cn=""):
"""Build a ResNet graph.
architecture: Can be resnet50 or resnet101
stage5: Boolean. If False, stage5 of the network is not created
@ -177,30 +177,30 @@ def resnet_graph(input_image, architecture, stage5=False, train_bn=True):
assert architecture in ["resnet50", "resnet101"]
# Stage 1
x = KL.ZeroPadding2D((3, 3))(input_image)
x = KL.Conv2D(64, (7, 7), strides=(2, 2), name='conv1', use_bias=True)(x)
x = BatchNorm(name='bn_conv1')(x, training=train_bn)
x = KL.Conv2D(64, (7, 7), strides=(2, 2), name='conv1' + cn, use_bias=True)(x)
x = BatchNorm(name='bn_conv1' + cn)(x, training=train_bn)
x = KL.Activation('relu')(x)
C1 = x = KL.MaxPooling2D((3, 3), strides=(2, 2), padding="same")(x)
# Stage 2
x = conv_block(x, 3, [64, 64, 256], stage=2, block='a', strides=(1, 1), train_bn=train_bn)
x = identity_block(x, 3, [64, 64, 256], stage=2, block='b', train_bn=train_bn)
C2 = x = identity_block(x, 3, [64, 64, 256], stage=2, block='c', train_bn=train_bn)
x = conv_block(x, 3, [64, 64, 256], stage=2, block='a' + cn, strides=(1, 1), train_bn=train_bn)
x = identity_block(x, 3, [64, 64, 256], stage=2, block='b' + cn, train_bn=train_bn)
C2 = x = identity_block(x, 3, [64, 64, 256], stage=2, block='c' + cn, train_bn=train_bn)
# Stage 3
x = conv_block(x, 3, [128, 128, 512], stage=3, block='a', train_bn=train_bn)
x = identity_block(x, 3, [128, 128, 512], stage=3, block='b', train_bn=train_bn)
x = identity_block(x, 3, [128, 128, 512], stage=3, block='c', train_bn=train_bn)
C3 = x = identity_block(x, 3, [128, 128, 512], stage=3, block='d', train_bn=train_bn)
x = conv_block(x, 3, [128, 128, 512], stage=3, block='a' + cn, train_bn=train_bn)
x = identity_block(x, 3, [128, 128, 512], stage=3, block='b' + cn, train_bn=train_bn)
x = identity_block(x, 3, [128, 128, 512], stage=3, block='c' + cn, train_bn=train_bn)
C3 = x = identity_block(x, 3, [128, 128, 512], stage=3, block='d' + cn, train_bn=train_bn)
# Stage 4
x = conv_block(x, 3, [256, 256, 1024], stage=4, block='a', train_bn=train_bn)
x = conv_block(x, 3, [256, 256, 1024], stage=4, block='a' + cn, train_bn=train_bn)
block_count = {"resnet50": 5, "resnet101": 22}[architecture]
for i in range(block_count):
x = identity_block(x, 3, [256, 256, 1024], stage=4, block=chr(98 + i), train_bn=train_bn)
x = identity_block(x, 3, [256, 256, 1024], stage=4, block=chr(98 + i) + cn, train_bn=train_bn)
C4 = x
# Stage 5
if stage5:
x = conv_block(x, 3, [512, 512, 2048], stage=5, block='a', train_bn=train_bn)
x = identity_block(x, 3, [512, 512, 2048], stage=5, block='b', train_bn=train_bn)
C5 = x = identity_block(x, 3, [512, 512, 2048], stage=5, block='c', train_bn=train_bn)
x = conv_block(x, 3, [512, 512, 2048], stage=5, block='a' + cn, train_bn=train_bn)
x = identity_block(x, 3, [512, 512, 2048], stage=5, block='b' + cn, train_bn=train_bn)
C5 = x = identity_block(x, 3, [512, 512, 2048], stage=5, block='c' + cn, train_bn=train_bn)
else:
C5 = None
return [C1, C2, C3, C4, C5]
@ -1907,9 +1907,9 @@ class MaskRCNN():
train_bn=config.TRAIN_BN)
else:
_, C2, C3, C4, C5 = resnet_graph(S_RGB, config.BACKBONE,
stage5=True, train_bn=config.TRAIN_BN)
stage5=True, train_bn=config.TRAIN_BN, cn="RGB")
_, C2D, C3D, C4D, C5D = resnet_graph(S_DEPTH, config.BACKBONE,
stage5=True, train_bn=config.TRAIN_BN)
stage5=True, train_bn=config.TRAIN_BN, cn="DEPTH")
# Top-down Layers
# TODO: add assert to varify feature map sizes match what's in config