tensorflow-yolov3 icon indicating copy to clipboard operation
tensorflow-yolov3 copied to clipboard

训练到中间会出现nan

Open fengxiuyaun opened this issue 6 years ago • 15 comments

你好,作者。非常感谢你的分享你的代码。我一直关注你的动态。从之前老版本的yolov3,到现在的版本。现在我用你的代码的时候,训练时,起初一开始就Nan,后来我把学习率放低,但是迭代到30几个epoch的时候就Nan了。我用你之前的版本并没有出现过这种情况。还有个奇怪的现象,我之前的学习率一般从0.001开始。现在0.0005,训到30还nan,这点有点奇怪

fengxiuyaun avatar Aug 22 '19 03:08 fengxiuyaun

你的目标是不是太小了,我之前的小目标会有这个问题

xliu79 avatar Aug 22 '19 06:08 xliu79

没有小目标。不知道怎么定位到发生nan的那个时刻

fengxiuyaun avatar Aug 23 '19 12:08 fengxiuyaun

你的目标是不是太小了,我之前的小目标会有这个问题 没有小目标。不知道怎么定位到发生nan的那个时刻

fengxiuyaun avatar Aug 23 '19 12:08 fengxiuyaun

现在已经解决,正是因为数据有脏数据。这个脏数据并不是不能用,但经过augument后可能不适合loss层计算,导致有些运算变成了不运算,比如除0,log有0等等。由于代码中并没有考虑这种极端现象,导致nan。后来人可使用tfdbg调试一下

fengxiuyaun avatar Sep 03 '19 01:09 fengxiuyaun

@fengxiuyaun 想問一下你的髒數據可以說明一下是甚麼樣的數據呢

btsken avatar Sep 03 '19 07:09 btsken

@fengxiuyaun 想問一下你的髒數據可以說明一下是甚麼樣的數據呢

我现在查到了一个原因是。我的数据经过augument之后,有一个GT box的w,h变成了0,再求IOU的时候,除数变成了0

fengxiuyaun avatar Sep 03 '19 08:09 fengxiuyaun

我用我的数据训练也遇到了相同的问题,训练到中间就nan了

zhangscth avatar Sep 05 '19 06:09 zhangscth

我也遇到了,把yolov3.py里关于iou和giou里的除法多个tf.maximum来限制就行了

DavidLeon777 avatar Nov 28 '19 03:11 DavidLeon777

楼上的大佬能不能详细说一下 “把yolov3.py里关于iou和giou里的除法多个tf.maximum来限制就行了” 这句话是什么意思?具体怎么操作?

zhishao avatar Nov 30 '19 15:11 zhishao

在yolo3.py的bbox_giou上改两处: iou = inter_area / tf.maximum(union_area, 1e-12) giou = iou - 1.0 * (enclose_area - union_area) / tf.maximum(enclose_area, 1e-12) 在yolo3.py的bbox_iou上改一处: iou = 1.0 * inter_area / tf.maximum(union_area, 1e-12) 亲测再也没有出现Nan的问题

DavidLeon777 avatar Dec 03 '19 06:12 DavidLeon777

哇 感谢楼上大佬!我回去试一下,我还不太会在这个上面@人。。。

zhishao avatar Dec 03 '19 06:12 zhishao

Hi @zhishao , does it work for you?

I see that union_area is calculated as:

union_area = boxes1_area + boxes2_area - inter_area

So as long as the label or ground truth area is not 0, I'm just curious if union_area will ever be 0 and the division later on will cause NaN value. @DavidLeon777 , what do you think?

witignite avatar Feb 06 '20 08:02 witignite

I don't know what exactly happened. It seems that the data argument part will cause the label to be missing? The event happened so accidentally that it was hard to capture. But it works if you add a program part that prevents dividing by 0

DavidLeon777 avatar Feb 12 '20 02:02 DavidLeon777

你的目标是不是太小了,我之前的小目标会有这个问题

请问你小目标是怎么解决这个问题的呢?

nengbunengzhengdianqi avatar Aug 26 '20 03:08 nengbunengzhengdianqi

现在已经解决,正是因为数据有脏数据。这个脏数据并不是不能用,但经过augument后可能不适合loss层计算,导致有些运算变成了不运算,比如除0,log有0等等。由于代码中并没有考虑这种极端现象,导致nan。后来人可使用tfdbg调试一下

你好,请问你是如何定位到这些脏数据的?

qingmeizhujiu avatar Jul 01 '21 04:07 qingmeizhujiu