Skip to content
Merged

FPN #55

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 22 additions & 40 deletions keras_resnet/models/_feature_pyramid_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

class FPN2D(keras.Model):
def __init__(
self,
inputs,
blocks,
block,
freeze_bn=True,
numerical_names=None,
*args,
**kwargs
self,
inputs,
blocks,
block,
freeze_bn=True,
numerical_names=None,
*args,
**kwargs
):
if keras.backend.image_data_format() == "channels_last":
axis = 3
Expand All @@ -36,7 +36,6 @@ def __init__(
numerical_names = [True] * len(blocks)

x = keras.layers.Conv2D(64, (7, 7), strides=(2, 2), use_bias=False, name="conv1", padding="same")(inputs)
# x = keras.layers.Lambda(lambda x_in: tensorflow.contrib.layers.group_norm(x_in, groups=1, channels_axis=axis))(x)
x = keras_resnet.layers.BatchNormalization(axis=axis, epsilon=1e-5, freeze=freeze_bn, name="bn_conv1")(x)
x = keras.layers.Activation("relu", name="conv1_relu")(x)
x = keras.layers.MaxPooling2D((3, 3), strides=(2, 2), padding="same", name="pool1")(x)
Expand Down Expand Up @@ -72,18 +71,9 @@ def __init__(
upsampled_p5 = keras.layers.UpSampling2D(
interpolation="bilinear",
name="p5_upsampled",
# size=(c4.shape[1], c4.shape[2]) # NOT THE SHAPE ! THE STRIDE
size=(2, 2)
)(pyramid_5)

pyramid_5 = keras.layers.Conv2D(
filters=256,
kernel_size=3,
strides=1,
padding="same",
name="p5"
)(pyramid_5)

pyramid_4 = keras.layers.Conv2D(
filters=256,
kernel_size=1,
Expand All @@ -99,7 +89,6 @@ def __init__(
upsampled_p4 = keras.layers.UpSampling2D(
interpolation="bilinear",
name="p4_upsampled",
# size=(c3.shape[1], c3.shape[2])
size=(2, 2)
)(pyramid_4)

Expand All @@ -126,7 +115,6 @@ def __init__(
upsampled_p3 = keras.layers.UpSampling2D(
interpolation="bilinear",
name="p3_upsampled",
# size=(c3.shape[1], c3.shape[2])
size=(2, 2)
)(pyramid_3)

Expand Down Expand Up @@ -158,13 +146,7 @@ def __init__(
name="p2"
)(pyramid_2)

pyramid_6 = keras.layers.Conv2D(
filters=256,
kernel_size=3,
strides=2,
padding="same",
name="p6"
)(c5)
pyramid_6 = keras.layers.MaxPooling2D(strides=2, name="p6")(pyramid_5)

outputs = [
pyramid_2,
Expand All @@ -182,26 +164,29 @@ def __init__(
)


class FPN2D18(FPN2D):
class FPN2D50(FPN2D):
def __init__(self, inputs, blocks=None, *args, **kwargs):
if blocks is None:
blocks = [2, 2, 2, 2]
blocks = [3, 4, 6, 3]

super(FPN2D18, self).__init__(
numerical_names = [False, False, False, False]

super(FPN2D50, self).__init__(
inputs,
blocks,
block=keras_resnet.blocks.basic_2d,
numerical_names=numerical_names,
block=keras_resnet.blocks.bottleneck_2d,
*args,
**kwargs
)


class FPN2D34(FPN2D):
class FPN2D18(FPN2D):
def __init__(self, inputs, blocks=None, *args, **kwargs):
if blocks is None:
blocks = [3, 4, 6, 3]
blocks = [2, 2, 2, 2]

super(FPN2D34, self).__init__(
super(FPN2D18, self).__init__(
inputs,
blocks,
block=keras_resnet.blocks.basic_2d,
Expand All @@ -210,18 +195,15 @@ def __init__(self, inputs, blocks=None, *args, **kwargs):
)


class FPN2D50(FPN2D):
class FPN2D34(FPN2D):
def __init__(self, inputs, blocks=None, *args, **kwargs):
if blocks is None:
blocks = [3, 4, 6, 3]

numerical_names = [False, False, False, False]

super(FPN2D50, self).__init__(
super(FPN2D34, self).__init__(
inputs,
blocks,
numerical_names=numerical_names,
block=keras_resnet.blocks.bottleneck_2d,
block=keras_resnet.blocks.basic_2d,
*args,
**kwargs
)
Expand Down