Skip to content

Commit

Permalink
Fixed new_coords=1, yolov4-csp.cfg, yolov4x-mish.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyAB committed Dec 6, 2020
1 parent 4709f61 commit c47b24a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
8 changes: 4 additions & 4 deletions build/darknet/x64/cfg/yolov4-csp.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ size=1
stride=1
pad=1
filters=255
activation=linear
activation=logistic


[yolo]
Expand All @@ -1046,7 +1046,7 @@ iou_loss=ciou
nms_kind=diounms
beta_nms=0.6
new_coords=1
max_delta=20
max_delta=5

[route]
layers = -4
Expand Down Expand Up @@ -1137,7 +1137,7 @@ size=1
stride=1
pad=1
filters=255
activation=linear
activation=logistic


[yolo]
Expand Down Expand Up @@ -1251,7 +1251,7 @@ size=1
stride=1
pad=1
filters=255
activation=linear
activation=logistic


[yolo]
Expand Down
8 changes: 4 additions & 4 deletions build/darknet/x64/cfg/yolov4x-mish.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ size=1
stride=1
pad=1
filters=255
activation=linear
activation=logistic


[yolo]
Expand All @@ -1173,7 +1173,7 @@ iou_loss=ciou
nms_kind=diounms
beta_nms=0.6
new_coords=1
max_delta=20
max_delta=5

[route]
layers = -4
Expand Down Expand Up @@ -1280,7 +1280,7 @@ size=1
stride=1
pad=1
filters=255
activation=linear
activation=logistic


[yolo]
Expand Down Expand Up @@ -1410,7 +1410,7 @@ size=1
stride=1
pad=1
filters=255
activation=linear
activation=logistic


[yolo]
Expand Down
2 changes: 1 addition & 1 deletion src/detector.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i

//if (i % 1000 == 0 || (i < 1000 && i % 100 == 0)) {
//if (i % 100 == 0) {
if (iteration >= (iter_save + 1000) || iteration % 1000 == 0) {
if (iteration >= (iter_save + 10000) || iteration % 10000 == 0) {
iter_save = iteration;
#ifdef GPU
if (ngpus != 1) sync_nets(nets, ngpus, 0);
Expand Down
27 changes: 15 additions & 12 deletions src/yolo_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,13 @@ ious delta_yolo_box(box truth, float *x, float *biases, int n, int index, int i,
float dw = all_ious.dx_iou.dl;
float dh = all_ious.dx_iou.dr;

/*

// predict exponential, apply gradient of e^delta_t ONLY for w,h
if (new_coords) {
dw *= 8 * x[index + 2 * stride] * biases[2 * n] / w;
dh *= 8 * x[index + 3 * stride] * biases[2 * n + 1] / h;
//dw *= 8 * x[index + 2 * stride];
//dh *= 8 * x[index + 3 * stride];
//dw *= 8 * x[index + 2 * stride] * biases[2 * n] / w;
//dh *= 8 * x[index + 3 * stride] * biases[2 * n + 1] / h;

//float grad_w = 8 * exp(-x[index + 2 * stride]) / pow(exp(-x[index + 2 * stride]) + 1, 3);
//float grad_h = 8 * exp(-x[index + 3 * stride]) / pow(exp(-x[index + 3 * stride]) + 1, 3);
Expand All @@ -245,10 +247,10 @@ ious delta_yolo_box(box truth, float *x, float *biases, int n, int index, int i,
dw *= exp(x[index + 2 * stride]);
dh *= exp(x[index + 3 * stride]);
}
*/

dw *= exp(x[index + 2 * stride]);
dh *= exp(x[index + 3 * stride]);

//dw *= exp(x[index + 2 * stride]);
//dh *= exp(x[index + 3 * stride]);

// normalize iou weight
dx *= iou_normalizer;
Expand Down Expand Up @@ -668,14 +670,14 @@ void forward_yolo_layer(const layer l, network_state state)
for (n = 0; n < l.n; ++n) {
int index = entry_index(l, b, n*l.w*l.h, 0);
if (l.new_coords) {
activate_array(l.output + index, 4 * l.w*l.h, LOGISTIC); // x,y,w,h
//activate_array(l.output + index, 4 * l.w*l.h, LOGISTIC); // x,y,w,h
}
else {
activate_array(l.output + index, 2 * l.w*l.h, LOGISTIC); // x,y,
index = entry_index(l, b, n*l.w*l.h, 4);
activate_array(l.output + index, (1 + l.classes)*l.w*l.h, LOGISTIC);
}
scal_add_cpu(2 * l.w*l.h, l.scale_x_y, -0.5*(l.scale_x_y - 1), l.output + index, 1); // scale x,y
index = entry_index(l, b, n*l.w*l.h, 4);
activate_array(l.output + index, (1 + l.classes)*l.w*l.h, LOGISTIC);
}
}
#endif
Expand Down Expand Up @@ -1173,14 +1175,15 @@ void forward_yolo_layer_gpu(const layer l, network_state state)
// if(y->1) x -> inf
// if(y->0) x -> -inf
if (l.new_coords) {
activate_array_ongpu(l.output_gpu + index, 4 * l.w*l.h, LOGISTIC); // x,y,w,h
//activate_array_ongpu(l.output_gpu + index, 4 * l.w*l.h, LOGISTIC); // x,y,w,h
}
else {
activate_array_ongpu(l.output_gpu + index, 2 * l.w*l.h, LOGISTIC); // x,y

index = entry_index(l, b, n*l.w*l.h, 4);
activate_array_ongpu(l.output_gpu + index, (1 + l.classes)*l.w*l.h, LOGISTIC); // classes and objectness
}
if (l.scale_x_y != 1) scal_add_ongpu(2 * l.w*l.h, l.scale_x_y, -0.5*(l.scale_x_y - 1), l.output_gpu + index, 1); // scale x,y
index = entry_index(l, b, n*l.w*l.h, 4);
activate_array_ongpu(l.output_gpu + index, (1+l.classes)*l.w*l.h, LOGISTIC); // classes and objectness
}
}
if(!state.train || l.onlyforward){
Expand Down
2 changes: 1 addition & 1 deletion src/yolo_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void correct_yolo_boxes(detection *dets, int n, int w, int h, int netw, int neth

#ifdef GPU
void forward_yolo_layer_gpu(const layer l, network_state state);
void backward_yolo_layer_gpu(layer l, network_state state);
void backward_yolo_layer_gpu(const layer l, network_state state);
#endif

#ifdef __cplusplus
Expand Down

0 comments on commit c47b24a

Please sign in to comment.