def __init__(self, stimuli, fixations, saliency_map_provider, remove_doublicates=False, antonio_gaussian=False, empirical_maps=None, cache_empirical_maps=True): self.stimuli = stimuli if remove_doublicates: fixations = remove_doublicate_fixations(fixations) self.fixations = fixations self.saliency_map_provider = saliency_map_provider if empirical_maps is not None: self.empirical_maps = empirical_maps elif not antonio_gaussian: self.empirical_maps = pysaliency.FixationMap( stimuli, fixations, kernel_size=23.99, caching=cache_empirical_maps) else: self.empirical_maps = MITFixationMap(stimuli, fixations, fc=8, caching=cache_empirical_maps)
def test_fixation_map_model(stimuli, fixation_trains): fixation_map = pysaliency.FixationMap(stimuli, fixation_trains) smap1 = fixation_map.saliency_map(stimuli[0]) assert smap1.min() == 0 assert smap1.max() == 3 assert smap1.sum() == (fixation_trains.n == 0).sum()
def test_fixation_map_model_ignore_doublicates(stimuli, fixation_trains): fixation_map = pysaliency.FixationMap(stimuli, fixation_trains, ignore_doublicates=True) smap1 = fixation_map.saliency_map(stimuli[0]) assert smap1.min() == 0 assert smap1.max() == 1 assert smap1.sum() == (fixation_trains.n == 0).sum() - 2
def test_cc_gauss(stimuli, fixation_trains): gsmm = GaussianSaliencyMapModel() gold = pysaliency.FixationMap(stimuli, fixation_trains, kernel_size=10, ignore_doublicates=True) cc = gsmm.CC(stimuli, gold) np.testing.assert_allclose(cc, -0.1542654)
def test_cc_constant(stimuli, fixation_trains): model = ConstantSaliencyMapModel() gold = pysaliency.FixationMap(stimuli, fixation_trains, kernel_size=10, ignore_doublicates=True) cc = model.CC(stimuli, gold) np.testing.assert_allclose(cc, 0)
def test_conditional_saliency_maps(stimuli, fixation_trains): model = pysaliency.FixationMap(stimuli, fixation_trains, kernel_size=10) saliency_maps_1 = model.conditional_saliency_maps(stimuli, fixation_trains) saliency_maps_2 = [ model.conditional_saliency_map_for_fixation(stimuli, fixation_trains, i) for i in range(len(fixation_trains)) ] np.testing.assert_allclose(saliency_maps_1, saliency_maps_2)
def test_image_based_kldiv_gauss_functions(stimuli, fixation_trains): gsmm = GaussianSaliencyMapModel() gold = pysaliency.FixationMap(stimuli, fixation_trains, kernel_size=10, ignore_doublicates=True) stimuli, fixation_trains = pysaliency.create_subset( stimuli, fixation_trains, [0]) saliency_map_1 = gsmm.saliency_map(stimuli[0]) saliency_map_2 = gold.saliency_map(stimuli[0]) value1 = gsmm.image_based_kl_divergence(stimuli, gsmm) value2 = pysaliency.metrics.image_based_kl_divergence( saliency_map_1, saliency_map_1) np.testing.assert_allclose(value1, value2) constant_gold = ConstantSaliencyMapModel() saliency_map_1 = gsmm.saliency_map(stimuli[0]) saliency_map_2 = constant_gold.saliency_map(stimuli[0]) value1 = gsmm.image_based_kl_divergence(stimuli, constant_gold) value2 = pysaliency.metrics.image_based_kl_divergence( saliency_map_1, saliency_map_2) np.testing.assert_allclose(value1, value2) constant_gold = ConstantSaliencyMapModel(value=0.0) saliency_map_2 = constant_gold.saliency_map(stimuli[0]) value1 = gsmm.image_based_kl_divergence(stimuli, constant_gold) value2 = pysaliency.metrics.image_based_kl_divergence( saliency_map_1, saliency_map_2) np.testing.assert_allclose(value1, value2) # test MIT Benchmarking settings # (minimum_value=0 can be problematic for constant models) value1 = gsmm.image_based_kl_divergence(stimuli, constant_gold, minimum_value=0, log_regularization=2.2204e-16, quotient_regularization=2.2204e-16) value2 = pysaliency.metrics.MIT_KLDiv(saliency_map_1, saliency_map_2) np.testing.assert_allclose(value1, value2) saliency_map_2 = gold.saliency_map(stimuli[0]) value1 = gsmm.image_based_kl_divergence(stimuli, gold) value2 = pysaliency.metrics.image_based_kl_divergence( saliency_map_1, saliency_map_2) np.testing.assert_allclose(value1, value2)
def test_SIM_gauss(stimuli, fixation_trains): gsmm = GaussianSaliencyMapModel() constant_gold = ConstantSaliencyMapModel() sim = gsmm.SIM(stimuli, constant_gold) np.testing.assert_allclose(sim, 0.54392, rtol=1e-6) constant_gold = ConstantSaliencyMapModel(value=0.0) sim = gsmm.SIM(stimuli, constant_gold) np.testing.assert_allclose(sim, 0.54392, rtol=1e-6) gold = pysaliency.FixationMap(stimuli, fixation_trains, kernel_size=10, ignore_doublicates=True) sim = gsmm.SIM(stimuli, gold) np.testing.assert_allclose(sim, 0.315899, rtol=1e-6)
def test_gauss(self): stimuli = pysaliency.Stimuli([np.random.randn(40, 40, 3), np.random.randn(40, 40, 3)]) gsmm = GaussianSaliencyMapModel() constant_gold = ConstantSaliencyMapModel() gold = pysaliency.FixationMap(stimuli, self.f, kernel_size = 10) ib_kl = gsmm.image_based_kl_divergence(stimuli, gsmm) np.testing.assert_allclose(ib_kl, 0.0) ib_kl = gsmm.image_based_kl_divergence(stimuli, constant_gold) np.testing.assert_allclose(ib_kl, 0.8152272380729648) ib_kl = gsmm.image_based_kl_divergence(stimuli, gold) np.testing.assert_allclose(ib_kl, 1.961124862592289) ib_kl = gold.image_based_kl_divergence(stimuli, gold) np.testing.assert_allclose(ib_kl, 0.0)
def test_image_based_kldiv_gauss(stimuli, fixation_trains): gsmm = GaussianSaliencyMapModel() gold = pysaliency.FixationMap(stimuli, fixation_trains, kernel_size=10, ignore_doublicates=True) ib_kl = gsmm.image_based_kl_divergence(stimuli, gsmm) np.testing.assert_allclose(ib_kl, 0.0) ib_kl = gsmm.KLDiv(stimuli, gsmm) np.testing.assert_allclose(ib_kl, 0.0) constant_gold = ConstantSaliencyMapModel() ib_kl = gsmm.image_based_kl_divergence(stimuli, constant_gold) np.testing.assert_allclose(ib_kl, 0.8396272788909165) ib_kl = gsmm.KLDiv(stimuli, constant_gold) np.testing.assert_allclose(ib_kl, 0.8396272788909165) constant_gold = ConstantSaliencyMapModel(value=0.0) ib_kl = gsmm.image_based_kl_divergence(stimuli, constant_gold) np.testing.assert_allclose(ib_kl, 0.8396272788909165) ib_kl = gsmm.KLDiv(stimuli, constant_gold) np.testing.assert_allclose(ib_kl, 0.8396272788909165) # test MIT Benchmarking settings # (minimum_value=0 can be problematic for constant models) ib_kl = gsmm.image_based_kl_divergence(stimuli, constant_gold, minimum_value=0, log_regularization=2.2204e-16, quotient_regularization=2.2204e-16) np.testing.assert_allclose(ib_kl, 0.8396272788909165) ib_kl = gsmm.image_based_kl_divergence(stimuli, gold) np.testing.assert_allclose(ib_kl, 2.029283206727416) ib_kl = gold.image_based_kl_divergence(stimuli, gold) np.testing.assert_allclose(ib_kl, 0.0)
def test_image_based_kldiv_gauss(stimuli, fixation_trains): gsmm = GaussianSaliencyMapModel() constant_gold = ConstantSaliencyMapModel() gold = pysaliency.FixationMap(stimuli, fixation_trains, kernel_size=10, ignore_doublicates=True) ib_kl = gsmm.image_based_kl_divergence(stimuli, gsmm) np.testing.assert_allclose(ib_kl, 0.0) ib_kl = gsmm.KLDiv(stimuli, gsmm) np.testing.assert_allclose(ib_kl, 0.0) ib_kl = gsmm.image_based_kl_divergence(stimuli, constant_gold) np.testing.assert_allclose(ib_kl, 0.8396272788909165) ib_kl = gsmm.KLDiv(stimuli, constant_gold) np.testing.assert_allclose(ib_kl, 0.8396272788909165) ib_kl = gsmm.image_based_kl_divergence(stimuli, gold) np.testing.assert_allclose(ib_kl, 2.029283206727416) ib_kl = gold.image_based_kl_divergence(stimuli, gold) np.testing.assert_allclose(ib_kl, 0.0)
def __init__(self, stimuli, fixations, fc=8): fixation_map = pysaliency.FixationMap(stimuli, fixations) super(MITFixationMap, self).__init__(fixation_map, fc=fc)