Giter Club home page Giter Club logo

keras-yolov4's Introduction

PPYOLO AND YOLOv4

概述

PP-YOLO是PaddleDetection优化和改进的YOLOv3的模型,其精度(COCO数据集mAP)和推理速度均优于YOLOv4模型。

2020/11/05:经过不懈努力,咩酱终于在Keras上实现了可变形卷积DCNv2!这应该是咩酱最自豪的工作了。之前的种种算法(如CenterNet)因为使用了可变形卷积,而Keras、tensorflow官方没有实现可变形卷积,使得这些算法无缘在Keras平台大显身手。 而咩酱不才,一直都无法实现这一算法。经过差不多两年对算法的学习,对深度学习框架的理解,这次我再次挑战实现可变形卷积,终于大获全胜! 值得一提的是这次的DCNv2并不需要读者编译什么c、c++、cuda、自定义op这些玩意!因为这是用tensorflow的纯python接口实现,效率极高,是咩酱的得意之作! 带有DCNv2的PPYOLO,速度超过了不带有DCNv2的YOLOv4,咩酱也亲自与Pytorch版的PPYOLO(https://github.com/miemie2013/Pytorch-PPYOLO )测过FPS,速度持平,可见实现的DCNv2效率极高。 其实一开始我并不想干这么费脑子的事情,但是抬头不见低头见,多造轮子其实是件好事,自己就会得到锻炼。下面我们来一览PPYOLO与YOLOv4的神采吧:

算法 骨干网络 图片输入大小 mAP(COCO val2017) mAP(COCO test2017) FPS
YOLOv4 CSPDarkNet53 (608,608) 0.491 0.420 10.3
PPYOLO ResNet50-vd (608,608) 0.448 0.451 11.9
PPYOLO_r18vd ResNet18-vd (608,608) 0.286 - 33.7
PPYOLO_r18vd ResNet18-vd (416,416) 0.286 - 50.8
PPYOLO_r18vd ResNet18-vd (320,320) 0.262 - 65.0

注意:

  • 测速环境为: win10, i5-9400F, 8GB RAM, GTX1660Ti(6GB), cuda9, tensorflow-gpu==1.12.2。若使用Linux系统FPS还能再提高。
  • FPS由demo.py测得。预测50张图片,预测之前会有一个热身(warm up)阶段使速度稳定。
  • 由于原版YOLOv4使用coco trainval2014进行训练,训练样本中包含部分评估样本,若使用val2017集会导致精度虚高。所以表中的0.491的精度并不可信。
  • PPYOLO使用了matrix_nms进行后处理,本仓库的YOLOv4亦使用了matrix_nms进行后处理。matrix_nms拥有和fast_nms一样的速度,mAP却比后者高。
  • PPYOLO_r18vd(416,416) mAP(IoU=0.50)(COCO val2017)为0.470,表中的0.286指的是mAP(IoU=0.50:0.95)(COCO val2017)。
  • PPYOLO_r18vd(608,608) mAP(IoU=0.50)(COCO val2017)为0.478。不建议使用608x608输入大小。
  • PPYOLO_r18vd(320,320) mAP(IoU=0.50)(COCO val2017)为0.437。

yolov4_2x.h5在val2017下的mAP:

Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.491
Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.720
Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.546
Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.331
Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.554
Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.610
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.357
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.599
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.650
Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.450
Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.719
Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.803

ppyolo_2x.h5在val2017下的mAP:

Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.448
Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.649
Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.492
Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.265
Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.483
Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.593
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.337
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.571
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.624
Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.420
Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.665
Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.773

yolov4_2x.h5在test2017下的mAP:

Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.420
Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.624
Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.464
Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.245
Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.457
Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.525
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.330
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.546
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.595
Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.369
Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.648
Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.755

ppyolo_2x.h5在test2017下的mAP:

Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.451
Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.655
Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.498
Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.265
Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.475
Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.573
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.343
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.578
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.630
Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.424
Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.659
Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.787

已实现的部分

EMA(指数滑动平均):修改config/ppyolo_2x.py中self.use_ema = True打开。修改config/ppyolo_2x.py中self.use_ema = False关闭。打开ema会拖慢训练速度。咩酱暂时想不到好办法优化这一部分。

DropBlock:随机丢弃特征图上的像素。

IoU Loss:iou损失。

IoU Aware:预测预测框和gt的iou。并作用在objness上。

Grid Sensitive:预测框中心点的xy可以出到网格之外,应付gt中心点在网格线上这种情况。

Matrix NMS:SOLOv2中提出的算法,在soft-nms等基础上进行并行化加速,若预测框与同类高分框有iou,减小预测框的分数而不是直接丢弃。这里用box iou代替mask iou。

CoordConv:特征图带上像素的坐标信息(通道数+2)。

SPP:3个池化层的输出和原图拼接。

未实现的部分

多卡训练(由于咩酱只有一张6G的卡,也不是硕士生没有实验室,这部分可能不会实现)。

L2权重衰减、学习率warm up和学习率分段衰减。这些在Pytorch版和Paddle版PPYOLO中都已经实现了:

https://github.com/miemie2013/Pytorch-PPYOLO

https://github.com/miemie2013/Paddle-PPYOLO

咩酱刷屏时刻

Keras版YOLOv3: https://github.com/miemie2013/Keras-DIOU-YOLOv3

Pytorch版YOLOv3:https://github.com/miemie2013/Pytorch-DIOU-YOLOv3

PaddlePaddle版YOLOv3:https://github.com/miemie2013/Paddle-DIOU-YOLOv3

PaddlePaddle完美复刻版版yolact: https://github.com/miemie2013/PaddlePaddle_yolact

Keras版YOLOv4: https://github.com/miemie2013/Keras-YOLOv4 (mAP 41%+)

Pytorch版YOLOv4: https://github.com/miemie2013/Pytorch-YOLOv4 (mAP 41%+)

Paddle版YOLOv4:https://github.com/miemie2013/Paddle-YOLOv4 (mAP 41%+)

PaddleDetection版SOLOv2: https://github.com/miemie2013/PaddleDetection-SOLOv2

Pytorch实时版FCOS,跑得比YOLOv4快: https://github.com/miemie2013/Pytorch-FCOS

Paddle实时版FCOS,跑得比YOLOv4快: https://github.com/miemie2013/Paddle-FCOS

Keras版CartoonGAN: https://github.com/miemie2013/keras_CartoonGAN

纯python实现一个深度学习框架: https://github.com/miemie2013/Pure_Python_Deep_Learning

Pytorch版PPYOLO: https://github.com/miemie2013/Pytorch-PPYOLO (mAP 44.8%)

更新日记

2020/11/05:初次见面

未来工作

加入轻量级模型,如PP-YOLO_r18vd、PP-YOLO-tiny模型。

快速开始

(1)环境搭建

需要安装cuda9,其余见requirements.txt。

(2)下载预训练模型

下载yolov4.pt 链接:https://pan.baidu.com/s/152poRrQW9Na_C8rkhNEh3g 提取码:09ou

将它放在项目根目录下。然后运行1_yolov4_2x_2keras.py得到一个yolov4_2x.h5,它也位于根目录下。

下载PaddleDetection的ppyolo.pdparams。如果你使用Linux,请使用以下命令:

wget https://paddlemodels.bj.bcebos.com/object_detection/ppyolo.pdparams

如果你使用Windows,请复制以下网址到浏览器或迅雷下载:

https://paddlemodels.bj.bcebos.com/object_detection/ppyolo.pdparams

下载好后将它放在项目根目录下。然后运行1_ppyolo_2x_2keras.py得到一个ppyolo_2x.h5,它也位于根目录下。

下载PaddleDetection的ppyolo_r18vd.pdparams。如果你使用Linux,请使用以下命令:

wget https://paddlemodels.bj.bcebos.com/object_detection/ppyolo_r18vd.pdparams

如果你使用Windows,请复制以下网址到浏览器或迅雷下载:

https://paddlemodels.bj.bcebos.com/object_detection/ppyolo_r18vd.pdparams

下载好后将它放在项目根目录下。然后运行1_ppyolo_r18vd_2keras.py得到一个ppyolo_r18vd.h5,它也位于根目录下。

(3)预测图片、获取FPS(预测images/test/里的图片,结果保存在images/res/)

(如果使用yolov4_2x.py配置文件)

python demo.py --config=0

(如果使用ppyolo_2x.py配置文件)

python demo.py --config=1

(如果使用ppyolo_r18vd.py配置文件)

python demo.py --config=2

数据集的放置位置

数据集应该和本项目位于同一级目录。一个示例:

D://GitHub
     |------COCO
     |        |------annotations
     |        |------test2017
     |        |------train2017
     |        |------val2017
     |
     |------VOCdevkit
     |        |------VOC2007
     |        |        |------Annotations
     |        |        |------ImageSets
     |        |        |------JPEGImages
     |        |        |------SegmentationClass
     |        |        |------SegmentationObject
     |        |
     |        |------VOC2012
     |                 |------Annotations
     |                 |------ImageSets
     |                 |------JPEGImages
     |                 |------SegmentationClass
     |                 |------SegmentationObject
     |
     |------Keras-YOLOv4-master
              |------annotation
              |------config
              |------data
              |------model
              |------...

训练

(如果使用yolov4_2x.py配置文件)

python train.py --config=0

(如果使用ppyolo_2x.py配置文件)

python train.py --config=1

通过修改config/xxxxxxx.py的代码来进行更换数据集、更改超参数以及训练参数。

训练时如果发现mAP很稳定了,就停掉,修改学习率为原来的十分之一,接着继续训练,mAP还会再上升。暂时是这样手动操作。

训练自定义数据集

自带的voc2012数据集是一个很好的例子。

将自己数据集的txt注解文件放到annotation目录下,txt注解文件的格式如下:

xxx.jpg 18.19,6.32,424.13,421.83,20 323.86,2.65,640.0,421.94,20
xxx.jpg 48,240,195,371,11 8,12,352,498,14
# 图片名 物体1左上角x坐标,物体1左上角y坐标,物体1右下角x坐标,物体1右下角y坐标,物体1类别id 物体2左上角x坐标,物体2左上角y坐标,物体2右下角x坐标,物体2右下角y坐标,物体2类别id ...

注意:xxx.jpg仅仅是文件名而不是文件的路径!xxx.jpg仅仅是文件名而不是文件的路径!xxx.jpg仅仅是文件名而不是文件的路径!

运行1_txt2json.py会在annotation_json目录下生成两个coco注解风格的json注解文件,这是train.py支持的注解文件格式。 在config/xxxxxxx.py里修改train_path、val_path、classes_path、train_pre_path、val_pre_path、num_classes这6个变量(自带的voc2012数据集直接解除注释就ok了),就可以开始训练自己的数据集了。 如果需要跑demo.py、eval.py,与数据集有关的变量也需要修改一下,应该很容易看懂。

评估

(如果使用yolov4_2x.py配置文件)

python eval.py --config=0

(如果使用ppyolo_2x.py配置文件)

python eval.py --config=1

test-dev

(如果使用yolov4_2x.py配置文件)

python test_dev.py --config=0

(如果使用ppyolo_2x.py配置文件)

python test_dev.py --config=1

运行完之后,进入results目录,把bbox_detections.json压缩成bbox_detections.zip,提交到 https://competitions.codalab.org/competitions/20794#participate 获得bbox mAP。该mAP是test集的结果,也就是大部分检测算法论文的标准指标。

预测

(如果使用yolov4_2x.py配置文件)

python demo.py --config=0

(如果使用ppyolo_2x.py配置文件)

python demo.py --config=1

预测视频

(如果使用yolov4_2x.py配置文件)

python demo_video.py --config=0

(如果使用ppyolo_2x.py配置文件)

python demo_video.py --config=1

(按esc键停止播放)

传送门

cv算法交流q群:645796480 但是关于仓库的疑问尽量在Issues上提,避免重复解答。

本人微信公众号:miemie_2013

技术博客:https://blog.csdn.net/qq_27311165

AIStudio主页:asasasaaawws

欢迎在GitHub或AIStudio上关注我(求粉)~

打赏

如果你觉得这个仓库对你很有帮助,可以给我打钱↓ Example 0

咩酱爱你哟!另外,有偿接私活,可联系微信wer186259,金主快点来吧!

keras-yolov4's People

Contributors

miemie2013 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

keras-yolov4's Issues

Yolo4 for action(3d) input

能不能实现一个接受动作输入的yolo4, 就是一个序列图片作为输入,检查视频里人的动作的种类的yolo4. 现有的yolo4都是2d的输入,现在要输入3d的数据。

推理时的速度如何?

我用实验室服务器的单张tesla T4跑qqwwee那版keras的YOLO V3,速度才十几fps,比作者原版代码>30fps的速度慢很多
我看了下YOLO V4 的网络层比起YOLO V3更多更复杂,加入了很多tricks,输入还从416变成608,这样速度还能增加吗?
请问你实现的这版keras的YOLO V4,在你的环境下,推理速度能达到多少呢?能达到相同环境下作者原代码速度的多少?

Using keras custom trained model In video?

Hi, I am a noob in computer vision. I was able to follow the author and train my custom dataset in yolov4 Keras. The final map value is great and its accuracy in images is great as well. But how to apply detection in video files?
Can anyone provide me some insight?

单机多卡应该怎么操作

model = keras.models.Model([model_body.input, *y_true], loss_list) parallel_model = multi_gpu_model(model, 2)
添加了multi_gpu_model,将后面所有model换成parallel_model,在保存模型的时候用model.save,但是不起作用,还是只是一张卡

关于anchor 的设置?

我的数据集中目标普遍偏小,是用默认的anchor,还是自己用kmeans从新聚类?

聚类出来的结果是[11, 24],[12, 11], [15, 23], [16, 40], [25 , 16][28, 58],[44, 24], [59,113], [102, 44]

目前我是使用了聚类的结果,但是效果很差。
所以想请教你一下

多线程调用模型进行测试

ValueError: Tensor Tensor("lambda_1/map/TensorArrayStack/TensorArrayGatherV3:0", shape=(?, ?, 6), dtype=float32) is not an element of this graph.

当我使用一下代码进行测试的时候出现这个错误,
hat_cfg = PPYOLO_2x_Config()
hat_detector = PPYOLO_2x_Hat(hat_cfg, use_gpu=True)
video_path = cfg.video_path

def main():
# ----------------------------------------视频处理------------------------------------------
cap = cv2.VideoCapture(video_path)
print('load ' + video_path)
print('---------------------------')
index = 0
while True:
print(index)
ret, frame = cap.read()
if not ret:
break
if index % cfg.sample_interval != 0:
index += 1
continue
_, hat_output_box = hat_detector.detect_image(frame) # 安全帽检测
print(hat_output_box)
index+=1

if name == 'main':
for i in range(3):
threading.Thread(target=main).start()

Loss error

loading annotations into memory...
Done (t=0.02s)
creating index...
index created!
2020-08-03 10:24:10,579-INFO: 2501 samples in train set.
WARNING:tensorflow:Output yolo_loss_1 missing from loss dictionary. We assume this was done on purpose. The fit and evaluate APIs will not be expecting any data to be passed to yolo_loss_1.
2020-08-03 10:24:10,604-WARNING: Output yolo_loss_1 missing from loss dictionary. We assume this was done on purpose. The fit and evaluate APIs will not be expecting any data to be passed to yolo_loss_1.
WARNING:tensorflow:Output yolo_loss_2 missing from loss dictionary. We assume this was done on purpose. The fit and evaluate APIs will not be expecting any data to be passed to yolo_loss_2.
2020-08-03 10:24:10,604-WARNING: Output yolo_loss_2 missing from loss dictionary. We assume this was done on purpose. The fit and evaluate APIs will not be expecting any data to be passed to yolo_loss_2.
Traceback (most recent call last):
File "C:\Users\AI Lord.conda\envs\pytorch_lib\lib\site-packages\tensorflow_core\python\framework\ops.py", line 1619, in _create_c_op
c_op = c_api.TF_FinishOperation(op_desc)
tensorflow.python.framework.errors_impl.InvalidArgumentError: slice index -1 of dimension 0 out of bounds. for 'loss/yolo_loss_loss/strided_slice' (op: 'StridedSlice') with input shapes: [0], [1], [1], [1] and with computed input tensors: input[1] = <-1>, input[2] = <0>, input[3] = <1>.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "F:/Yolov4_资料/yolov4_test/train.py", line 360, in
model.compile(loss={'yolo_loss': lambda y_true, y_pred: y_pred}, optimizer=Adam(lr=cfg.lr))

请问这个错误怎么解决?不是很明白. 谢谢

训练只使用cpu

请问有遇到训练自己的数据没有调用gpu的情况吗,我自训练结果在使用cpu。没有自动去使用gpu

MemoryError

2020-06-21 20:08:35,249-INFO: Test iter 5800
loading annotations into memory...
Done (t=0.06s)
creating index...
index created!
2020-06-21 20:09:15,991-INFO: Generating json file...
Traceback (most recent call last):
File "eval.py", line 72, in
box_ap = eval(_decode, images, eval_pre_path, anno_file, eval_batch_size, _clsid2catid, draw_image)
File "E:\chongqingchuyuxiangmu\Keras-YOLOv4\tools\cocotools.py", line 167, in eval
box_ap_stats = bbox_eval(anno_file)
File "E:\chongqingchuyuxiangmu\Keras-YOLOv4\tools\cocotools.py", line 86, in bbox_eval
for line in f:
MemoryError
运行test_dev.py正常,但运行eval.py程序之后,出现MemoryError,请问是怎么回事?

小白求问个细节问题

在yolo_model.py 里,为啥有
grid_h, grid_w, num_boxes = map(int, out.shape[1: 4])

按我的理解,out的尺寸应该是(13x13为例):[13, 13, 3, 85],如果要输出网格的长宽、bbox数量的话,那不应该是:out.shape[0:3] 吗?

anchor尺寸问题

大神,你好,请问config.py中的anchor尺寸是相对于原始图像大小(如(h,w)),还是实际进入模型的图像大小(如[608,608]呢?非常感谢

Resource exhausted

NVIDIA GEFORCE RTX 2060 6GB+cuda10.0,运行过程中会出现资源耗尽的错误,请问是什么原因呢?

tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[8,64,256,256] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
[[{{node mish_4/mul}}]]

ValueError: slice index -1 of dimension 0 out of bounds. 错误

在运行train.py时,模型能成功导入,但是yolo_loss处则出现报错,如下:

Traceback (most recent call last):
File "train.py", line 370, in
model.compile(loss={"yolo_loss": lambda y_true, y_pred: y_pred}, optimizer=keras.optimizers.Adam(lr=cfg.lr))
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/base.py", line 457, in _method_wrapper
result = method(self, *args, **kwargs)
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 446, in compile
self._compile_weights_loss_and_weighted_metrics()
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/base.py", line 457, in _method_wrapper
result = method(self, *args, **kwargs)
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 1592, in _compile_weights_loss_and_weighted_metrics
self.total_loss = self._prepare_total_loss(masks)
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 1652, in _prepare_total_loss
per_sample_losses = loss_fn.call(y_true, y_pred)
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/keras/losses.py", line 220, in call
y_pred, y_true)
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/ops/losses/util.py", line 79, in squeeze_or_expand_dimensions
is_last_dim_1 = math_ops.equal(1, array_ops.shape(y_pred)[-1])
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/ops/array_ops.py", line 898, in _slice_helper
name=name)
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/ops/array_ops.py", line 1064, in strided_slice
shrink_axis_mask=shrink_axis_mask)
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/ops/gen_array_ops.py", line 9535, in strided_slice
shrink_axis_mask=shrink_axis_mask, name=name)
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/framework/op_def_library.py", line 742, in _apply_op_helper
attrs=attr_protos, op_def=op_def)
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 3322, in _create_op_internal
op_def=op_def)
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 1786, in init
control_input_ops)
File "/home/ma-user/anaconda3/envs/TensorFlow-2.1.0/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 1622, in _create_c_op
raise ValueError(str(e))
ValueError: slice index -1 of dimension 0 out of bounds. for 'loss/yolo_loss_loss/strided_slice' (op: 'StridedSlice') with input shapes: [0], [1], [1], [1] and with computed input tensors: input[1] = <-1>, input[2] = <0>, input[3] = <1>.

使用的是自制数据集。另外,keras模块全部是使用tensorflow内的keras submodule。百度了下还是没法子。谢谢

请问是否可以将darknet-tiny-yolov4的weights文件转换成.h5?

我尝试执行convert.py转换darknet的yolov4-tiny weights,输出如下:

Weights Header:  0 2 5 [1280000]
Converting  0
Converting  1
Converting  2
Converting  3
Converting  4
Converting  5
Converting  6
Converting  7
Converting  8
Converting  9
Converting  10
Converting  11
Converting  12
Converting  13
Converting  14
Converting  15
Converting  16
Converting  17
Converting  18
Converting  19
Converting  20
Converting  21
Converting  22
Converting  23
Converting  24
Converting  25
Converting  26
Converting  27
Converting  28
Converting  29
Converting  30
Converting  31
Converting  32
Converting  33
Converting  34
Converting  35
Converting  36
Converting  37
Converting  38
Converting  39
Converting  40
Converting  41
Converting  42
Converting  43
Converting  44
Converting  45
Converting  46
Converting  47
Converting  48
Traceback (most recent call last):
  File "convert.py", line 173, in <module>
    yolo4_model = Yolo4(score, iou, anchors_path, classes_path, model_path, weights_path)
  File "convert.py", line 157, in __init__
    self.load_yolo()
  File "convert.py", line 130, in load_yolo
    buffer=weights_file.read(weights_size * 4))
TypeError: buffer is too small for requested array

模型转keras出现EOF错误?

模型转keras出现EOF错误
可否能够提供一个可执行的keras预训练模型?

并且,在从头训练时,11G 1080ti,size 608时 batch 最高只能为2 ,否则显存溢出,这是为什么?
ps:显卡运行良好

多GPU训练遇到的问题

请问这个训练可以使用多GPU训练吗?我单独GPU可以,但是多个就不行了,错误如下。不知道是我这边代码的问题还是yolo4还没有实现多GPU训练
image

如何将 yolov4_2x.h5、ppyolo_2x.h5和ppyolo_r18vd.h5权重文件保存成完整的图?

以上3个文件用netron打开看只有权重,在demo.py中加载后用 predict_model.save("yolov4_2x_all.h5") 报错如下

Traceback (most recent call last):
  File "demo.py", line 102, in <module>
    predict_model.save("yolov4_2x_all.h5"); print("###END"); time.sleep(1000)      ### error
  File "/data/zhou.zhou/project_envs/P31_jieqin/lib/python3.6/site-packages/keras/engine/network.py", line 1139, in save
    save_model(self, filepath, overwrite, include_optimizer)
  File "/data/zhou.zhou/project_envs/P31_jieqin/lib/python3.6/site-packages/keras/engine/saving.py", line 415, in save_wrapper
    save_function(obj, filepath, overwrite, *args, **kwargs)
  File "/data/zhou.zhou/project_envs/P31_jieqin/lib/python3.6/site-packages/keras/engine/saving.py", line 507, in save_model
    _serialize_model(model, h5dict, include_optimizer)
  File "/data/zhou.zhou/project_envs/P31_jieqin/lib/python3.6/site-packages/keras/engine/saving.py", line 100, in _serialize_model
    model_config['config'] = model.get_config()
  File "/data/zhou.zhou/project_envs/P31_jieqin/lib/python3.6/site-packages/keras/engine/network.py", line 937, in get_config
    return copy.deepcopy(config)
  File "/usr/local/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/local/lib/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/local/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/local/lib/python3.6/copy.py", line 215, in _deepcopy_list
    append(deepcopy(a, memo))
  File "/usr/local/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/local/lib/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/local/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/local/lib/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/local/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/local/lib/python3.6/copy.py", line 220, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "/usr/local/lib/python3.6/copy.py", line 220, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "/usr/local/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/local/lib/python3.6/copy.py", line 220, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "/usr/local/lib/python3.6/copy.py", line 220, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "/usr/local/lib/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/local/lib/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/local/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/local/lib/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/local/lib/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/local/lib/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/local/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/local/lib/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/local/lib/python3.6/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/local/lib/python3.6/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/local/lib/python3.6/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/local/lib/python3.6/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/local/lib/python3.6/copy.py", line 169, in deepcopy
    rv = reductor(4)
TypeError: can't pickle _thread.RLock objects

请问下,如何将权重保存为完整的图,谢谢!

yolo_loss的问题

在开始训练后出现了一个问题,在输出损失的时候提示
File ".\train.py", line 402, in
iter_id, losses[0], losses[0], losses[1], losses[2], losses[3], eta)
IndexError: list index out of range
查看losses的形状时,发现只是一个长度为2的数组
而yolo_loss输出的是长度为3的数组
不知道哪里出了问题,大佬可以看一下吗
(之前尝试过改成all_loss = losses[0]+losses[1]+losses[2]还是不行)

判断最佳模型的条件,以及设置停止条件

您好,我最近用您这个做了一个简单的检测箱子的模型,开始5000次保存的模型感觉效果还行,就一直训练着,现在训练到46000次,发现模型效果反而变得很差,查看日志,损失函数期间从降低一直到再次升高,但最终损失函数还是蛮小的,不知道有没有一个比较好的参考值,比如说mAP达到多少,我的任务相对简单,评测mAP大的时候有0.68的样子;后续一直训练,最终最佳模型mAP能达到0.8的样子,实际效果却很不理想了

out of memory

i have a 1060 card with 6G memory, it seems it always give me error when train it. i set up batch = 1, 416x416.

what could be wrong? any idea?

多gpu训练

不知道有没有人使用过多gpu训练并成功?我这边好像不行

能否将Resize操作写成层

想要将预处理中的Resize写成层,放在Input后面。

# 自定义Resize层
class Resizing(tf.keras.layers.Layer):
    def __init__(self, target_size, method=tf.image.ResizeMethod.BILINEAR, **kwargs):
        super().__init__(**kwargs)
        
        self.target_size = target_size
        self.method = method 
    
    def __call__(self, inputs):
        return tf.image.resize(inputs, size=self.target_size, method=self.method)
    
    def compute_output_shape(self, input_shape):
        return (self.target_size[0], self.target_size[1], input_shape[-1])

# build model
cfg = YOLOv4_2x_Config()
cfg.head["drop_block"] = False

backbone = CSPDarknet53(**cfg.backbone)
head = YOLOv4Head(yolo_loss=None, nms_cfg=cfg.nms_cfg, **cfg.head)
yolo = YOLO(backbone, head)

x = keras.layers.Input(shape=(None, None, 3), name="x", dtype="float32")
xp = Resizing(target_size=(608,608), name="resize")(x)
im_size = keras.layers.Input(shape=(2,), name="im_size", dtype="int32")
outputs = yolo.get_outputs(xp)
preds = yolo.get_prediction(outputs, im_size)

model = keras.models.Model(inputs=[x, im_size], outputs=preds)

在yolov4_head里面做拼接时,卷积得到的featuremap的size是None,x不是None,二者无法Concat
https://github.com/miemie2013/Keras-YOLOv4/blob/master/model/yolov4_head.py#169

请教下有没有什么解决思路

從新訓練model遇到問題

我在重新訓練model時遇到以下列問題:
在每5000步要eval集的mAP時遇到
Loading and preparing results...
Traceback (most recent call last):
File "train.py", line 420, in
box_ap = eval(_decode, val_images, cfg.val_pre_path, cfg.val_path, cfg.eval_batch_size, _clsid2catid, cfg.draw_image)
File "/home/Keras-YOLOv4/tools/cocotools.py", line 164, in eval
box_ap_stats = bbox_eval(anno_file)
File "/home/Keras-YOLOv4/tools/cocotools.py", line 92, in bbox_eval
map_stats = cocoapi_eval(outfile, 'bbox', coco_gt=coco_gt)
File "/home/Keras-YOLOv4/tools/cocotools.py", line 62, in cocoapi_eval
coco_dt = coco_gt.loadRes(jsonfile)
File "/usr/local/lib/python3.6/dist-packages/pycocotools/coco.py", line 326, in loadRes
if 'caption' in anns[0]:
IndexError: list index out of range

請問有人有相同問題嗎?

map

你好,我想知道作者的yolov4网络在voc2007上能达到多少,还有您的能达到多少呢

input size修改

請問我如果要修改model的input size是只要修改config.py理的input_shape就好嗎?
另外如果我想要train單通道的圖片該怎麼做修改

widerface数据集上训练了15000次,测试ap全是-1.00

Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000
2020-06-21 21:31:47,448-INFO: box ap: -1.000
2020-06-21 21:31:47,448-INFO: Best test ap: 0.0, in iter: 0
2020-06-21 21:31:54,487-INFO: Train iter: 85020, all_loss: 1.343320, ciou_loss: 0.422198, conf_loss: 0.921049, prob_loss: 0.000073, eta: 99 days, 14:04:02
2020-06-21 21:32:01,028-INFO: Train iter: 85040, all_loss: 23.520687, ciou_loss: 9.526450, conf_loss: 13.994050, prob_loss: 0.000187, eta: 2 days, 17:30:05
2020-06-21 21:32:08,001-INFO: Train iter: 85060, all_loss: 0.913662, ciou_loss: 0.542059, conf_loss: 0.371578, prob_loss: 0.000024, eta: 2 days, 20:36:34

有关于自定义coco格式数据集进行训练的问题

您好,请问一下,在tools下的cocotools.py文件中的clsid2catid和catid2clsid两个字典代表什么?
我在使用自己定义的coco标注格式的数据集进行训练时遇到以下的报错,看起来像是因为数据信息造成的。

我的环境是这样的:
操作系统 Ubuntu 18.04
gcc版本 7.5.0
tensorflow 1.14
keras 2.2.5
cuda 10.1
cudnn 7.6.5

然后,我制作的coco数据集有四类标签,catid分别是1,2,3,4。

loading annotations into memory...
Done (t=0.14s)
creating index...
index created!
Traceback (most recent call last):
File "train.py", line 248, in
train_dataset, train_img_ids, _catid2clsid, cfg.train_pre_path)
File "/home/mortal/ETOP/Document_Layout_Analysis/keras_yolov4/tools/data_process.py", line 60, in data_clean
gt_class[i][0] = catid2clsid[catid]
KeyError: 4

Error while trying to train a model for a new dataset

Hey

I am having the following error when I try to train a new model for the voc dataset!!!
Any idea how to solve this ?

Traceback (most recent call last):
File "train.py", line 273, in
model_body.load_weights(cfg.model_path, by_name=True, skip_mismatch=True)
File ".........conda\envs\tflow_coco\lib\site-packages\keras\engine\saving.py", line 458, in load_wrapper
return load_function(*args, **kwargs)
File ".........conda\envs\tflow_coco\lib\site-packages\keras\engine\network.py", line 1214, in load_weights
reshape=reshape)
File ".........conda\envs\tflow_coco\lib\site-packages\keras\engine\saving.py", line 1245, in load_weights_from_hdf5_group_by_name
g = f[name]
File "h5py_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "C:\Users\merwan.birem.conda\envs\tflow_coco\lib\site-packages\h5py_hl\group.py", line 264, in getitem
oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
File "h5py_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py\h5o.pyx", line 190, in h5py.h5o.open
KeyError: "Unable to open object (object 'tf_op_layer_split' doesn't exist)"

Thank you

Merwan

数据增强代码BUG

class BboxXYXY2XYWH(BaseOperator):
"""
Convert bbox XYXY format to XYWH format.
"""

def __init__(self):
    super(BboxXYXY2XYWH, self).__init__()

def __call__(self, sample, context=None):
    assert 'gt_bbox' in sample
    bbox = sample['gt_bbox']
    bbox[:, 2:4] = bbox[:, 2:4] - bbox[:, :2]
    bbox[:, :2] = bbox[:, :2] + bbox[:, 2:4] / 2.
    sample['gt_bbox'] = bbox
    return sample

bbox[:, :2] = bbox[:, :2] + bbox[:, 2:4] / 2. 这一部分代码是变成 中心点,应该是有误的吧  不需要它

demo.py

博主好,yolov4.pt转keras,h5已转成功,现在检测其效果,当我运行demo.py时出现以下错误:
Traceback (most recent call last):
File "demo_fast.py", line 137, in
outs = yolo.predict(pimage)
File "/home/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 1462, in predict
callbacks=callbacks)
File "/home/anaconda3/lib/python3.6/site-packages/keras/engine/training_arrays.py", line 324, in predict_loop
batch_outs = f(ins_batch)
File "/home/.local/lib/python3.6/site-packages/tensorflow/python/keras/backend.py", line 3076, in call
run_metadata=self.run_metadata)
File "/home/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1439, in call
run_metadata_ptr)
File "/home/.local/lib/python3.6/site-packages/tensorflow/python/framework/errors_impl.py", line 528, in exit
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
[[{{node conv2d_1/convolution}}]]
[[{{node lambda_1/Reshape_24}}]]

请问这是怎么回事?怎么解决 ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.