目录
1. 下载
https://pjreddie.com/media/files/cifar.tgz
2. 解压
3. 代码处理
import os
if __name__ == '__main__':
data_path = r"E:\code\c++\darknet-master\data\cifar"
dir_name_list = os.listdir(data_path)
for dir_name in dir_name_list: # train / test
dir_full_str = os.path.join(data_path, dir_name)
if os.path.isdir(dir_full_str):
list_file_path = os.path.join(data_path, "{}.list".format(dir_name)) # train.list / test.list
fd = open(list_file_path, "w", encoding="utf-8")
# read image name
img_name_list = os.listdir(dir_full_str)
for img_name in img_name_list:
# cur_img_relative_path = "{}/{}\n".format(dir_name, img_name) # relative path
cur_img_abstract_path = "{}\{}\n".format(dir_full_str, img_name) # abstract path
fd.write(cur_img_abstract_path)
fd.close()
4.处理后格式
train.list内容,指明图片路径。
再创建一个数据集说明文件:cifar.data
cifar.data内容如下
classes=10
train = E:\code\c++\darknet-master\data/cifar/train.list
valid = E:\code\c++\darknet-master\data/cifar/test.list
labels = E:\code\c++\darknet-master\data/cifar/labels.txt
backup = backup/
top=2
5. 开启训练
命令行开启训练,这里的darknet.exe是之前编译生成的。
darknet.exe classifier train 数据集说明文件路径 网络配置说明文件
darknet.exe classifier train E:\code\c++\darknet-master\data\cifar\cifar.data E:\code\c++\darknet-master\cfg\cifar_small.cfg
默认的训练配置:
训练中:
训练结束:
6. 测试
darknet.exe classifier valid E:\code\c++\darknet-master\data\cifar\cifar.data E:\code\c++\darknet-master\cfg\cifar_small.cfg backup/cifar_small_final.weights
可以看到top1和top2分类精度都挺高的。