Darknet:如何使用标签进行分类?

Darknet: How labels used for classification?

我想在没有 bbox 检测的情况下使用 YOLOv3 进行 class化,并且正在关注这个 link how to train a classifier with darknet

但是,我似乎无法确定每个图像的 class 的确切分配位置。每个图像都没有任何 .txt 文件用于检测。 class 是从文件名中简单提取出来的吗?

如何为我的多重 class class 化中的每个图像分配一个 class?或者我只是简单地输入图像,YOLO 根据您在 labels.txt 中指定的 classes 的数量自行学习?

是的,每个训练图像的class是从文件名中提取的。查看 src/data.c 中的 load_labels_path()fill_truth() 函数。 load_labels_path() 通过 # of classes 创建一个 # of images 矩阵,并用 1 和 0 填充它是否属于 class 使用 fill_truth(),它测试是否 class 名称是图像文件名的子字符串。

matrix load_labels_paths(char **paths, int n, char **labels, int k, tree *hierarchy)
{
    matrix y = make_matrix(n, k);
    int i;
    for(i = 0; i < n && labels; ++i){
        fill_truth(paths[i], labels, k, y.vals[i]);
        if(hierarchy){
            fill_hierarchy(y.vals[i], k, hierarchy);
        }
    }
    return y;
}

...

void fill_truth(char *path, char **labels, int k, float *truth)
{
    int i;
    memset(truth, 0, k*sizeof(float));
    int count = 0;
    for(i = 0; i < k; ++i){
        if(strstr(path, labels[i])){
            truth[i] = 1;
            ++count;
            //printf("%s %s %d\n", path, labels[i], i);
        }
    }
    if(count != 1 && (k != 1 || count != 0)) printf("Too many or too few labels: %d, %s\n", count, path);
}

https://github.com/pjreddie/darknet/blob/master/src/data.c#L620 https://github.com/pjreddie/darknet/blob/master/src/data.c#L543