dariozanca / G-Eymol

Implementation of a gravitational model of visual attention scanpath
4 stars 1 forks source link

get_fixations returns IndexError #1

Open sendjasni opened 3 years ago

sendjasni commented 3 years ago

Calling get_fexations() gives an error :

list_of_fixations = eymol.get_fixations(gaze_positions)

.../G-Eymol/eymol.py in get_fixations(eye_positions)
    678 
    679 def get_fixations(eye_positions):
--> 680     return np.array(fixation_detection(eye_positions[:, 1], eye_positions[:, 0], eye_positions[:, 2] * 1000.)[1])[:, (3, 4, 0, 1)]
    681 

IndexError: too many indices for array
dariozanca commented 3 years ago

Did you execute it following the jupyter tutorial?

I am currently not getting this error. Could you check what is the gaze_positions.shape at that point? (It should be an N-by-3 array)

sendjasni commented 3 years ago

Hi, The gaze_positions.shape gave (125, 3) and its return the same error. I changed one line in the code as it returns an error (AttributeError: module 'time' has no attribute 'clock'):

self.real_time_last_saccade = time.clock() changed to self.real_time_last_saccade = time.process_time()

dariozanca commented 3 years ago

Which python version are you currently using?

sendjasni commented 3 years ago

Python 3.8.5

dariozanca commented 3 years ago

The python version should be fine.

My guess is that for some reason the fixation detector is returning an empty array. Could you check it out?

To do so, please modify get_fixations() to:

def get_fixations(eye_positions):

    x = fixation_detection(eye_positions[:, 1], eye_positions[:, 0], eye_positions[:, 2] * 1000.)[1]
    print("Fixation detector output shape:", x.shape)

    return np.array(x)[:, (3, 4, 0, 1)]
sendjasni commented 3 years ago

This is what I got :

Fixation detector output shape: (0,)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-6-9f266b28fe4d> in <module>
----> 1 list_of_fixations = eymol.get_fixations(gaze_positions)

~/Worspace/G-Eymol/eymol.py in get_fixations(eye_positions)
    682     print("Fixation detector output shape:", np.array(x).shape)
    683 
--> 684     return np.array(x)[:, (3, 4, 0, 1)]

IndexError: too many indices for array
sendjasni commented 3 years ago

I have changed the image and it's working, I used another one and it did not. Do you know why ? Here is the output for the one it worked:

img.shape : (2688, 5376, 3) gaze_positions.shape : (125, 3) Fixation detector output shape : (1, 5) List of fixation points ([pixel row, pixel column, intial time, final time]): [[2928. 1584. 120. 280.]]

dariozanca commented 3 years ago

In such a case everything is "working"... but there are some numerical problems. From your working image, you actually get a single fixation from a 5 seconds simulation, which is not good (and this can be due to ill-gradient scaling).

You should get something like this instead (where every blue point is a fixation):

download

Next check I suggest you is to verify if you fed an image properly (this may very with different codec). Please verify that your pixel range between 0 and 255. Normalize them otherwise.

The reason is the following. This model work using image gradient as an actractive force that guide the attention mechanism. If you rescale the image gradient, you need to search to new hyperparameter because default would not work.

sendjasni commented 3 years ago

Thank you, @dariozanca I'm actually trying to use your model on panoramic images, which are high resolution images. The image attributes are :

img = cv2.imread('010.png')
img.shape
print('Data range : ', np.amin(img), np.amax(img))

This gives :

(2048, 4096, 3)
Data range : [0, 255]