DarkNet - 没有检测到自定义训练数据
DarkNet - Nothing is detected for the custom training data
我创建了自己的数据集,这是一组足球图像。由于我只有 1 个 class,我将 ball-yolov3-tiny.cfg
修改为将 filters
设置为 18
,将 classes
设置为 1
。
然后我对图像进行了注释,并将创建的 .txt
个文件放入图像的同一目录中。最后,我通过执行命令 darknet detector train custom/ball-obj.data custom/ball-yolov3-tiny.cfg darknet53.conv.74
.
使用 darknet53.conv.74
模型开始训练
我有 134 张图像用于训练,15 张图像用于测试。这是训练过程的示例输出:
95: 670.797241, 597.741333 avg, 0.000000 rate, 313.254830 seconds, 6080 images
Loaded: 0.000302 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499381, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.496005, No Obj: 0.496541, .5R: 0.000000, .75R: 0.000000, count: 32
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499381, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.496005, No Obj: 0.496541, .5R: 0.000000, .75R: 0.000000, count: 32
96: 670.557190, 605.022949 avg, 0.000000 rate, 312.962750 seconds, 6144 images
Loaded: 0.000272 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499360, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.495868, No Obj: 0.496454, .5R: 0.000000, .75R: 0.000000, count: 32
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499360, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.495868, No Obj: 0.496454, .5R: 0.000000, .75R: 0.000000, count: 32
97: 670.165161, 611.537170 avg, 0.000000 rate, 312.681998 seconds, 6208 images
Loaded: 0.000282 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499331, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.495722, No Obj: 0.496397, .5R: 0.000000, .75R: 0.000000, count: 32
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499331, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.495722, No Obj: 0.496397, .5R: 0.000000, .75R: 0.000000, count: 32
98: 669.815918, 617.365051 avg, 0.000000 rate, 319.203044 seconds, 6272 images
Loaded: 0.000244 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499294, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344947, Class: 0.498204, Obj: 0.495569, No Obj: 0.496253, .5R: 0.000000, .75R: 0.000000, count: 32
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499294, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344947, Class: 0.498204, Obj: 0.495569, No Obj: 0.496253, .5R: 0.000000, .75R: 0.000000, count: 32
99: 669.555664, 622.584106 avg, 0.000000 rate, 320.330266 seconds, 6336 images
Loaded: 0.000244 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499246, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344948, Class: 0.498204, Obj: 0.495409, No Obj: 0.496197, .5R: 0.000000, .75R: 0.000000, count: 32
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499246, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344948, Class: 0.498204, Obj: 0.495409, No Obj: 0.496197, .5R: 0.000000, .75R: 0.000000, count: 32
100: 669.132629, 627.238953 avg, 0.000000 rate, 329.954091 seconds, 6400 images
Saving weights to backup//ball-yolov3-tiny.backup
Saving weights to backup//ball-yolov3-tiny_100.weights
Resizing
576
Loaded: 1.764142 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499216, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.430712, Class: 0.498203, Obj: 0.495251, No Obj: 0.496154, .5R: 0.000000, .75R: 0.000000, count: 32
其他配置文件如下:
球-obj.data
classes= 1
train = custom/ball-train.txt
valid = custom/ball-test.txt
names = custom/ball-obj.names
backup = backup/
球-obj.names
ball
当我使用创建的权重来测试单个图像时,它根本无法在图像中找到足球。为此我需要更多(例如 10K)图像吗?或者我需要长时间训练模型吗?我只是想确保我的设置一切正常。
请随时询问有关我的实验的任何问题。非常感谢您的帮助。提前致谢。
p.s。这是我的 ball-yolov3-tiny.cnf
:
的全部内容
[net]
# Testing
batch=1
subdivisions=1
# Training
#batch=64
#subdivisions=2
width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=16
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=1
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
###########
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=18
activation=linear
[yolo]
mask = 3,4,5
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=1
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 8
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=18
activation=linear
[yolo]
mask = 0,1,2
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=1
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
我执行的命令是:
darknet detector train custom/ball-obj.data custom/ball-yolov3-tiny.cfg darknet53.conv.74
- 你的数据集很小,我认为 15 张用于测试的图像太小了。
batch=1 subdivisions=1
表示你每1次迭代只训练1张图片,如果你有足够的GPU,你可以尝试增加数量让你的模型收敛得更好
- 您的模型不好的最明显原因是
100: 669.132629, 627.238953 avg
。您可以看到平均损失是 627.238953,这太大了。好的 YOLO 模型损失在 0.06~1 左右。
所以你可以根据我上面的观点做的事情是继续训练(100次迭代是不够的,尤其是Tiny YOLO),增加批次和细分,增加你的数据集。
Addition : 使用你的数据集重新计算锚框也是一个不错的选择,你可以在互联网上找到很多很好的例子和代码。
将批量大小增加到 64,并使用尽可能少的细分,因为您的 GPU 内存可以容纳:从 1、2、4、8、16、32 开始,如果您继续让 CUDA 内存不足,最后是 64。
您应该训练您的网络,直到您的平均损失率 < 1。
您使用的是 Joseph Redmons 存储库中的原始版本的 darknet,还是您使用的是 fork?有一系列关于如何改进对象检测的建议 here,但是,我不确定它们是否适用于所有其他版本。
max_batches= (# of classes)* 2000
max_batches = 6000
如果你训练 1,2,3 类 它将是 6000
和
Steps=(80% of max_batches),(90% of max_batches) i.e,
steps=4800,5400
我创建了自己的数据集,这是一组足球图像。由于我只有 1 个 class,我将 ball-yolov3-tiny.cfg
修改为将 filters
设置为 18
,将 classes
设置为 1
。
然后我对图像进行了注释,并将创建的 .txt
个文件放入图像的同一目录中。最后,我通过执行命令 darknet detector train custom/ball-obj.data custom/ball-yolov3-tiny.cfg darknet53.conv.74
.
darknet53.conv.74
模型开始训练
我有 134 张图像用于训练,15 张图像用于测试。这是训练过程的示例输出:
95: 670.797241, 597.741333 avg, 0.000000 rate, 313.254830 seconds, 6080 images
Loaded: 0.000302 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499381, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.496005, No Obj: 0.496541, .5R: 0.000000, .75R: 0.000000, count: 32
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499381, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.496005, No Obj: 0.496541, .5R: 0.000000, .75R: 0.000000, count: 32
96: 670.557190, 605.022949 avg, 0.000000 rate, 312.962750 seconds, 6144 images
Loaded: 0.000272 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499360, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.495868, No Obj: 0.496454, .5R: 0.000000, .75R: 0.000000, count: 32
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499360, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.495868, No Obj: 0.496454, .5R: 0.000000, .75R: 0.000000, count: 32
97: 670.165161, 611.537170 avg, 0.000000 rate, 312.681998 seconds, 6208 images
Loaded: 0.000282 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499331, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.495722, No Obj: 0.496397, .5R: 0.000000, .75R: 0.000000, count: 32
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499331, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344946, Class: 0.498204, Obj: 0.495722, No Obj: 0.496397, .5R: 0.000000, .75R: 0.000000, count: 32
98: 669.815918, 617.365051 avg, 0.000000 rate, 319.203044 seconds, 6272 images
Loaded: 0.000244 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499294, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344947, Class: 0.498204, Obj: 0.495569, No Obj: 0.496253, .5R: 0.000000, .75R: 0.000000, count: 32
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499294, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344947, Class: 0.498204, Obj: 0.495569, No Obj: 0.496253, .5R: 0.000000, .75R: 0.000000, count: 32
99: 669.555664, 622.584106 avg, 0.000000 rate, 320.330266 seconds, 6336 images
Loaded: 0.000244 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499246, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344948, Class: 0.498204, Obj: 0.495409, No Obj: 0.496197, .5R: 0.000000, .75R: 0.000000, count: 32
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499246, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.344948, Class: 0.498204, Obj: 0.495409, No Obj: 0.496197, .5R: 0.000000, .75R: 0.000000, count: 32
100: 669.132629, 627.238953 avg, 0.000000 rate, 329.954091 seconds, 6400 images
Saving weights to backup//ball-yolov3-tiny.backup
Saving weights to backup//ball-yolov3-tiny_100.weights
Resizing
576
Loaded: 1.764142 seconds
Region 16 Avg IOU: -nan, Class: -nan, Obj: -nan, No Obj: 0.499216, .5R: -nan, .75R: -nan, count: 0
Region 23 Avg IOU: 0.430712, Class: 0.498203, Obj: 0.495251, No Obj: 0.496154, .5R: 0.000000, .75R: 0.000000, count: 32
其他配置文件如下:
球-obj.data
classes= 1
train = custom/ball-train.txt
valid = custom/ball-test.txt
names = custom/ball-obj.names
backup = backup/
球-obj.names
ball
当我使用创建的权重来测试单个图像时,它根本无法在图像中找到足球。为此我需要更多(例如 10K)图像吗?或者我需要长时间训练模型吗?我只是想确保我的设置一切正常。
请随时询问有关我的实验的任何问题。非常感谢您的帮助。提前致谢。
p.s。这是我的 ball-yolov3-tiny.cnf
:
[net]
# Testing
batch=1
subdivisions=1
# Training
#batch=64
#subdivisions=2
width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=16
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=1
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
###########
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=18
activation=linear
[yolo]
mask = 3,4,5
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=1
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 8
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=18
activation=linear
[yolo]
mask = 0,1,2
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=1
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
我执行的命令是:
darknet detector train custom/ball-obj.data custom/ball-yolov3-tiny.cfg darknet53.conv.74
- 你的数据集很小,我认为 15 张用于测试的图像太小了。
batch=1 subdivisions=1
表示你每1次迭代只训练1张图片,如果你有足够的GPU,你可以尝试增加数量让你的模型收敛得更好- 您的模型不好的最明显原因是
100: 669.132629, 627.238953 avg
。您可以看到平均损失是 627.238953,这太大了。好的 YOLO 模型损失在 0.06~1 左右。
所以你可以根据我上面的观点做的事情是继续训练(100次迭代是不够的,尤其是Tiny YOLO),增加批次和细分,增加你的数据集。
Addition : 使用你的数据集重新计算锚框也是一个不错的选择,你可以在互联网上找到很多很好的例子和代码。
将批量大小增加到 64,并使用尽可能少的细分,因为您的 GPU 内存可以容纳:从 1、2、4、8、16、32 开始,如果您继续让 CUDA 内存不足,最后是 64。
您应该训练您的网络,直到您的平均损失率 < 1。
您使用的是 Joseph Redmons 存储库中的原始版本的 darknet,还是您使用的是 fork?有一系列关于如何改进对象检测的建议 here,但是,我不确定它们是否适用于所有其他版本。
max_batches= (# of classes)* 2000
max_batches = 6000
如果你训练 1,2,3 类 它将是 6000
和
Steps=(80% of max_batches),(90% of max_batches) i.e,
steps=4800,5400