-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathmodel.py
111 lines (108 loc) · 3.62 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import (
Dense,
InputLayer,
Dropout,
Flatten,
Reshape,
LeakyReLU,
)
from tensorflow.keras.layers import Conv2D, MaxPooling2D, GlobalMaxPooling2D
from tensorflow.keras.regularizers import l2
from utils import CustomReshapeLayer
def yolo_model():
# We will follow the leaky relu activation as mentioned in the paper
leakyR = LeakyReLU(alpha=0.1)
# Stack 1
model = Sequential()
model.add(
Conv2D(
filters=64,
kernel_size=(7, 7),
strides=(2, 2),
input_shape=(448, 448, 3),
padding="same",
activation=leakyR,
)
)
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2), padding="same"))
# Stack2
model.add(
Conv2D(filters=192, kernel_size=(3, 3), padding="same", activation=leakyR)
)
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2), padding="same"))
# Stack3
model.add(
Conv2D(filters=128, kernel_size=(1, 1), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=256, kernel_size=(3, 3), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=256, kernel_size=(1, 1), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=512, kernel_size=(3, 3), padding="same", activation=leakyR)
)
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2), padding="same"))
# Stack4
model.add(
Conv2D(filters=256, kernel_size=(1, 1), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=512, kernel_size=(3, 3), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=256, kernel_size=(1, 1), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=512, kernel_size=(3, 3), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=256, kernel_size=(1, 1), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=512, kernel_size=(3, 3), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=256, kernel_size=(1, 1), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=512, kernel_size=(3, 3), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=512, kernel_size=(1, 1), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=1024, kernel_size=(3, 3), padding="same", activation=leakyR)
)
model.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2), padding="same"))
# Stack5
model.add(
Conv2D(filters=512, kernel_size=(1, 1), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=1024, kernel_size=(3, 3), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=512, kernel_size=(1, 1), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=1024, kernel_size=(3, 3), padding="same", activation=leakyR)
)
model.add(
Conv2D(filters=1024, kernel_size=(3, 3), padding="same", activation=leakyR)
)
model.add(Conv2D(filters=1024, kernel_size=(3, 3), strides=(2, 2), padding="same"))
# Stack6
model.add(Conv2D(filters=1024, kernel_size=(3, 3), activation=leakyR))
model.add(Conv2D(filters=1024, kernel_size=(3, 3), activation=leakyR))
# Fully Connected Layers
model.add(Flatten())
model.add(Dense(512))
model.add(Dense(1024))
model.add(Dropout(0.5))
model.add(Dense(1470, activation="sigmoid"))
model.add(CustomReshapeLayer(target_shape=(7, 7, 30)))
# model.summary()
return model