博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
yolo训练精简版
阅读量:4074 次
发布时间:2019-05-25

本文共 3828 字,大约阅读时间需要 12 分钟。

在darknet版的yoloV4中。data文件中train.txt中只提供了图像的路径,那标签文件是怎么对应读取的呢?

在源码中,找到下面这个函数可以看到:

void replace_image_to_label(const char* input_path, char* output_path){
find_replace(input_path, "/images/train2014/", "/labels/train2014/", output_path); // COCO find_replace(output_path, "/images/val2014/", "/labels/val2014/", output_path); // COCO find_replace(output_path, "/JPEGImages/", "/labels/", output_path); // PascalVOC find_replace(output_path, "\\images\\train2014\\", "\\labels\\train2014\\", output_path); // COCO find_replace(output_path, "\\images\\val2014\\", "\\labels\\val2014\\", output_path); // COCO find_replace(output_path, "\\JPEGImages\\", "\\labels\\", output_path); // PascalVOC //find_replace(output_path, "/images/", "/labels/", output_path); // COCO //find_replace(output_path, "/VOC2007/JPEGImages/", "/VOC2007/labels/", output_path); // PascalVOC //find_replace(output_path, "/VOC2012/JPEGImages/", "/VOC2012/labels/", output_path); // PascalVOC //find_replace(output_path, "/raw/", "/labels/", output_path); trim(output_path); // replace only ext of files find_replace_extension(output_path, ".jpg", ".txt", output_path); find_replace_extension(output_path, ".JPG", ".txt", output_path); // error find_replace_extension(output_path, ".jpeg", ".txt", output_path); find_replace_extension(output_path, ".JPEG", ".txt", output_path); find_replace_extension(output_path, ".png", ".txt", output_path); find_replace_extension(output_path, ".PNG", ".txt", output_path); find_replace_extension(output_path, ".bmp", ".txt", output_path); find_replace_extension(output_path, ".BMP", ".txt", output_path); find_replace_extension(output_path, ".ppm", ".txt", output_path); find_replace_extension(output_path, ".PPM", ".txt", output_path); find_replace_extension(output_path, ".tiff", ".txt", output_path); find_replace_extension(output_path, ".TIFF", ".txt", output_path); // Check file ends with txt: if(strlen(output_path) > 4) {
char *output_path_ext = output_path + strlen(output_path) - 4; if( strcmp(".txt", output_path_ext) != 0){
fprintf(stderr, "Failed to infer label file name (check image extension is supported): %s \n", output_path); } }else{
fprintf(stderr, "Label file name is too short: %s \n", output_path); }}

以PascalVOC数据集为例,程序会自动把图像路径中的/JPEGImages/ 替换为 /labels/

然后把文件扩展名替换为txt 就得到对应的标签文件路径了

所以我们在任一路径下可以新建两个文件夹

-JPEGImages   #放入所有的训练图片文件-labels   #放入所有的txt文件,会自动生成此文件夹
后来想想,只要得到图像的全路径就可以,文件夹都不用创建,标签文件也不用分开,直接放在一个文件夹,执行下面的程序,会自动给你划分出训练集和验证集,更简单!

执行下面的Python程序

import os# iter floderdef iter_files(rootDir, extend_name):    file_list = []    fileName = []    #Iterate over the roots    for root,dirs,files in os.walk(rootDir):        for file_name in files:            root = os.path.normpath(root) #格式化路径 斜杠问题  / -> \            file_path = os.path.join(root, file_name)  # 连接路径            file_path = file_path.replace("\\", "/")            flag = file_path.endswith(extend_name)            if flag:                file_list.append(file_path)                fileName.append(os.path.splitext(file_name)[0])    return file_list, fileName# split train and valdef  split_train_val(fileList):    trainFile = open('train.txt', 'a')    validFile = open('val.txt', 'a')    num = 0    for files in fileList:        num = num + 1        if num % 4 == 0:            validFile.write(files + '\n')        else:            trainFile.write(files + '\n')    trainFile.close()    validFile.close()if __name__ == '__main__':    root = 'D:/Python/images/JEPGImages'  #训练图像的路径    [fileList, fileName] = iter_files(root, 'png')    split_train_val(fileList)

这样我们就直接得到了训练集和验证集的txt文件,前提是你直接有txt格式的标注文件,不是xml的。不然还是需要之前的那篇教程。

后面就简简单单改几个地方,就能训练起来了!

在这里插入图片描述

转载地址:http://rxwni.baihongyu.com/

你可能感兴趣的文章
19. Remove Nth Node From End of List (双指针)
查看>>
49. Group Anagrams (String, Map)
查看>>
139. Word Break (DP)
查看>>
Tensorflow入门资料
查看>>
剑指_用两个栈实现队列
查看>>
剑指_顺时针打印矩阵
查看>>
剑指_栈的压入弹出序列
查看>>
剑指_复杂链表的复制
查看>>
服务器普通用户(非管理员账户)在自己目录下安装TensorFlow
查看>>
星环后台研发实习面经
查看>>
大数相乘不能用自带大数类型
查看>>
字节跳动后端开发一面
查看>>
CentOS Tensorflow 基础环境配置
查看>>
centOS7安装FTP
查看>>
FTP的命令
查看>>
CentOS操作系统下安装yum的方法
查看>>
ping 报name or service not known
查看>>
FTP 常见问题
查看>>
zookeeper单机集群安装
查看>>
do_generic_file_read()函数
查看>>