Gaze estimation

hey, kindly help me in the following issue of python pytorch; the values of gaze estimation prediction are in floating points. How can i use a threshold to make 2 classes out of these so that one class gets the images with accurate gaze estimation, and other gets vice versa? Thanks

Do you mean you would like to separate your predictions into two classes, i.e. good predictions and bad predictions?

Yes, how can I do that?

You could use your metric, e.g. MSE, and use a threshold to separate the predictions.

predictions = torch.randn(100)
threshold = 0
pred_cluster = torch.where(predictions > threshold, torch.ones(1), torch.zeros(1))
1 Like

Thank you, it works!

Hi, I need help in the following issue; I have got two classes with data, one of good prediction and other of bad prediction. Now I want to take the average of both classes seperately. Kindly help me in this regard.


You could just use the threshold to index the tensor:

pred_errors = torch.randn(100)
threshold = 0.0
pred_errors[pred_errors < threshold].mean()
pred_errors[pred_errors >= threshold].mean()
1 Like

No, I need help in the following issue; I have got two classes with data, one of good prediction and other of bad prediction. Now I want to know the percentage wise ratio of data in both classes (i-e ratio of 0’s and 1’s). Can this be done from confusion matrix or any other mechanism? Kindly help me in this regard.


Could you post a small example?
As far as I understand you have to tensors, one with bad predictions and the other with good ones.
Both tensors just contain zeros and ones and now you would like to calculate the ratio?

good_pred = torch.empty(100).random_(2)

(good_pred==0).float().sum() / good_pred.size(0)
(good_pred==1).float().sum() / good_pred.size(0)
1 Like

Thanks alot, it really help me out in solving my issue. Stay blessed!

Hi, i have a query to ask from my code. My code is working fine, but i wish to know why the threshold is set to zero ‘0’. And what will happen if we change it to some other value? Kindly help me with this. Thanks!

Oh sorry for not making it clear.
I’ve just set the threshold in my demo code to zero, as torch.randn samples from a normal distribution with zero mean. The threshold should therefore divide the samples in two classes with approx. the same amount of samples.
In your code your error distribution will look differently and you should adjust the threshold.

As far as I’ve understood your use case, you expect two clusters of errors, i.e. good and bad predictions.
You have to calculate or estimate this threshold.

Thanks alot, i have found the threshold value suitable for my task. So nice of you to explain!

hi, i want to ask a query. i want to import my self made dataset into the code. Kindly guide me to do so. Following is the screenshot of my code. Thanks!

The code looks alright! Do you have problems running it somehow?
Also, it’s better to post code directly, as others can search for it. :wink:

Actually I wish to import my own data set that i made. I want to know how can I import my self made data set into pytorch? Please guide me…

Have a look at the Data Loading Tutorial.
There you can see, how to create and use your own Dataset.

From the code you’ve posted, it looks like you already have a Dataset for your gaze data.
You can just wrap this Dataset into a DataLoader and use it to get your samples:

dataset = MPIGaueDataset(subject_id=..., dataset_dir=...)
loader = DataLoader(
for image, pose, gaze in loader:
    # Your training routine

No,this code is working fine.
I want to apply this code on my self made dataset. I don’t know how to set directory of dataset and how to import it in code.
Also, Can you please guide me how to do annotation of images or guide me some tutorial of it?

So you would like to create your own dataset?
Could you explain, what kind of images you have or would like to capture?
From the topic it seems you would like to create some gaze estimation dataset.
Do you already have images?

For the MPII gaze dataset the authors give the following information:

We implemented custom software running as a background service on participants’ laptops. Every 10 minutes the software automatically asked participants to look at a random sequence of 20 on-screen positions (a recording session), visualized as a grey circle shrinking in size and with a white dot in the middle. Participants were asked to fixate on these dots and confirm each by pressing the spacebar once the circle was about to disappear. This was to ensure participants concentrated on the task and fixated exactly at the intended on-screen positions. No other instructions were given to them, in particular no constraints as to how and where to use their laptops.

For a small use case you could try out some commercial gaze estimation sensors and use them as your ground truth.

Hi, I need help in the following issue; I have got two classes with data, one of good prediction and other of bad prediction. Now I want to check the accuracy of it. How can I do that?

Please guide me. :disappointed::worried: