Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] Loss function #5

Open
LdDl opened this issue Nov 3, 2020 · 0 comments
Open

[FEATURE REQUEST] Loss function #5

LdDl opened this issue Nov 3, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@LdDl
Copy link
Owner

LdDl commented Nov 3, 2020

Is your feature request related to a problem? Please describe.
Current trainer - https://github.com/LdDl/yolo-go/blob/master/yolo_trainer.go#L11
Current loss function for YOLO bounding boxes - https://github.com/LdDl/yolo-go/blob/master/yolo_trainer.go#L100
I have doubts that it is right code (or even approach). Need to implement it step-by-step and compare with classic C-based implementation (may be take inspirations by some tensorflow/pytorch implementation)

Describe the solution you'd like and provide pseudocode examples if you can
According to source code of YOLO:
IOU's - https://github.com/AlexeyAB/darknet/blob/master/src/yolo_layer.c#L166:

float delta_yolo_box(box truth, float *x, float *biases, int n, int index, int i, int j, int lw, int lh, int w, int h, float *delta, float scale, int stride)
{
    box pred = get_yolo_box(x, biases, n, index, i, j, lw, lh, w, h, stride);
    float iou = box_iou(pred, truth);

    float tx = (truth.x*lw - i);
    float ty = (truth.y*lh - j);
    float tw = log(truth.w*w / biases[2*n]);
    float th = log(truth.h*h / biases[2*n + 1]);

    delta[index + 0*stride] = scale * (tx - x[index + 0*stride]);
    delta[index + 1*stride] = scale * (ty - x[index + 1*stride]);
    delta[index + 2*stride] = scale * (tw - x[index + 2*stride]);
    delta[index + 3*stride] = scale * (th - x[index + 3*stride]);
    return iou;
}

classes - https://github.com/AlexeyAB/darknet/blob/master/src/yolo_layer.c#L276:

void delta_yolo_class(float *output, float *delta, int index, int class, int classes, int stride, float *avg_cat)
{
    int n;
    if (delta[index]){
        delta[index + stride*class] = 1 - output[index + stride*class];
        if(avg_cat) *avg_cat += output[index + stride*class];
        return;
    }
    for(n = 0; n < classes; ++n){
        delta[index + stride*n] = ((n == class)?1 : 0) - output[index + stride*n];
        if(n == class && avg_cat) *avg_cat += output[index + stride*n];
    }
}

Describe alternatives you've considered and provide pseudocode examples if you can
nope

Additional context
nope

@LdDl LdDl added enhancement New feature or request good first issue Good for newcomers labels Nov 3, 2020
@LdDl LdDl self-assigned this Nov 3, 2020
@LdDl LdDl added this to the Training mode milestone Nov 3, 2020
@LdDl LdDl added help wanted Extra attention is needed question Further information is requested and removed question Further information is requested labels Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant