1 Alphapose中使用yolov3-tiny检测器的应用场景

Alphapose的官方仓库中默认使用的是yolov3-spp,根据官网公布的数据,其mAP为60.6,FPS能到20FPS。但是如果我们面临的是一个不复杂的场景,场景中人数较少,而我们有需要其性能够好,实时性能达到应用的要求或者更好,那我们为什么不使用yolov3-tiny检测器,由于简化了网络结构,根据官网的公布的数据,其FPS能达到220FPS,而mAP也有33.1,对于普通场景这种精度完全够用。

Alphapose – 在Alphapose中使用yolov3-tiny检测器大幅提升检测性能-StubbornHuang Blog

2 在Alphapose中使用yolov3-tiny

2.1 下载yolov3-tiny的权重和配置文件

官网地址:https://pjreddie.com/darknet/yolo/

在官网分别下载weights和cfg文件

Alphapose – 在Alphapose中使用yolov3-tiny检测器大幅提升检测性能-StubbornHuang Blog

将权重文件yolov3-tiny.weights放置到Alphapose的AlphaPose\detector\yolo\data文件夹下;
将配置文件yolov3-tiny.cfg放置到Alphapose的AlphaPose\detector\yolo\cfg文件夹下;

2.2 修改Alphapose的yolo_cfg文件

将AlphaPose\detector\yolo_cfg.py文件中的:

cfg.CONFIG = 'detector/yolo/cfg/yolov3-spp.cfg'
cfg.WEIGHTS = 'detector/yolo/data/yolov3-spp.weights'

修改为

cfg.CONFIG = 'detector/yolo/cfg/yolov3-tiny.cfg'
cfg.WEIGHTS = 'detector/yolo/data/yolov3-tiny.weights'

附上yolo_cfg.py的全部内容:

from easydict import EasyDict as edict

cfg = edict()

cfg.CONFIG = 'detector/yolo/cfg/yolov3-tiny.cfg'
cfg.WEIGHTS = 'detector/yolo/data/yolov3-tiny.weights'

cfg.INP_DIM =  320
cfg.NMS_THRES =  0.45
cfg.CONFIDENCE = 0.6
cfg.NUM_CLASSES = 80

2.3 yolov3-tiny.cfg的修改

好了,在我们进行了上述配置之后,就可以信心满满的运行Alphapose,试一试Alphapose的速度了!!!

但是,出现了以下错误:

Traceback (most recent call last):
  File "G:\ProgramData\Anaconda3\envs\Alphapose\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "G:\ProgramData\Anaconda3\envs\Alphapose\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "F:\下载目录\Github项目\Machine Learning And Deep Learning\AlphaPose\alphapose\utils\detector.py", line 223, in image_detection
    dets = self.detector.images_detection(imgs, im_dim_list)
  File "F:\下载目录\Github项目\Machine Learning And Deep Learning\AlphaPose\detector\yolo_api.py", line 99, in images_detection
    prediction = self.model(imgs, args=args)
  File "G:\ProgramData\Anaconda3\envs\Alphapose\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "F:\下载目录\Github项目\Machine Learning And Deep Learning\AlphaPose\detector\yolo\darknet.py", line 353, in forward
    x = torch.cat((map1, map2), 1)
RuntimeError: Sizes of tensors must match except in dimension 2. Got 20 and 18 (The offending index is 0)

好吧,从错误上以及调试的结果来看估计是yolov3-tiny.cfg网络结果有点问题,可是官方的配置文件为啥有问题啊!

不管了,经过我的不懈测试,终于发现了问题所在的地方,yolov3-tiny.cfg的157行:

[route]
layers = -1, 8

将其修改为:

[route]
layers = -1, 19

即可。

附上修改后的yolov3-tiny.cfg全部内容:

[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=255
activation=linear



[yolo]
mask = 3,4,5
anchors = 10,14,  23,27,  37,58,  81,82,  135,169,  344,319
classes=80
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
layers = -1, 19

[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky

[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear

[yolo]
mask = 0,1,2
anchors = 10,14,  23,27,  37,58,  81,82,  135,169,  344,319
classes=80
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1

修改完之后,就放肆跑吧!!!速度有很大提升!

如果您觉得对您有帮助,可以请站长喝一杯咖啡哦!

记得在赞赏备注里写上您的昵称

您可在本站资助名单中查看你的打赏记录哦!

支付宝扫一扫

微信扫一扫

金额随意,礼清义重

当前分类随机文章推荐

全站随机文章推荐

关于本站站长 StubbornHuang
Alphapose – 在Alphapose中使用yolov3-tiny检测器大幅提升检测性能-StubbornHuang Blog纵使晴明无雨色,入云深处亦沾衣。