Skip to content

Commit 05ef3ae

Browse files
committed
model: Rename variables
필드 이름 순서를 반대로 정렬
1 parent 30eb969 commit 05ef3ae

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

model/yolov3.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,19 @@ def __init__(self, image_size: int, num_classes: int):
129129
final_out_channel = 3 * (4 + 1 + num_classes)
130130

131131
self.darknet53 = self.make_darknet53()
132-
self.conv_block1 = self.make_conv_block(1024, 512)
133-
self.conv_final1 = self.make_conv_final(512, final_out_channel)
134-
self.yolo_layer1 = YOLODetection(anchors['scale1'], image_size, num_classes)
132+
self.conv_block3 = self.make_conv_block(1024, 512)
133+
self.conv_final3 = self.make_conv_final(512, final_out_channel)
134+
self.yolo_layer3 = YOLODetection(anchors['scale1'], image_size, num_classes)
135135

136-
self.upsample1 = self.make_upsample(512, 256, scale_factor=2)
136+
self.upsample2 = self.make_upsample(512, 256, scale_factor=2)
137137
self.conv_block2 = self.make_conv_block(768, 256)
138138
self.conv_final2 = self.make_conv_final(256, final_out_channel)
139139
self.yolo_layer2 = YOLODetection(anchors['scale2'], image_size, num_classes)
140140

141-
self.upsample2 = self.make_upsample(256, 128, scale_factor=2)
142-
self.conv_block3 = self.make_conv_block(384, 128)
143-
self.conv_final3 = self.make_conv_final(128, final_out_channel)
144-
self.yolo_layer3 = YOLODetection(anchors['scale3'], image_size, num_classes)
141+
self.upsample1 = self.make_upsample(256, 128, scale_factor=2)
142+
self.conv_block1 = self.make_conv_block(384, 128)
143+
self.conv_final1 = self.make_conv_final(128, final_out_channel)
144+
self.yolo_layer1 = YOLODetection(anchors['scale3'], image_size, num_classes)
145145

146146
self.yolo_layers = [self.yolo_layer1, self.yolo_layer2, self.yolo_layer3]
147147

@@ -163,23 +163,23 @@ def forward(self, x, targets=None):
163163
residual_output[key] = x
164164

165165
# Yolov3 layer forward
166-
conv_b1 = self.conv_block1(residual_output['residual_5_4'])
167-
scale1 = self.conv_final1(conv_b1)
168-
yolo_output1, layer_loss = self.yolo_layer1(scale1, targets)
166+
conv_block3 = self.conv_block3(residual_output['residual_5_4'])
167+
scale3 = self.conv_final3(conv_block3)
168+
yolo_output3, layer_loss = self.yolo_layer3(scale3, targets)
169169
loss += layer_loss
170170

171-
scale2 = self.upsample1(conv_b1)
171+
scale2 = self.upsample2(conv_block3)
172172
scale2 = torch.cat((scale2, residual_output['residual_4_8']), dim=1)
173-
conv_b2 = self.conv_block2(scale2)
174-
scale2 = self.conv_final2(conv_b2)
173+
conv_block2 = self.conv_block2(scale2)
174+
scale2 = self.conv_final2(conv_block2)
175175
yolo_output2, layer_loss = self.yolo_layer2(scale2, targets)
176176
loss += layer_loss
177177

178-
scale3 = self.upsample2(conv_b2)
179-
scale3 = torch.cat((scale3, residual_output['residual_3_8']), dim=1)
180-
conv_b3 = self.conv_block3(scale3)
181-
scale3 = self.conv_final3(conv_b3)
182-
yolo_output3, layer_loss = self.yolo_layer3(scale3, targets)
178+
scale1 = self.upsample1(conv_block2)
179+
scale1 = torch.cat((scale1, residual_output['residual_3_8']), dim=1)
180+
conv_block1 = self.conv_block1(scale1)
181+
scale1 = self.conv_final1(conv_block1)
182+
yolo_output1, layer_loss = self.yolo_layer1(scale1, targets)
183183
loss += layer_loss
184184

185185
yolo_outputs = [yolo_output1, yolo_output2, yolo_output3]
@@ -288,17 +288,17 @@ def load_darknet_weights(self, weights_path: str):
288288

289289
# Load YOLOv3 weights
290290
if weights_path.find('yolov3.weights') != -1:
291-
for module in self.conv_block1:
291+
for module in self.conv_block3:
292292
ptr = self.load_bn_weights(module[1], weights, ptr)
293293
ptr = self.load_conv_weights(module[0], weights, ptr)
294294

295-
ptr = self.load_bn_weights(self.conv_final1[0][1], weights, ptr)
296-
ptr = self.load_conv_weights(self.conv_final1[0][0], weights, ptr)
297-
ptr = self.load_conv_bias(self.conv_final1[1], weights, ptr)
298-
ptr = self.load_conv_weights(self.conv_final1[1], weights, ptr)
295+
ptr = self.load_bn_weights(self.conv_final3[0][1], weights, ptr)
296+
ptr = self.load_conv_weights(self.conv_final3[0][0], weights, ptr)
297+
ptr = self.load_conv_bias(self.conv_final3[1], weights, ptr)
298+
ptr = self.load_conv_weights(self.conv_final3[1], weights, ptr)
299299

300-
ptr = self.load_bn_weights(self.upsample1[0][1], weights, ptr)
301-
ptr = self.load_conv_weights(self.upsample1[0][0], weights, ptr)
300+
ptr = self.load_bn_weights(self.upsample2[0][1], weights, ptr)
301+
ptr = self.load_conv_weights(self.upsample2[0][0], weights, ptr)
302302

303303
for module in self.conv_block2:
304304
ptr = self.load_bn_weights(module[1], weights, ptr)
@@ -309,17 +309,17 @@ def load_darknet_weights(self, weights_path: str):
309309
ptr = self.load_conv_bias(self.conv_final2[1], weights, ptr)
310310
ptr = self.load_conv_weights(self.conv_final2[1], weights, ptr)
311311

312-
ptr = self.load_bn_weights(self.upsample2[0][1], weights, ptr)
313-
ptr = self.load_conv_weights(self.upsample2[0][0], weights, ptr)
312+
ptr = self.load_bn_weights(self.upsample1[0][1], weights, ptr)
313+
ptr = self.load_conv_weights(self.upsample1[0][0], weights, ptr)
314314

315-
for module in self.conv_block3:
315+
for module in self.conv_block1:
316316
ptr = self.load_bn_weights(module[1], weights, ptr)
317317
ptr = self.load_conv_weights(module[0], weights, ptr)
318318

319-
ptr = self.load_bn_weights(self.conv_final3[0][1], weights, ptr)
320-
ptr = self.load_conv_weights(self.conv_final3[0][0], weights, ptr)
321-
ptr = self.load_conv_bias(self.conv_final3[1], weights, ptr)
322-
ptr = self.load_conv_weights(self.conv_final3[1], weights, ptr)
319+
ptr = self.load_bn_weights(self.conv_final1[0][1], weights, ptr)
320+
ptr = self.load_conv_weights(self.conv_final1[0][0], weights, ptr)
321+
ptr = self.load_conv_bias(self.conv_final1[1], weights, ptr)
322+
ptr = self.load_conv_weights(self.conv_final1[1], weights, ptr)
323323

324324
# Load BN bias, weights, running mean and running variance
325325
def load_bn_weights(self, bn_layer, weights, ptr: int):

0 commit comments

Comments
 (0)