Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PASCAL-S dataset uses ScanpathFixations #68

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions pysaliency/external_datasets/pascal_s.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
from __future__ import absolute_import, print_function, division
from __future__ import absolute_import, division, print_function

import zipfile
import os
import zipfile

import requests
import numpy as np
import requests

from ..datasets import FixationTrains
from ..datasets import ScanpathFixations, Scanpaths
from ..utils import (
TemporaryDirectory,
download_and_check,
atomic_directory_setup,
download_and_check,
)

from .utils import create_stimuli, _load
from .utils import _load, create_stimuli


def get_PASCAL_S(location=None):
Expand Down Expand Up @@ -100,7 +99,13 @@ def get_PASCAL_S(location=None):
train_ns.append(n)
train_subjects.append(subject - 1) # subjects are 1-indexed in matlab

fixations = FixationTrains.from_fixation_trains(train_xs, train_ys, train_ts, train_ns, train_subjects)
fixations = ScanpathFixations(Scanpaths(
xs=train_xs,
ys=train_ys,
ts=train_ts,
n=train_ns,
subject=train_subjects,
))

if location:
stimuli.to_hdf5(os.path.join(location, 'stimuli.hdf5'))
Expand Down
52 changes: 52 additions & 0 deletions tests/external_datasets/test_PASCAL_S.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import numpy as np
import pytest
from pytest import approx
from scipy.stats import kurtosis, skew

import pysaliency
import pysaliency.external_datasets
from tests.test_external_datasets import _location, entropy


@pytest.mark.slow
@pytest.mark.download
def test_PASCAL_S(location):
real_location = _location(location)

stimuli, fixations = pysaliency.external_datasets.get_PASCAL_S(location=real_location)
if location is None:
assert isinstance(stimuli, pysaliency.Stimuli)
assert not isinstance(stimuli, pysaliency.FileStimuli)
else:
assert isinstance(stimuli, pysaliency.FileStimuli)
assert location.join('PASCAL-S/stimuli.hdf5').check()
assert location.join('PASCAL-S/fixations.hdf5').check()

assert len(stimuli.stimuli) == 850

assert len(fixations.x) == 40314

assert np.mean(fixations.x) == approx(240.72756362553952)
assert np.mean(fixations.y) == approx(194.85756809048965)
assert np.mean(fixations.t) == approx(2.7856823932132757)
assert np.mean(fixations.scanpath_history_length) == approx(2.7856823932132757)

assert np.std(fixations.x) == approx(79.57401169717699)
assert np.std(fixations.y) == approx(65.21296890260112)
assert np.std(fixations.t) == approx(2.1191752645988675)
assert np.std(fixations.scanpath_history_length) == approx(2.1191752645988675)

assert kurtosis(fixations.x) == approx(0.0009226786675387011)
assert kurtosis(fixations.y) == approx(1.1907544566979986)
assert kurtosis(fixations.t) == approx(-0.540943536495714)
assert kurtosis(fixations.scanpath_history_length) == approx(-0.540943536495714)

assert skew(fixations.x) == approx(0.2112334873314548)
assert skew(fixations.y) == approx(0.7208733522533084)
assert skew(fixations.t) == approx(0.4800678710338635)
assert skew(fixations.scanpath_history_length) == approx(0.4800678710338635)

assert entropy(fixations.n) == approx(9.711222735065062)
assert (fixations.n == 0).sum() == 35

assert len(fixations) == len(pysaliency.datasets.remove_out_of_stimulus_fixations(stimuli, fixations))
44 changes: 0 additions & 44 deletions tests/test_external_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,50 +284,6 @@ def test_mit1003_onesize(location, matlab):
assert (fixations.n == 0).sum() == 121


@pytest.mark.slow
@pytest.mark.download
def test_PASCAL_S(location):
real_location = _location(location)

stimuli, fixations = pysaliency.external_datasets.get_PASCAL_S(location=real_location)
if location is None:
assert isinstance(stimuli, pysaliency.Stimuli)
assert not isinstance(stimuli, pysaliency.FileStimuli)
else:
assert isinstance(stimuli, pysaliency.FileStimuli)
assert location.join('PASCAL-S/stimuli.hdf5').check()
assert location.join('PASCAL-S/fixations.hdf5').check()

assert len(stimuli.stimuli) == 850

assert len(fixations.x) == 40314

assert np.mean(fixations.x) == approx(240.72756362553952)
assert np.mean(fixations.y) == approx(194.85756809048965)
assert np.mean(fixations.t) == approx(2.7856823932132757)
assert np.mean(fixations.scanpath_history_length) == approx(2.7856823932132757)

assert np.std(fixations.x) == approx(79.57401169717699)
assert np.std(fixations.y) == approx(65.21296890260112)
assert np.std(fixations.t) == approx(2.1191752645988675)
assert np.std(fixations.scanpath_history_length) == approx(2.1191752645988675)

assert kurtosis(fixations.x) == approx(0.0009226786675387011)
assert kurtosis(fixations.y) == approx(1.1907544566979986)
assert kurtosis(fixations.t) == approx(-0.540943536495714)
assert kurtosis(fixations.scanpath_history_length) == approx(-0.540943536495714)

assert skew(fixations.x) == approx(0.2112334873314548)
assert skew(fixations.y) == approx(0.7208733522533084)
assert skew(fixations.t) == approx(0.4800678710338635)
assert skew(fixations.scanpath_history_length) == approx(0.4800678710338635)

assert entropy(fixations.n) == approx(9.711222735065062)
assert (fixations.n == 0).sum() == 35

assert len(fixations) == len(pysaliency.datasets.remove_out_of_stimulus_fixations(stimuli, fixations))


@pytest.mark.slow
@pytest.mark.download
def test_DUT_OMRON(location, tmpdir):
Expand Down
Loading