pielet / HairNet

Reimplement of HairNet (a simple vision)
MIT License
54 stars 12 forks source link

nan loss for curvature #5

Open screnary opened 4 years ago

screnary commented 4 years ago

Hi! Thank you for your amazing implementation! When I tried the train code, using your training data, I found the loss sometimes run into 'nan' or 'inf'. I check the code, locating the problem at the curvature loss. I also checked the curvature mean and std, there are some 'inf' or very large numbers. Have you ever met this problem? And is there some experience for data normalization to aviod bad values?

screnary commented 4 years ago

I found the ground truth train_y['curv'] has 'inf'. That is the main cause. I also found the neighbor sample points in that strand has zero curvature. So, I simply set the invalid value to 0.0. P.S., the curvature loss is hard to converge...

screnary commented 4 years ago

I checked your curvature computation code in hair.cpp-->trainy() (line 319) ac = P{j+1} - P{j} ab = P{j+1} - P_{j} then, the curvature radius = ((ab x ac) x ab |ac|^2) + (ac x (ab x ac) |ab|^2) / (2.0 |ab x ac|^2) = (n1 |ac| + n2 |ab|) / (2.0sin(theta)) where n1 is the normal vector of vector ab, n2 is the normal vector of vector ac (inverse direction), theta is the angle between <ac, ab>.

It seems that, the diagnal vector of the <ab, ac>, divided by their sin<ab, ac>, is the radius. But I can't figure out why?

Xkimna commented 1 year ago

Hello, I also encountered the same problem, do you have a solution? T.T @screnary

screnary commented 1 year ago

@Xkimna

Hello! I left the project for quite a while. You can refer to the solution above (manually process the invalid value). Or, a better solution, you can check the curvature computation implementation in hair.cpp.

If you find something, please let me know :) Best wishes.

Xkimna commented 1 year ago

Thank you for your reply!! I will try to solve this problem according to the ideas you mentioned.