Skip to content

Commit 9888d0e

Browse files
committed
update training code
1 parent a2903f7 commit 9888d0e

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

core/yolov4.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
import core.backbone as backbone
99
from core.config import cfg
1010

11-
12-
NUM_CLASS = len(utils.read_class_names(cfg.YOLO.CLASSES))
13-
STRIDES = np.array(cfg.YOLO.STRIDES)
14-
IOU_LOSS_THRESH = cfg.YOLO.IOU_LOSS_THRESH
15-
XYSCALE = cfg.YOLO.XYSCALE
16-
ANCHORS = utils.get_anchors(cfg.YOLO.ANCHORS)
11+
# NUM_CLASS = len(utils.read_class_names(cfg.YOLO.CLASSES))
12+
# STRIDES = np.array(cfg.YOLO.STRIDES)
13+
# IOU_LOSS_THRESH = cfg.YOLO.IOU_LOSS_THRESH
14+
# XYSCALE = cfg.YOLO.XYSCALE
15+
# ANCHORS = utils.get_anchors(cfg.YOLO.ANCHORS)
1716

1817
def YOLOv3(input_layer, NUM_CLASS):
1918
route_1, route_2, conv = backbone.darknet53(input_layer)
@@ -251,8 +250,7 @@ def bbox_giou(boxes1, boxes2):
251250

252251
return giou
253252

254-
# def compute_loss(pred, conv, label, bboxes, STRIDES, NUM_CLASS, IOU_LOSS_THRESH, i=0):
255-
def compute_loss(pred, conv, label, bboxes, i=0):
253+
def compute_loss(pred, conv, label, bboxes, STRIDES, NUM_CLASS, IOU_LOSS_THRESH, i=0):
256254
conv_shape = tf.shape(conv)
257255
batch_size = conv_shape[0]
258256
output_size = conv_shape[1]

train.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def main(_argv):
4343
bbox_tensors = []
4444
for i, fm in enumerate(feature_maps):
4545
bbox_tensor = decode_train(fm, NUM_CLASS, STRIDES, ANCHORS, i)
46+
bbox_tensors.append(fm)
4647
bbox_tensors.append(bbox_tensor)
4748
model = tf.keras.Model(input_layer, bbox_tensors)
4849
else:
@@ -51,13 +52,15 @@ def main(_argv):
5152
bbox_tensors = []
5253
for i, fm in enumerate(feature_maps):
5354
bbox_tensor = decode_train(fm, NUM_CLASS, STRIDES, ANCHORS, i)
55+
bbox_tensors.append(fm)
5456
bbox_tensors.append(bbox_tensor)
5557
model = tf.keras.Model(input_layer, bbox_tensors)
5658
elif FLAGS.model == 'yolov4':
5759
feature_maps = YOLOv4(input_layer, NUM_CLASS)
5860
bbox_tensors = []
5961
for i, fm in enumerate(feature_maps):
6062
bbox_tensor = decode_train(fm, NUM_CLASS, STRIDES, ANCHORS, i, XYSCALE)
63+
bbox_tensors.append(fm)
6164
bbox_tensors.append(bbox_tensor)
6265
model = tf.keras.Model(input_layer, bbox_tensors)
6366

@@ -89,8 +92,7 @@ def train_step(image_data, target):
8992
# optimizing process
9093
for i in range(3):
9194
conv, pred = pred_result[i * 2], pred_result[i * 2 + 1]
92-
# loss_items = compute_loss(pred, conv, target[i][0], target[i][1], STRIDES=STRIDES, NUM_CLASS=NUM_CLASS, IOU_LOSS_THRESH=IOU_LOSS_THRESH, i=i)
93-
loss_items = compute_loss(pred, conv, *target[i], i)
95+
loss_items = compute_loss(pred, conv, target[i][0], target[i][1], STRIDES=STRIDES, NUM_CLASS=NUM_CLASS, IOU_LOSS_THRESH=IOU_LOSS_THRESH, i=i)
9496
giou_loss += loss_items[0]
9597
conf_loss += loss_items[1]
9698
prob_loss += loss_items[2]
@@ -129,7 +131,7 @@ def test_step(image_data, target):
129131
# optimizing process
130132
for i in range(3):
131133
conv, pred = pred_result[i * 2], pred_result[i * 2 + 1]
132-
loss_items = compute_loss(pred, conv, *target[i], STRIDES=STRIDES, NUM_CLASS=NUM_CLASS, IOU_LOSS_THRESH=IOU_LOSS_THRESH, i=i)
134+
loss_items = compute_loss(pred, conv, target[i][0], target[i][1], STRIDES=STRIDES, NUM_CLASS=NUM_CLASS, IOU_LOSS_THRESH=IOU_LOSS_THRESH, i=i)
133135
giou_loss += loss_items[0]
134136
conf_loss += loss_items[1]
135137
prob_loss += loss_items[2]

0 commit comments

Comments
 (0)