Skip to content

Instantly share code, notes, and snippets.

@John1231983
Created March 13, 2018 22:57
Show Gist options
  • Save John1231983/d044137611102f77e2cad3bbe5b453fe to your computer and use it in GitHub Desktop.
Save John1231983/d044137611102f77e2cad3bbe5b453fe to your computer and use it in GitHub Desktop.
_, C2, C3, C4, C5 = resnet_graph(input_image, "resnet50", stage5=True)
P5 = KL.Conv2D(256, (1, 1), name='fpn_c5p5')(C5)
P4 = KL.Add(name="fpn_p4add")([
KL.UpSampling2D(size=(2, 2), name="fpn_p5upsampled")(P5),
KL.Conv2D(256, (1, 1), name='fpn_c4p4')(C4)])
P3 = KL.Add(name="fpn_p3add")([
KL.UpSampling2D(size=(2, 2), name="fpn_p4upsampled")(P4),
KL.Conv2D(256, (1, 1), name='fpn_c3p3')(C3)])
P2 = KL.Add(name="fpn_p2add")([
KL.UpSampling2D(size=(2, 2), name="fpn_p3upsampled")(P3),
KL.Conv2D(256, (1, 1), name='fpn_c2p2')(C2)])
# New branch
#Ni+1=Ni_down+P_(i+1)
N2= P2
N3 = KL.Add(name="fpn_p3n3add")([
KL.Conv2D(256, (3, 3), strides=2, name="fpn_p2downsampled", padding="same")(N2),P3])
N4 = KL.Add(name="fpn_p4n4add")([
KL.Conv2D(256, (3, 3), strides=2, name="fpn_p3downsampled",padding="same")(N3), P4])
N5 = KL.Add(name="fpn_p5n5add")([
KL.Conv2D(256, (3, 3), strides=2, name="fpn_p4downsampled",padding="same")(N4), P5])
# Attach 3x3 conv to all P layers to get the final feature maps.
N2 = KL.Conv2D(256, (3, 3), padding="SAME", name="fpn_n2")(N2)
N3 = KL.Conv2D(256, (3, 3), padding="SAME", name="fpn_n3")(N3)
N4 = KL.Conv2D(256, (3, 3), padding="SAME", name="fpn_n4")(N4)
N5 = KL.Conv2D(256, (3, 3), padding="SAME", name="fpn_n5")(N5)
# P6 is used for the 5th anchor scale in RPN. Generated by
# subsampling from P5 with stride of 2.
N6 = KL.MaxPooling2D(pool_size=(1, 1), strides=2, name="fpn_p6")(N5)
rpn_feature_maps = [N2, N3, N4, N5, N6]
mrcnn_feature_maps = [N2, N3, N4, N5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment