Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to compute the gaussian_radius?Who can tell me the formula about it?Thank you! #110

Open
qiuhaining opened this issue May 30, 2019 · 54 comments

Comments

@qiuhaining
Copy link

No description provided.

@fenglv12345
Copy link

i have the same question. i have tryed to derive the mathematical formulas.but mine is different with the author's code

@fenglv12345
Copy link

here is one of my mathematical formulas for (r3)
image

@qiuhaining
Copy link
Author

qiuhaining commented Jun 1, 2019

here is one of my mathematical formulas for (r3)
image

I guess that it is the two peaks of redius value。The minimum value should be obtained from the two peaks. But,i cannot prove my guess. Your answer is the one of the peaks.

image

@fenglv12345
Copy link

for r1
image

for r2
image

for r3
image

conclusion:
with great possibility,the authour's mathmatical formulas are not correct and are not corresponding to the mind in papers.

@fenglv12345
Copy link

the correct formulas as below
image

@qiuhaining
Copy link
Author

the correct formulas as below
image

what is the redius of the object as below??
image

@fenglv12345
Copy link

compute as below
image
by the way,i am improving the method in this way.

@qiuhaining
Copy link
Author

compute as below
image
by the way,i am improving the method in this way.

Yes,this is the same as my idea,i look forward to the result, but,we need a dataset including various aspect ratios to confirm the idea!

@fenglv12345
Copy link

just the previous datasets like COCO is ok

@qiuhaining
Copy link
Author

just the previous datasets like COCO is ok

Its my code in CenterNet and it can improve the performance a little! The formula can get by MATLAB Simulink. I need time to do this.

a = min((1 - min_overlap) / (1 + min_overlap) * width, 0.5 * width)
b = min((1 - min_overlap) / (1 + min_overlap) * height, 0.5 * height)
return a, b

@fenglv12345
Copy link

@qiuhaining ok,can you underline the code you have changed or just a picture,because i can not easily find the diversity

@gtwell
Copy link

gtwell commented Jun 6, 2019

6ff0f58b-74cc-4637-bbb9-1ea3aec26cdc

@ggsggs
Copy link

ggsggs commented Aug 6, 2019

Was this a small bug? Has someone noticed any improvement after re-typing the formulas?

@fenglv12345
Copy link

@ggsggs i have tried.the result is that AP is almost the same,but AR is higher. i haven't found the reason why

@ggsggs
Copy link

ggsggs commented Aug 18, 2019

@ggsggs i have tried.the result is that AP is almost the same,but AR is higher. i haven't found the reason why

Oh, interesting. Was it a significant improvement in AR?

@fenglv12345
Copy link

@ggsggs the result as below:
gaussian

@fenglv12345
Copy link

@ggsggs by the way,my work is based on the paper centernet(objects as points),using the model resdcn-18

@ggsggs
Copy link

ggsggs commented Aug 22, 2019

@ggsggs the result as below:
gaussian

@fenglv12345 Thank you for the experiments. ~1-3 points higher! It's not bad at all :)

@ggsggs by the way,my work is based on the paper centernet(objects as points),using the model resdcn-18

I am also working with CenterNet(objects as points one), actually. So it is good to know.

@fenglv12345
Copy link

@ggsggs thanks for your reminding which make me deep into the problem,perhaps i found the reason why. And i have a idea to make the AP higher while the AP is higher. By the way,there is some other method which has the problem (COCO detection challenge . focus on the MSRA)

image

@CF2220160244
Copy link

@fenglv12345 @ggsggs , In CenterNet I use the modified gaussian_radius you mentioned above, and keep other training parameters invariable,I use DLA34dcn, but both the AP and AR reduce. Can you tell me how you get the AR increase? Do you change any other hyper-parameter?

@fenglv12345
Copy link

@CF2220160244 my work in based on resdcn18 ,i didn't change any hyper-parameter,maybe there is some wrong with your implement. the formula as below.or you can show me your code
image

@CF2220160244
Copy link

CF2220160244 commented Aug 28, 2019

@fenglv12345 ,my code is:
r = 0.5*(1-np.sqrt(0.7))*np.sqrt(width ** 2 + height ** 2)
return r

@fenglv12345
Copy link

what about a and b? please understand the formula,you should also change the gaussian function,rather than just the r

@fenglv12345
Copy link

(1)get r
(2)get a and b
(3)change the gasssian function as above (when you change this,you will find some details should be changed)

@fenglv12345
Copy link

by the way,you don't have to calculate this :np.sqrt(width ** 2 + height ** 2),just use w and h

@CF2220160244
Copy link

Thank you very much, I will try! @fenglv12345

@CF2220160244
Copy link

CF2220160244 commented Aug 28, 2019

@fenglv12345
Is it right? I change the code to the following,

#def gaussian2D(shape, sigma=1):
def gaussian2D(shape, a=1,b=1):
m, n = [(ss - 1.) / 2. for ss in shape]
y, x = np.ogrid[-m:m+1,-n:n+1]
#h = np.exp(-(x * x + y * y) / (2 * sigma * sigma))
h = np.exp(-(x * x ) / (2 * a/3 * a/3)-(y * y) / (2 * b/3 * b/3))
h[h < np.finfo(h.dtype).eps * h.max()] = 0
return h

def draw_umich_gaussian(heatmap, center, radius, k=1):
diameter = 2 * radius + 1
height, width = heatmap.shape[0:2]
gaussian = gaussian2D((diameter, diameter), a=0.1155 * width, b=0.1155 * height)
#gaussian = gaussian2D((diameter, diameter), sigma=diameter / 6)
x, y = int(center[0]), int(center[1])
#height, width = heatmap.shape[0:2]
....

def gaussian_radius(det_size, min_overlap=0.7):
height, width = det_size
r = 0.5*(1-np.sqrt(min_overlap))*np.sqrt(width ** 2 + height ** 2)
return r

@CF2220160244
Copy link

CF2220160244 commented Sep 4, 2019

@fenglv12345
After i change to the oval gauss,the AR is almost the same,but the AP drop obviously, there are more false positive.

@seekFire
Copy link

seekFire commented Sep 4, 2019

@fenglv12345
How to deduce the formula "a = sqrt(2)r1a / sqrt(a^2 + b^2)" when using oval gaussian?

@fenglv12345
Copy link

@seekFire as below
image

@fenglv12345
Copy link

@CF2220160244 which model you have trained?dla34 or res18?res18 worked.and dla34 didn't work,i am trying to fix the problem,not the formula but other things, i will upload my code two or three days later on my repositories

@seekFire
Copy link

seekFire commented Sep 4, 2019

@fenglv12345 Good! Thank you very much!

@CF2220160244
Copy link

@fenglv12345 I train DLA. Looking forward to your result!

@seekFire
Copy link

seekFire commented Sep 5, 2019

@fenglv12345
By the way, does the function "draw_dense_reg" in image.py also need to be rectified?

@fenglv12345
Copy link

@seekFire we don't use draw_dense_reg

@CF2220160244
Copy link

@fenglv12345 Do you have any progress about the training?

@lcchust
Copy link

lcchust commented Nov 25, 2019

@fenglv12345
image
In your code "gaussian_radius1", I think 'ra' represent 'rh' and 'rb' represent 'w', but in code "draw_umich_gaussian1" you send 'ra' to 'rw' and 'rb' to 'rh'
image
I'm confused with "ra", "rb" and "rh", "rw", could you explain it?

@Dantju
Copy link

Dantju commented Dec 31, 2019

@qiuhaining i follow your code,but get error while training,have u change code expect the image u show

@AlphaPlusTT
Copy link

which size should i use to calculate the radius of the gaussion? i believe the shape should be the size of the gt bbox divided by the stride, but the code seem to use the original size of the gt bbox ? did i miss something ?

@ranjiewwen
Copy link

ranjiewwen commented Apr 26, 2020

def gaussian2D(shape, sigma=1):
    m, n = [(ss - 1.) / 2. for ss in shape]
    y, x = np.ogrid[-m:m+1,-n:n+1]

    h = np.exp(-(x * x + y * y) / (2 * sigma * sigma))
    h[h < np.finfo(h.dtype).eps * h.max()] = 0
    return h

def draw_umich_gaussian(heatmap, center, radius, k=1):
  diameter = 2 * radius + 1
  gaussian = gaussian2D((diameter, diameter), sigma=diameter / 6)

when the radius = 0, maybe small object cause?

@AlphaPlusTT
Copy link

@ranjiewwen yes, the stride in centernet is 4, If the short edge of the object only occupies 3 pixels, floor(3/4)=0

@Apostatee
Copy link

@fenglv12345
image
In your code "gaussian_radius1", I think 'ra' represent 'rh' and 'rb' represent 'w', but in code "draw_umich_gaussian1" you send 'ra' to 'rw' and 'rb' to 'rh'
image
I'm confused with "ra", "rb" and "rh", "rw", could you explain it?

Must be a mistake

@JyunYuLai
Copy link

@CF2220160244 my work in based on resdcn18 ,i didn't change any hyper-parameter,maybe there is some wrong with your implement. the formula as below.or you can show me your code
image

Hi @fenglv12345 ,
I'm curious about why you use r2 for CenterNet.
In CornerNet, because r3 > r1 > r2 so you choose r2.
But in CenterNet, the only case that happen is r1.
I am not sure if my idea is correct.
Looking forward to your reply.
Thank you.

@18804601171
Copy link

@fenglv12345 你好,请问你在前面放的你的代码图里,ra和rb与公式相反了,是否是写错了呢

@urbaneman
Copy link

@CF2220160244 my work in based on resdcn18 ,i didn't change any hyper-parameter,maybe there is some wrong with your implement. the formula as below.or you can show me your code
image

Hi @fenglv12345 ,
I'm curious about why you use r2 for CenterNet.
In CornerNet, because r3 > r1 > r2 so you choose r2.
But in CenterNet, the only case that happen is r1.
I am not sure if my idea is correct.
Looking forward to your reply.
Thank you.

Hi @JyunYuLai ,
I agree with you. CenterNet only need to find one point(center), not two corners. So, the only case that happens is r1.
What do you think? @fenglv12345.
Looking forward to your reply. Thanks.

@igo312
Copy link

igo312 commented Apr 25, 2021

In my experiment useing right method to generate gaussian heatmap will make result bad surprisingly

Intuitively it should improve the perfomance, so really upset about that. Let's named origin generating method as G1 and rectified method as G2

my dataset is aerial image.here's example of G1 and G2, first one is G1, second one is G2

though the model trained by G2 get smaller loss but the map is only 67 in training dataset and 58 in validation dataset

the model trained by G1 get 89 in training dataset and 75 in validation dataset

image

image

@wangx1996
Copy link

In my experiment useing right method to generate gaussian heatmap will make result bad surprisingly

Intuitively it should improve the perfomance, so really upset about that. Let's named origin generating method as G1 and rectified method as G2

my dataset is aerial image.here's example of G1 and G2, first one is G1, second one is G2

though the model trained by G2 get smaller loss but the map is only 67 in training dataset and 58 in validation dataset

the model trained by G1 get 89 in training dataset and 75 in validation dataset

image

image

以这种方式生成的高斯分布是带有方向性的,看你的数据应该是旋转box,但是只依靠上述的高斯分布生成方法只能是对正矩形有效吧

@liuzw-cyy
Copy link

In my experiment useing right method to generate gaussian heatmap will make result bad surprisingly

Intuitively it should improve the perfomance, so really upset about that. Let's named origin generating method as G1 and rectified method as G2

my dataset is aerial image.here's example of G1 and G2, first one is G1, second one is G2

though the model trained by G2 get smaller loss but the map is only 67 in training dataset and 58 in validation dataset

the model trained by G1 get 89 in training dataset and 75 in validation dataset

image

image

Hello! Excuse me, can you share the code for drawing these two diagrams?

@Jayden9912
Copy link

Hi.

Given this picture

$$ IOU = \frac{(w-2r_2\cos\theta)(h-2r_2\sin\theta)}{wh}$$

$$ (4\sin\theta \cos\theta)r_2^2 - 2(w\sin\theta+h\cos\theta)r_2+wh(1-IOU) = 0$$

Using quadratic formula,
$$r_2 = \frac{2(w\sin\theta +h\cos\theta)\pm \sqrt{4(w\sin\theta+h\cos\theta)^2-16\sin\theta \cos\theta(wh)(1-IOU)}}{8\sin\theta \cos\theta} $$

How should I proceed to simplify the equation to get

$$ r_2 = \frac{(1-\sqrt{IOU})\sqrt{w^2+h^2}}{2} $$

which is calculated by using the concept of overlapping in the diagonal line of the 2 bounding boxes

$$ \sqrt{IOU} = \frac{\sqrt{(w^2+h^2)}-2r_2}{\sqrt{w^2+h^2}} $$

@qiuhaining
Copy link
Author

qiuhaining commented Oct 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests