Skip to content

Commit

Permalink
Refacto architecture outputs orders
Browse files Browse the repository at this point in the history
  • Loading branch information
lmontier committed Jun 10, 2020
1 parent f56c49a commit 02a2fe0
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def cspdarknet53_416():

@pytest.fixture(scope="session")
def yolov4_neck_416():
input_shapes = [(13, 13, 1024), (26, 26, 512), (52, 52, 256)]
input_shapes = [(52, 52, 256), (26, 26, 512), (13, 13, 1024)]
return yolov4_neck(input_shapes)


@pytest.fixture(scope="session")
def yolov3_head_416_training(num_classes, yolo_max_boxes):
input_shapes = [(13, 13, 512), (26, 26, 256), (52, 52, 128)]
input_shapes = [(52, 52, 128), (26, 26, 256), (13, 13, 512)]

return yolov3_head(
input_shapes,
Expand All @@ -35,7 +35,7 @@ def yolov3_head_416_training(num_classes, yolo_max_boxes):

@pytest.fixture(scope="session")
def yolov3_head_416_inference(num_classes, yolo_max_boxes):
input_shapes = [(13, 13, 512), (26, 26, 256), (52, 52, 128)]
input_shapes = [(52, 52, 128), (26, 26, 256), (13, 13, 512)]

return yolov3_head(
input_shapes,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_csp_darknet53.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
def test_backbone_should_have_valid_output_shapes(cspdarknet53_416):
output_1, output_2, output_3 = cspdarknet53_416.outputs
assert output_1.shape.as_list() == [None, 13, 13, 1024]
assert output_1.shape.as_list() == [None, 52, 52, 256]
assert output_2.shape.as_list() == [None, 26, 26, 512]
assert output_3.shape.as_list() == [None, 52, 52, 256]
assert output_3.shape.as_list() == [None, 13, 13, 1024]


def test_backbone_should_have_the_right_number_of_parameters(cspdarknet53_416):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def test_model_should_predict_valid_shapes_at_training(yolov4_training, num_clas
tf.random.uniform((n_images, 416, 416, 3))
)

assert output_1.shape == (n_images, 13, 13, 3, expected_head_shape)
assert output_1.shape == (n_images, 52, 52, 3, expected_head_shape)
assert output_2.shape == (n_images, 26, 26, 3, expected_head_shape)
assert output_3.shape == (n_images, 52, 52, 3, expected_head_shape)
assert output_3.shape == (n_images, 13, 13, 3, expected_head_shape)


def test_model_should_predict_valid_shapes_at_inference(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_yolov3_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ def test_head_should_have_valid_output_shapes_training(
expected_head_shape = (num_classes + objectness_score_shape) + bounding_box_shape

output_1, output_2, output_3 = yolov3_head_416_training.outputs
assert output_1.shape.as_list() == [None, 13, 13, 3, expected_head_shape]
assert output_1.shape.as_list() == [None, 52, 52, 3, expected_head_shape]
assert output_2.shape.as_list() == [None, 26, 26, 3, expected_head_shape]
assert output_3.shape.as_list() == [None, 52, 52, 3, expected_head_shape]
assert output_3.shape.as_list() == [None, 13, 13, 3, expected_head_shape]


def test_head_should_have_valid_output_shapes_inference(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_yolov4_neck.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def test_neck_should_have_valid_output_shapes(yolov4_neck_416):
output_1, output_2, output_3 = yolov4_neck_416.outputs
assert output_1.shape.as_list() == [None, 13, 13, 512]
assert output_1.shape.as_list() == [None, 52, 52, 128]
assert output_2.shape.as_list() == [None, 26, 26, 256]
assert output_3.shape.as_list() == [None, 52, 52, 128]
assert output_3.shape.as_list() == [None, 13, 13, 512]
8 changes: 4 additions & 4 deletions tf2_yolov4/anchors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import numpy as np

YOLOV4_ANCHORS = [
np.array([(142, 110), (192, 243), (459, 401)], np.float32),
np.array([(36, 75), (76, 55), (72, 146)], np.float32),
np.array([(12, 16), (19, 36), (40, 28)], np.float32),
np.array([(36, 75), (76, 55), (72, 146)], np.float32),
np.array([(142, 110), (192, 243), (459, 401)], np.float32),
]

YOLOV3_ANCHORS = [
np.array([(116, 90), (156, 198), (373, 326)], np.float32),
np.array([(30, 61), (62, 45), (59, 119)], np.float32),
np.array([(10, 13), (16, 30), (33, 23)], np.float32),
np.array([(30, 61), (62, 45), (59, 119)], np.float32),
np.array([(116, 90), (156, 198), (373, 326)], np.float32),
]


Expand Down
2 changes: 1 addition & 1 deletion tf2_yolov4/backbones/csp_darknet53.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def csp_darknet53(input_shape):
# Fifth downsampling: L616 -> L744
output_3 = csp_block(output_2, filters=1024, num_blocks=4)

return tf.keras.Model(inputs, [output_3, output_2, output_1], name="CSPDarknet53")
return tf.keras.Model(inputs, [output_1, output_2, output_3], name="CSPDarknet53")


if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions tf2_yolov4/heads/yolov3_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def yolov3_head(
input_2 = tf.keras.Input(shape=filter(None, input_shapes[1]))
input_3 = tf.keras.Input(shape=filter(None, input_shapes[2]))

x = conv_bn(input_3, filters=256, kernel_size=3, strides=1, activation="leaky_relu")
output_3 = conv_classes_anchors(
x = conv_bn(input_1, filters=256, kernel_size=3, strides=1, activation="leaky_relu")
output_1 = conv_classes_anchors(
x, num_anchors_stage=len(anchors[0]), num_classes=num_classes
)

x = conv_bn(
input_3,
input_1,
filters=256,
kernel_size=3,
strides=2,
Expand Down Expand Up @@ -80,14 +80,14 @@ def yolov3_head(
padding="valid",
activation="leaky_relu",
)
x = tf.keras.layers.Concatenate()([x, input_1])
x = tf.keras.layers.Concatenate()([x, input_3])
x = conv_bn(x, filters=512, kernel_size=1, strides=1, activation="leaky_relu")
x = conv_bn(x, filters=1024, kernel_size=3, strides=1, activation="leaky_relu")
x = conv_bn(x, filters=512, kernel_size=1, strides=1, activation="leaky_relu")
x = conv_bn(x, filters=1024, kernel_size=3, strides=1, activation="leaky_relu")
x = conv_bn(x, filters=512, kernel_size=1, strides=1, activation="leaky_relu")
x = conv_bn(x, filters=1024, kernel_size=3, strides=1, activation="leaky_relu")
output_1 = conv_classes_anchors(
output_3 = conv_classes_anchors(
x, num_anchors_stage=len(anchors[2]), num_classes=num_classes
)

Expand Down
10 changes: 5 additions & 5 deletions tf2_yolov4/necks/yolov4_neck.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def yolov4_neck(input_shapes):
input_2 = tf.keras.Input(shape=filter(None, input_shapes[1]))
input_3 = tf.keras.Input(shape=filter(None, input_shapes[2]))

x = conv_bn(input_1, filters=512, kernel_size=1, strides=1, activation="leaky_relu")
x = conv_bn(input_3, filters=512, kernel_size=1, strides=1, activation="leaky_relu")
x = conv_bn(x, filters=1024, kernel_size=3, strides=1, activation="leaky_relu")
x = conv_bn(x, filters=512, kernel_size=1, strides=1, activation="leaky_relu")

Expand All @@ -31,11 +31,11 @@ def yolov4_neck(input_shapes):

x = conv_bn(spp, filters=512, kernel_size=1, strides=1, activation="leaky_relu")
x = conv_bn(x, filters=1024, kernel_size=3, strides=1, activation="leaky_relu")
output_1 = conv_bn(
output_3 = conv_bn(
x, filters=512, kernel_size=1, strides=1, activation="leaky_relu"
)
x = conv_bn(
output_1, filters=256, kernel_size=1, strides=1, activation="leaky_relu"
output_3, filters=256, kernel_size=1, strides=1, activation="leaky_relu"
)

upsampled = tf.keras.layers.UpSampling2D()(x)
Expand All @@ -56,14 +56,14 @@ def yolov4_neck(input_shapes):

upsampled = tf.keras.layers.UpSampling2D()(x)

x = conv_bn(input_3, filters=128, kernel_size=1, strides=1, activation="leaky_relu")
x = conv_bn(input_1, filters=128, kernel_size=1, strides=1, activation="leaky_relu")
x = tf.keras.layers.Concatenate()([x, upsampled])

x = conv_bn(x, filters=128, kernel_size=1, strides=1, activation="leaky_relu")
x = conv_bn(x, filters=256, kernel_size=3, strides=1, activation="leaky_relu")
x = conv_bn(x, filters=128, kernel_size=1, strides=1, activation="leaky_relu")
x = conv_bn(x, filters=256, kernel_size=3, strides=1, activation="leaky_relu")
output_3 = conv_bn(
output_1 = conv_bn(
x, filters=128, kernel_size=1, strides=1, activation="leaky_relu"
)

Expand Down

0 comments on commit 02a2fe0

Please sign in to comment.