# 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.

Thanks!

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.

Thanks!

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.

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. 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…

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=...)
dataset,
num_workers=...,
shuffle=...
)

for image, pose, gaze in loader:
``````

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.
Please guide me.  