hysts / pytorch_mpiigaze

An unofficial PyTorch implementation of MPIIGaze and MPIIFaceGaze
MIT License
346 stars 85 forks source link

puzzle about getting the '_register_hook' #55

Closed pxssw closed 2 years ago

pxssw commented 2 years ago

Hi boy, it`s a great job, but I'm puzzled about the process in 'resnet_simplt.py' getting the '_register_hook'. Why this step is needed in the model init ?

hysts commented 2 years ago

Hi, @pxssw

It's an implementation of the spatial weight mechanism described in section 4.1 of this paper. The hook is registered to average the gradients by the number of the channels. About function hook in PyTorch, take a look at this.

pxssw commented 2 years ago

umm I got it, Thanks. But when make the ' x = self.feature_extractor(x) y = F.relu(self.conv(x)) x = x * y' the y means Spatial Weights, Whether it is necessary to make the y pass though a logistic function? Considering whether the result is too big.

hysts commented 2 years ago

Sorry, I don't understand what you are asking. But anyway, if you have another idea, it's nice to try it out.

pxssw commented 2 years ago

The process above just is the 'forward' function of 'resnet_simplt.py' , and 'y = F.relu(self.conv(x)) x = x * y' is the application of '_register_hook'(4.1 part of the parer). I was just wondering about the 'y' (Spatial Weights) should be normalized into [0,1] or not.

hysts commented 2 years ago

Ah, I see. Yes, using sigmoid instead of ReLU is a possible option. I've tried some structures including changing backbones and the attention branch, but they didn't make much difference. But what I tried is not exhaustive, so some ideas may work better.

pxssw commented 2 years ago

OK, thanks a lot. I have one more question, how the '_compute_normalizing_rotation' of '/gaze_estimation/gaze_estimator/head_pose_estimation/head_pose_normalizer.py' works? can you give me some simple describtion or inference of math?Thanks!

hysts commented 2 years ago

@pxssw

It's an implementation of what's described in Figure 9 and section 4.2 of this paper, so taking a look at them would help.

pxssw commented 2 years ago

get it , thanks a lot!