From a9a1fed17607f424c617463aa3885cb6c8bec40e Mon Sep 17 00:00:00 2001 From: shashikg Date: Sun, 26 Jan 2020 17:34:52 +0530 Subject: [PATCH 1/4] add klabZhang2018 visual search stimuli --- .gitignore | 2 + mkgu_packaging/klab/__init__.py | 0 mkgu_packaging/klab/search_obj_array.py | 117 ++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100755 .gitignore create mode 100755 mkgu_packaging/klab/__init__.py create mode 100755 mkgu_packaging/klab/search_obj_array.py diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..f14a889 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Data files +mkgu_packaging/klab/search_datasets* diff --git a/mkgu_packaging/klab/__init__.py b/mkgu_packaging/klab/__init__.py new file mode 100755 index 0000000..e69de29 diff --git a/mkgu_packaging/klab/search_obj_array.py b/mkgu_packaging/klab/search_obj_array.py new file mode 100755 index 0000000..6929209 --- /dev/null +++ b/mkgu_packaging/klab/search_obj_array.py @@ -0,0 +1,117 @@ +import os + +import h5py +import numpy as np +import pandas as pd +import scipy.misc +import xarray as xr +from pathlib import Path +from result_caching import store +from sklearn.model_selection import StratifiedShuffleSplit +from tqdm import tqdm +from scipy.io import loadmat + +from brainio_base.assemblies import BehavioralAssembly +from brainio_base.stimuli import StimulusSet +from brainio_contrib.packaging import package_stimulus_set, package_data_assembly + +def collect_stimuli(data_path): + stimuli = [] + + arr_loc = loadmat(os.path.join(data_path / 'gt', 'array.mat')) + + for i in range(1, 301): + j = (np.argmax(arr_loc['MyData'][i-1]['arraycate'][0] == arr_loc['MyData'][i-1]['targetcate'][0])) + target_path = os.path.join(data_path / 'stimuli', 'array_' + str(i) + '.jpg') + filename = 'array_' + str(i) + '.jpg' + image_id = 'stimuli_' + str(i) + image_label = 'stimuli' + sample_number = i + + stimuli.append({ + 'image_current_local_file_path': target_path, + 'image_path_within_store': filename, + 'image_label': image_label, + 'image_id': image_id, + 'tar_obj_pos': j, + 'sample_number': sample_number, + }) + + for i in range(1, 301): + j = (np.argmax(arr_loc['MyData'][i-1]['arraycate'][0] == arr_loc['MyData'][i-1]['targetcate'][0])) + target_path = os.path.join(data_path / 'target', 'target_' + str(i) + '.jpg') + filename = 'target_' + str(i) + '.jpg' + image_id = 'target_' + str(i) + image_label = 'target' + sample_number = i + + stimuli.append({ + 'image_current_local_file_path': target_path, + 'image_path_within_store': filename, + 'image_label': image_label, + 'image_id': image_id, + 'tar_obj_pos': j, + 'sample_number': sample_number, + }) + + for i in range(1,7): + target_path = os.path.join(data_path / 'gt', 'mask' + str(i) + '.jpg') + filename = 'mask' + str(i) + '.jpg' + image_id = 'mask_' + str(i) + image_label = 'mask' + sample_number = i + + stimuli.append({ + 'image_current_local_file_path': target_path, + 'image_path_within_store': filename, + 'image_label': image_label, + 'image_id': image_id, + 'tar_obj_pos': i - 1, + 'sample_number': sample_number, + }) + + stimuli = StimulusSet(stimuli) + return stimuli + +def collect_data(data_path, sub_id): + image_id = ['stimuli_' + str(i) for i in range(1, 301)] + subjects = [] + for i in sub_id: + subjects += [i]*len(image_id) + + S_data = np.load(os.path.join(data_path / 'human_data', 'human_all.npy')) + I_data = np.load(os.path.join(data_path / 'human_data', 'I_human_all.npy')) + data = np.zeros((300*len(sub_id), 8, 2), dtype=int) + data[:,:7,:] = S_data + data[:,7,:] = I_data + + assembly = BehavioralAssembly(data, + coords={'image_id': ('presentation', image_id*len(sub_id)), + 'subjects': ('presentation', subjects), + 'fixation': [*range(8)], + 'position': ['x', 'y']}, + dims=['presentation', 'fixation', 'position']) + return assembly + +def main(): + data_dir = Path(__file__).parent / 'search_datasets' + data_path = data_dir / 'array' + + # create stimuli + stimuli = collect_stimuli(data_path) + stimuli.name = 'klab.Zhang2018.search_obj_array' + + # create assembly for different subjects + assembly = collect_data(data_path, [*range(1, 16)]) + assembly.name = 'klab.Zhang2018search_obj_array' + + # package + print("\nPackaging Stimuli ----------") + package_stimulus_set(stimuli, stimulus_set_name=stimuli.name) + + print("\nPackaging Assembly ----------") + package_data_assembly(assembly, data_assembly_name=assembly.name, stimulus_set_name=stimuli.name) + + +if __name__ == '__main__': + main() From ebe7d0c03909622c7fccfb62a2f484b921292376 Mon Sep 17 00:00:00 2001 From: shashikg Date: Thu, 4 Jun 2020 13:22:31 +0530 Subject: [PATCH 2/4] add klabZhang2018 visual search stimuli for waldo and naturaldesign --- .gitignore | 4 + mkgu_packaging/klab/search_naturaldesign.py | 117 ++++++++++++++++++++ mkgu_packaging/klab/search_obj_array.py | 4 + mkgu_packaging/klab/search_waldo.py | 117 ++++++++++++++++++++ 4 files changed, 242 insertions(+) create mode 100644 mkgu_packaging/klab/search_naturaldesign.py create mode 100644 mkgu_packaging/klab/search_waldo.py diff --git a/.gitignore b/.gitignore index f14a889..7cb5866 100755 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ # Data files mkgu_packaging/klab/search_datasets* + +brainio_contrib.egg-info* +build* +dist* diff --git a/mkgu_packaging/klab/search_naturaldesign.py b/mkgu_packaging/klab/search_naturaldesign.py new file mode 100644 index 0000000..4078fb2 --- /dev/null +++ b/mkgu_packaging/klab/search_naturaldesign.py @@ -0,0 +1,117 @@ +import os + +import h5py +import numpy as np +import pandas as pd +import scipy.misc +import xarray as xr +from pathlib import Path +from result_caching import store +from sklearn.model_selection import StratifiedShuffleSplit +from tqdm import tqdm +from scipy.io import loadmat + +from brainio_base.assemblies import BehavioralAssembly +from brainio_base.stimuli import StimulusSet +from brainio_contrib.packaging import package_stimulus_set, package_data_assembly + +def collect_stimuli(data_path): + stimuli = [] + + # search images + for i in range(1, 241): + target_path = os.path.join(data_path / 'stimuli', 's_' + str(i) + '.jpg') + filename = 's_' + str(i) + '.jpg' + image_id = 'stimuli_' + str(i) + image_label = 'stimuli' + sample_number = i + + stimuli.append({ + 'image_current_local_file_path': target_path, + 'image_path_within_store': filename, + 'image_label': image_label, + 'image_id': image_id, + 'sample_number': sample_number, + }) + + # target images + for i in range(1, 241): + target_path = os.path.join(data_path / 'target', 't_' + str(i) + '.jpg') + filename = 't_' + str(i) + '.jpg' + image_id = 'target_' + str(i) + image_label = 'target' + sample_number = i + + stimuli.append({ + 'image_current_local_file_path': target_path, + 'image_path_within_store': filename, + 'image_label': image_label, + 'image_id': image_id, + 'sample_number': sample_number, + }) + + # target mask + for i in range(1, 241): + target_path = os.path.join(data_path / 'gt', 'gt_' + str(i) + '.jpg') + filename = 'gt' + str(i) + '.jpg' + image_id = 'gt_' + str(i) + image_label = 'gt' + sample_number = i + + stimuli.append({ + 'image_current_local_file_path': target_path, + 'image_path_within_store': filename, + 'image_label': image_label, + 'image_id': image_id, + 'sample_number': sample_number, + }) + + stimuli = StimulusSet(stimuli) + + stimuli.image_paths = {row.image_id: row.image_current_local_file_path for row in stimuli.itertuples()} + stimuli['image_file_name']= stimuli['image_path_within_store'] + + return stimuli + +def collect_data(data_path, sub_id): + image_id = ['stimuli_' + str(i) for i in range(1, 241)] + subjects = [] + for i in sub_id: + subjects += [i]*len(image_id) + + S_data = np.load(os.path.join(data_path / 'human_data', 'human_all.npy')) + I_data = np.load(os.path.join(data_path / 'human_data', 'I_human_all.npy')) + data = np.zeros((240*len(sub_id), 66, 2), dtype=int) + data[:,:65,:] = S_data + data[:,65,:] = I_data + + assembly = BehavioralAssembly(data, + coords={'image_id': ('presentation', image_id*len(sub_id)), + 'subjects': ('presentation', subjects), + 'fixation': [*range(66)], + 'position': ['x', 'y']}, + dims=['presentation', 'fixation', 'position']) + return assembly + +def main(): + data_dir = Path(__file__).parent / 'search_datasets' + data_path = data_dir / 'naturaldesign' + + # create stimuli + stimuli = collect_stimuli(data_path) + stimuli.name = 'klab.Zhang2018.search_naturaldesign' + + # create assembly for different subjects + assembly = collect_data(data_path, [*range(1, 16)]) + assembly.name = 'klab.Zhang2018search_naturaldesign' + + # package + print("\nPackaging Stimuli ----------") + package_stimulus_set(stimuli, stimulus_set_name=stimuli.name) + + print("\nPackaging Assembly ----------") + package_data_assembly(assembly, data_assembly_name=assembly.name, stimulus_set_name=stimuli.name) + + +if __name__ == '__main__': + main() diff --git a/mkgu_packaging/klab/search_obj_array.py b/mkgu_packaging/klab/search_obj_array.py index 6929209..ed729cb 100755 --- a/mkgu_packaging/klab/search_obj_array.py +++ b/mkgu_packaging/klab/search_obj_array.py @@ -71,6 +71,10 @@ def collect_stimuli(data_path): }) stimuli = StimulusSet(stimuli) + + stimuli.image_paths = {row.image_id: row.image_current_local_file_path for row in stimuli.itertuples()} + stimuli['image_file_name']= stimuli['image_path_within_store'] + return stimuli def collect_data(data_path, sub_id): diff --git a/mkgu_packaging/klab/search_waldo.py b/mkgu_packaging/klab/search_waldo.py new file mode 100644 index 0000000..d1c7c62 --- /dev/null +++ b/mkgu_packaging/klab/search_waldo.py @@ -0,0 +1,117 @@ +import os + +import h5py +import numpy as np +import pandas as pd +import scipy.misc +import xarray as xr +from pathlib import Path +from result_caching import store +from sklearn.model_selection import StratifiedShuffleSplit +from tqdm import tqdm +from scipy.io import loadmat + +from brainio_base.assemblies import BehavioralAssembly +from brainio_base.stimuli import StimulusSet +from brainio_contrib.packaging import package_stimulus_set, package_data_assembly + +def collect_stimuli(data_path): + stimuli = [] + + # search images + for i in range(1, 68): + target_path = os.path.join(data_path / 'stimuli', 's_' + str(i) + '.jpg') + filename = 's_' + str(i) + '.jpg' + image_id = 'stimuli_' + str(i) + image_label = 'stimuli' + sample_number = i + + stimuli.append({ + 'image_current_local_file_path': target_path, + 'image_path_within_store': filename, + 'image_label': image_label, + 'image_id': image_id, + 'sample_number': sample_number, + }) + + # target images + for i in range(1, 68): + target_path = os.path.join(data_path / 'target', 't_' + str(i) + '.jpg') + filename = 't_' + str(i) + '.jpg' + image_id = 'target_' + str(i) + image_label = 'target' + sample_number = i + + stimuli.append({ + 'image_current_local_file_path': target_path, + 'image_path_within_store': filename, + 'image_label': image_label, + 'image_id': image_id, + 'sample_number': sample_number, + }) + + # target mask + for i in range(1, 68): + target_path = os.path.join(data_path / 'gt', 'gt_' + str(i) + '.jpg') + filename = 'gt' + str(i) + '.jpg' + image_id = 'gt_' + str(i) + image_label = 'gt' + sample_number = i + + stimuli.append({ + 'image_current_local_file_path': target_path, + 'image_path_within_store': filename, + 'image_label': image_label, + 'image_id': image_id, + 'sample_number': sample_number, + }) + + stimuli = StimulusSet(stimuli) + + stimuli.image_paths = {row.image_id: row.image_current_local_file_path for row in stimuli.itertuples()} + stimuli['image_file_name']= stimuli['image_path_within_store'] + + return stimuli + +def collect_data(data_path, sub_id): + image_id = ['stimuli_' + str(i) for i in range(1, 68)] + subjects = [] + for i in sub_id: + subjects += [i]*len(image_id) + + S_data = np.load(os.path.join(data_path / 'human_data', 'human_all.npy')) + I_data = np.load(os.path.join(data_path / 'human_data', 'I_human_all.npy')) + data = np.zeros((67*len(sub_id), 81, 2), dtype=int) + data[:,:80,:] = S_data + data[:,80,:] = I_data + + assembly = BehavioralAssembly(data, + coords={'image_id': ('presentation', image_id*len(sub_id)), + 'subjects': ('presentation', subjects), + 'fixation': [*range(81)], + 'position': ['x', 'y']}, + dims=['presentation', 'fixation', 'position']) + return assembly + +def main(): + data_dir = Path(__file__).parent / 'search_datasets' + data_path = data_dir / 'waldo' + + # create stimuli + stimuli = collect_stimuli(data_path) + stimuli.name = 'klab.Zhang2018.search_waldo' + + # create assembly for different subjects + assembly = collect_data(data_path, [*range(1, 16)]) + assembly.name = 'klab.Zhang2018search_waldo' + + # package + print("\nPackaging Stimuli ----------") + package_stimulus_set(stimuli, stimulus_set_name=stimuli.name) + + print("\nPackaging Assembly ----------") + package_data_assembly(assembly, data_assembly_name=assembly.name, stimulus_set_name=stimuli.name) + + +if __name__ == '__main__': + main() From e7e356cf473795959032f02f76556815dba3d009 Mon Sep 17 00:00:00 2001 From: shashikg Date: Thu, 4 Jun 2020 20:52:25 +0530 Subject: [PATCH 3/4] changed image id --- .gitignore | 1 + mkgu_packaging/klab/Untitled2.ipynb | 663 ++++++++++++++++++++ mkgu_packaging/klab/search_naturaldesign.py | 11 +- mkgu_packaging/klab/search_waldo.py | 8 +- 4 files changed, 674 insertions(+), 9 deletions(-) create mode 100644 mkgu_packaging/klab/Untitled2.ipynb diff --git a/.gitignore b/.gitignore index 7cb5866..6607600 100755 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ mkgu_packaging/klab/search_datasets* brainio_contrib.egg-info* build* dist* +.ipynb_checkpoints* diff --git a/mkgu_packaging/klab/Untitled2.ipynb b/mkgu_packaging/klab/Untitled2.ipynb new file mode 100644 index 0000000..e9fd584 --- /dev/null +++ b/mkgu_packaging/klab/Untitled2.ipynb @@ -0,0 +1,663 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "search_datasets/waldo/stimuli/s_1.jpg s_1.jpg klab_vs_waldo_stimuli_1\n", + "search_datasets/waldo/stimuli/s_2.jpg s_2.jpg klab_vs_waldo_stimuli_2\n", + "search_datasets/waldo/stimuli/s_3.jpg s_3.jpg klab_vs_waldo_stimuli_3\n", + "search_datasets/waldo/stimuli/s_4.jpg s_4.jpg klab_vs_waldo_stimuli_4\n", + "search_datasets/waldo/stimuli/s_5.jpg s_5.jpg klab_vs_waldo_stimuli_5\n", + "search_datasets/waldo/stimuli/s_6.jpg s_6.jpg klab_vs_waldo_stimuli_6\n", + "search_datasets/waldo/stimuli/s_7.jpg s_7.jpg klab_vs_waldo_stimuli_7\n", + "search_datasets/waldo/stimuli/s_8.jpg s_8.jpg klab_vs_waldo_stimuli_8\n", + "search_datasets/waldo/stimuli/s_9.jpg s_9.jpg klab_vs_waldo_stimuli_9\n", + "search_datasets/waldo/stimuli/s_10.jpg s_10.jpg klab_vs_waldo_stimuli_10\n", + "search_datasets/waldo/stimuli/s_11.jpg s_11.jpg klab_vs_waldo_stimuli_11\n", + "search_datasets/waldo/stimuli/s_12.jpg s_12.jpg klab_vs_waldo_stimuli_12\n", + "search_datasets/waldo/stimuli/s_13.jpg s_13.jpg klab_vs_waldo_stimuli_13\n", + "search_datasets/waldo/stimuli/s_14.jpg s_14.jpg klab_vs_waldo_stimuli_14\n", + "search_datasets/waldo/stimuli/s_15.jpg s_15.jpg klab_vs_waldo_stimuli_15\n", + "search_datasets/waldo/stimuli/s_16.jpg s_16.jpg klab_vs_waldo_stimuli_16\n", + "search_datasets/waldo/stimuli/s_17.jpg s_17.jpg klab_vs_waldo_stimuli_17\n", + "search_datasets/waldo/stimuli/s_18.jpg s_18.jpg klab_vs_waldo_stimuli_18\n", + "search_datasets/waldo/stimuli/s_19.jpg s_19.jpg klab_vs_waldo_stimuli_19\n", + "search_datasets/waldo/stimuli/s_20.jpg s_20.jpg klab_vs_waldo_stimuli_20\n", + "search_datasets/waldo/stimuli/s_21.jpg s_21.jpg klab_vs_waldo_stimuli_21\n", + "search_datasets/waldo/stimuli/s_22.jpg s_22.jpg klab_vs_waldo_stimuli_22\n", + "search_datasets/waldo/stimuli/s_23.jpg s_23.jpg klab_vs_waldo_stimuli_23\n", + "search_datasets/waldo/stimuli/s_24.jpg s_24.jpg klab_vs_waldo_stimuli_24\n", + "search_datasets/waldo/stimuli/s_25.jpg s_25.jpg klab_vs_waldo_stimuli_25\n", + "search_datasets/waldo/stimuli/s_26.jpg s_26.jpg klab_vs_waldo_stimuli_26\n", + "search_datasets/waldo/stimuli/s_27.jpg s_27.jpg klab_vs_waldo_stimuli_27\n", + "search_datasets/waldo/stimuli/s_28.jpg s_28.jpg klab_vs_waldo_stimuli_28\n", + "search_datasets/waldo/stimuli/s_29.jpg s_29.jpg klab_vs_waldo_stimuli_29\n", + "search_datasets/waldo/stimuli/s_30.jpg s_30.jpg klab_vs_waldo_stimuli_30\n", + "search_datasets/waldo/stimuli/s_31.jpg s_31.jpg klab_vs_waldo_stimuli_31\n", + "search_datasets/waldo/stimuli/s_32.jpg s_32.jpg klab_vs_waldo_stimuli_32\n", + "search_datasets/waldo/stimuli/s_33.jpg s_33.jpg klab_vs_waldo_stimuli_33\n", + "search_datasets/waldo/stimuli/s_34.jpg s_34.jpg klab_vs_waldo_stimuli_34\n", + "search_datasets/waldo/stimuli/s_35.jpg s_35.jpg klab_vs_waldo_stimuli_35\n", + "search_datasets/waldo/stimuli/s_36.jpg s_36.jpg klab_vs_waldo_stimuli_36\n", + "search_datasets/waldo/stimuli/s_37.jpg s_37.jpg klab_vs_waldo_stimuli_37\n", + "search_datasets/waldo/stimuli/s_38.jpg s_38.jpg klab_vs_waldo_stimuli_38\n", + "search_datasets/waldo/stimuli/s_39.jpg s_39.jpg klab_vs_waldo_stimuli_39\n", + "search_datasets/waldo/stimuli/s_40.jpg s_40.jpg klab_vs_waldo_stimuli_40\n", + "search_datasets/waldo/stimuli/s_41.jpg s_41.jpg klab_vs_waldo_stimuli_41\n", + "search_datasets/waldo/stimuli/s_42.jpg s_42.jpg klab_vs_waldo_stimuli_42\n", + "search_datasets/waldo/stimuli/s_43.jpg s_43.jpg klab_vs_waldo_stimuli_43\n", + "search_datasets/waldo/stimuli/s_44.jpg s_44.jpg klab_vs_waldo_stimuli_44\n", + "search_datasets/waldo/stimuli/s_45.jpg s_45.jpg klab_vs_waldo_stimuli_45\n", + "search_datasets/waldo/stimuli/s_46.jpg s_46.jpg klab_vs_waldo_stimuli_46\n", + "search_datasets/waldo/stimuli/s_47.jpg s_47.jpg klab_vs_waldo_stimuli_47\n", + "search_datasets/waldo/stimuli/s_48.jpg s_48.jpg klab_vs_waldo_stimuli_48\n", + "search_datasets/waldo/stimuli/s_49.jpg s_49.jpg klab_vs_waldo_stimuli_49\n", + "search_datasets/waldo/stimuli/s_50.jpg s_50.jpg klab_vs_waldo_stimuli_50\n", + "search_datasets/waldo/stimuli/s_51.jpg s_51.jpg klab_vs_waldo_stimuli_51\n", + "search_datasets/waldo/stimuli/s_52.jpg s_52.jpg klab_vs_waldo_stimuli_52\n", + "search_datasets/waldo/stimuli/s_53.jpg s_53.jpg klab_vs_waldo_stimuli_53\n", + "search_datasets/waldo/stimuli/s_54.jpg s_54.jpg klab_vs_waldo_stimuli_54\n", + "search_datasets/waldo/stimuli/s_55.jpg s_55.jpg klab_vs_waldo_stimuli_55\n", + "search_datasets/waldo/stimuli/s_56.jpg s_56.jpg klab_vs_waldo_stimuli_56\n", + "search_datasets/waldo/stimuli/s_57.jpg s_57.jpg klab_vs_waldo_stimuli_57\n", + "search_datasets/waldo/stimuli/s_58.jpg s_58.jpg klab_vs_waldo_stimuli_58\n", + "search_datasets/waldo/stimuli/s_59.jpg s_59.jpg klab_vs_waldo_stimuli_59\n", + "search_datasets/waldo/stimuli/s_60.jpg s_60.jpg klab_vs_waldo_stimuli_60\n", + "search_datasets/waldo/stimuli/s_61.jpg s_61.jpg klab_vs_waldo_stimuli_61\n", + "search_datasets/waldo/stimuli/s_62.jpg s_62.jpg klab_vs_waldo_stimuli_62\n", + "search_datasets/waldo/stimuli/s_63.jpg s_63.jpg klab_vs_waldo_stimuli_63\n", + "search_datasets/waldo/stimuli/s_64.jpg s_64.jpg klab_vs_waldo_stimuli_64\n", + "search_datasets/waldo/stimuli/s_65.jpg s_65.jpg klab_vs_waldo_stimuli_65\n", + "search_datasets/waldo/stimuli/s_66.jpg s_66.jpg klab_vs_waldo_stimuli_66\n", + "search_datasets/waldo/stimuli/s_67.jpg s_67.jpg klab_vs_waldo_stimuli_67\n", + "search_datasets/waldo/target/t_1.jpg t_1.jpg klab_vs_waldo_target_1\n", + "search_datasets/waldo/target/t_2.jpg t_2.jpg klab_vs_waldo_target_2\n", + "search_datasets/waldo/target/t_3.jpg t_3.jpg klab_vs_waldo_target_3\n", + "search_datasets/waldo/target/t_4.jpg t_4.jpg klab_vs_waldo_target_4\n", + "search_datasets/waldo/target/t_5.jpg t_5.jpg klab_vs_waldo_target_5\n", + "search_datasets/waldo/target/t_6.jpg t_6.jpg klab_vs_waldo_target_6\n", + "search_datasets/waldo/target/t_7.jpg t_7.jpg klab_vs_waldo_target_7\n", + "search_datasets/waldo/target/t_8.jpg t_8.jpg klab_vs_waldo_target_8\n", + "search_datasets/waldo/target/t_9.jpg t_9.jpg klab_vs_waldo_target_9\n", + "search_datasets/waldo/target/t_10.jpg t_10.jpg klab_vs_waldo_target_10\n", + "search_datasets/waldo/target/t_11.jpg t_11.jpg klab_vs_waldo_target_11\n", + "search_datasets/waldo/target/t_12.jpg t_12.jpg klab_vs_waldo_target_12\n", + "search_datasets/waldo/target/t_13.jpg t_13.jpg klab_vs_waldo_target_13\n", + "search_datasets/waldo/target/t_14.jpg t_14.jpg klab_vs_waldo_target_14\n", + "search_datasets/waldo/target/t_15.jpg t_15.jpg klab_vs_waldo_target_15\n", + "search_datasets/waldo/target/t_16.jpg t_16.jpg klab_vs_waldo_target_16\n", + "search_datasets/waldo/target/t_17.jpg t_17.jpg klab_vs_waldo_target_17\n", + "search_datasets/waldo/target/t_18.jpg t_18.jpg klab_vs_waldo_target_18\n", + "search_datasets/waldo/target/t_19.jpg t_19.jpg klab_vs_waldo_target_19\n", + "search_datasets/waldo/target/t_20.jpg t_20.jpg klab_vs_waldo_target_20\n", + "search_datasets/waldo/target/t_21.jpg t_21.jpg klab_vs_waldo_target_21\n", + "search_datasets/waldo/target/t_22.jpg t_22.jpg klab_vs_waldo_target_22\n", + "search_datasets/waldo/target/t_23.jpg t_23.jpg klab_vs_waldo_target_23\n", + "search_datasets/waldo/target/t_24.jpg t_24.jpg klab_vs_waldo_target_24\n", + "search_datasets/waldo/target/t_25.jpg t_25.jpg klab_vs_waldo_target_25\n", + "search_datasets/waldo/target/t_26.jpg t_26.jpg klab_vs_waldo_target_26\n", + "search_datasets/waldo/target/t_27.jpg t_27.jpg klab_vs_waldo_target_27\n", + "search_datasets/waldo/target/t_28.jpg t_28.jpg klab_vs_waldo_target_28\n", + "search_datasets/waldo/target/t_29.jpg t_29.jpg klab_vs_waldo_target_29\n", + "search_datasets/waldo/target/t_30.jpg t_30.jpg klab_vs_waldo_target_30\n", + "search_datasets/waldo/target/t_31.jpg t_31.jpg klab_vs_waldo_target_31\n", + "search_datasets/waldo/target/t_32.jpg t_32.jpg klab_vs_waldo_target_32\n", + "search_datasets/waldo/target/t_33.jpg t_33.jpg klab_vs_waldo_target_33\n", + "search_datasets/waldo/target/t_34.jpg t_34.jpg klab_vs_waldo_target_34\n", + "search_datasets/waldo/target/t_35.jpg t_35.jpg klab_vs_waldo_target_35\n", + "search_datasets/waldo/target/t_36.jpg t_36.jpg klab_vs_waldo_target_36\n", + "search_datasets/waldo/target/t_37.jpg t_37.jpg klab_vs_waldo_target_37\n", + "search_datasets/waldo/target/t_38.jpg t_38.jpg klab_vs_waldo_target_38\n", + "search_datasets/waldo/target/t_39.jpg t_39.jpg klab_vs_waldo_target_39\n", + "search_datasets/waldo/target/t_40.jpg t_40.jpg klab_vs_waldo_target_40\n", + "search_datasets/waldo/target/t_41.jpg t_41.jpg klab_vs_waldo_target_41\n", + "search_datasets/waldo/target/t_42.jpg t_42.jpg klab_vs_waldo_target_42\n", + "search_datasets/waldo/target/t_43.jpg t_43.jpg klab_vs_waldo_target_43\n", + "search_datasets/waldo/target/t_44.jpg t_44.jpg klab_vs_waldo_target_44\n", + "search_datasets/waldo/target/t_45.jpg t_45.jpg klab_vs_waldo_target_45\n", + "search_datasets/waldo/target/t_46.jpg t_46.jpg klab_vs_waldo_target_46\n", + "search_datasets/waldo/target/t_47.jpg t_47.jpg klab_vs_waldo_target_47\n", + "search_datasets/waldo/target/t_48.jpg t_48.jpg klab_vs_waldo_target_48\n", + "search_datasets/waldo/target/t_49.jpg t_49.jpg klab_vs_waldo_target_49\n", + "search_datasets/waldo/target/t_50.jpg t_50.jpg klab_vs_waldo_target_50\n", + "search_datasets/waldo/target/t_51.jpg t_51.jpg klab_vs_waldo_target_51\n", + "search_datasets/waldo/target/t_52.jpg t_52.jpg klab_vs_waldo_target_52\n", + "search_datasets/waldo/target/t_53.jpg t_53.jpg klab_vs_waldo_target_53\n", + "search_datasets/waldo/target/t_54.jpg t_54.jpg klab_vs_waldo_target_54\n", + "search_datasets/waldo/target/t_55.jpg t_55.jpg klab_vs_waldo_target_55\n", + "search_datasets/waldo/target/t_56.jpg t_56.jpg klab_vs_waldo_target_56\n", + "search_datasets/waldo/target/t_57.jpg t_57.jpg klab_vs_waldo_target_57\n", + "search_datasets/waldo/target/t_58.jpg t_58.jpg klab_vs_waldo_target_58\n", + "search_datasets/waldo/target/t_59.jpg t_59.jpg klab_vs_waldo_target_59\n", + "search_datasets/waldo/target/t_60.jpg t_60.jpg klab_vs_waldo_target_60\n", + "search_datasets/waldo/target/t_61.jpg t_61.jpg klab_vs_waldo_target_61\n", + "search_datasets/waldo/target/t_62.jpg t_62.jpg klab_vs_waldo_target_62\n", + "search_datasets/waldo/target/t_63.jpg t_63.jpg klab_vs_waldo_target_63\n", + "search_datasets/waldo/target/t_64.jpg t_64.jpg klab_vs_waldo_target_64\n", + "search_datasets/waldo/target/t_65.jpg t_65.jpg klab_vs_waldo_target_65\n", + "search_datasets/waldo/target/t_66.jpg t_66.jpg klab_vs_waldo_target_66\n", + "search_datasets/waldo/target/t_67.jpg t_67.jpg klab_vs_waldo_target_67\n", + "search_datasets/waldo/gt/gt_1.jpg gt_1.jpg klab_vs_waldo_gt_1\n", + "search_datasets/waldo/gt/gt_2.jpg gt_2.jpg klab_vs_waldo_gt_2\n", + "search_datasets/waldo/gt/gt_3.jpg gt_3.jpg klab_vs_waldo_gt_3\n", + "search_datasets/waldo/gt/gt_4.jpg gt_4.jpg klab_vs_waldo_gt_4\n", + "search_datasets/waldo/gt/gt_5.jpg gt_5.jpg klab_vs_waldo_gt_5\n", + "search_datasets/waldo/gt/gt_6.jpg gt_6.jpg klab_vs_waldo_gt_6\n", + "search_datasets/waldo/gt/gt_7.jpg gt_7.jpg klab_vs_waldo_gt_7\n", + "search_datasets/waldo/gt/gt_8.jpg gt_8.jpg klab_vs_waldo_gt_8\n", + "search_datasets/waldo/gt/gt_9.jpg gt_9.jpg klab_vs_waldo_gt_9\n", + "search_datasets/waldo/gt/gt_10.jpg gt_10.jpg klab_vs_waldo_gt_10\n", + "search_datasets/waldo/gt/gt_11.jpg gt_11.jpg klab_vs_waldo_gt_11\n", + "search_datasets/waldo/gt/gt_12.jpg gt_12.jpg klab_vs_waldo_gt_12\n", + "search_datasets/waldo/gt/gt_13.jpg gt_13.jpg klab_vs_waldo_gt_13\n", + "search_datasets/waldo/gt/gt_14.jpg gt_14.jpg klab_vs_waldo_gt_14\n", + "search_datasets/waldo/gt/gt_15.jpg gt_15.jpg klab_vs_waldo_gt_15\n", + "search_datasets/waldo/gt/gt_16.jpg gt_16.jpg klab_vs_waldo_gt_16\n", + "search_datasets/waldo/gt/gt_17.jpg gt_17.jpg klab_vs_waldo_gt_17\n", + "search_datasets/waldo/gt/gt_18.jpg gt_18.jpg klab_vs_waldo_gt_18\n", + "search_datasets/waldo/gt/gt_19.jpg gt_19.jpg klab_vs_waldo_gt_19\n", + "search_datasets/waldo/gt/gt_20.jpg gt_20.jpg klab_vs_waldo_gt_20\n", + "search_datasets/waldo/gt/gt_21.jpg gt_21.jpg klab_vs_waldo_gt_21\n", + "search_datasets/waldo/gt/gt_22.jpg gt_22.jpg klab_vs_waldo_gt_22\n", + "search_datasets/waldo/gt/gt_23.jpg gt_23.jpg klab_vs_waldo_gt_23\n", + "search_datasets/waldo/gt/gt_24.jpg gt_24.jpg klab_vs_waldo_gt_24\n", + "search_datasets/waldo/gt/gt_25.jpg gt_25.jpg klab_vs_waldo_gt_25\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "search_datasets/waldo/gt/gt_26.jpg gt_26.jpg klab_vs_waldo_gt_26\n", + "search_datasets/waldo/gt/gt_27.jpg gt_27.jpg klab_vs_waldo_gt_27\n", + "search_datasets/waldo/gt/gt_28.jpg gt_28.jpg klab_vs_waldo_gt_28\n", + "search_datasets/waldo/gt/gt_29.jpg gt_29.jpg klab_vs_waldo_gt_29\n", + "search_datasets/waldo/gt/gt_30.jpg gt_30.jpg klab_vs_waldo_gt_30\n", + "search_datasets/waldo/gt/gt_31.jpg gt_31.jpg klab_vs_waldo_gt_31\n", + "search_datasets/waldo/gt/gt_32.jpg gt_32.jpg klab_vs_waldo_gt_32\n", + "search_datasets/waldo/gt/gt_33.jpg gt_33.jpg klab_vs_waldo_gt_33\n", + "search_datasets/waldo/gt/gt_34.jpg gt_34.jpg klab_vs_waldo_gt_34\n", + "search_datasets/waldo/gt/gt_35.jpg gt_35.jpg klab_vs_waldo_gt_35\n", + "search_datasets/waldo/gt/gt_36.jpg gt_36.jpg klab_vs_waldo_gt_36\n", + "search_datasets/waldo/gt/gt_37.jpg gt_37.jpg klab_vs_waldo_gt_37\n", + "search_datasets/waldo/gt/gt_38.jpg gt_38.jpg klab_vs_waldo_gt_38\n", + "search_datasets/waldo/gt/gt_39.jpg gt_39.jpg klab_vs_waldo_gt_39\n", + "search_datasets/waldo/gt/gt_40.jpg gt_40.jpg klab_vs_waldo_gt_40\n", + "search_datasets/waldo/gt/gt_41.jpg gt_41.jpg klab_vs_waldo_gt_41\n", + "search_datasets/waldo/gt/gt_42.jpg gt_42.jpg klab_vs_waldo_gt_42\n", + "search_datasets/waldo/gt/gt_43.jpg gt_43.jpg klab_vs_waldo_gt_43\n", + "search_datasets/waldo/gt/gt_44.jpg gt_44.jpg klab_vs_waldo_gt_44\n", + "search_datasets/waldo/gt/gt_45.jpg gt_45.jpg klab_vs_waldo_gt_45\n", + "search_datasets/waldo/gt/gt_46.jpg gt_46.jpg klab_vs_waldo_gt_46\n", + "search_datasets/waldo/gt/gt_47.jpg gt_47.jpg klab_vs_waldo_gt_47\n", + "search_datasets/waldo/gt/gt_48.jpg gt_48.jpg klab_vs_waldo_gt_48\n", + "search_datasets/waldo/gt/gt_49.jpg gt_49.jpg klab_vs_waldo_gt_49\n", + "search_datasets/waldo/gt/gt_50.jpg gt_50.jpg klab_vs_waldo_gt_50\n", + "search_datasets/waldo/gt/gt_51.jpg gt_51.jpg klab_vs_waldo_gt_51\n", + "search_datasets/waldo/gt/gt_52.jpg gt_52.jpg klab_vs_waldo_gt_52\n", + "search_datasets/waldo/gt/gt_53.jpg gt_53.jpg klab_vs_waldo_gt_53\n", + "search_datasets/waldo/gt/gt_54.jpg gt_54.jpg klab_vs_waldo_gt_54\n", + "search_datasets/waldo/gt/gt_55.jpg gt_55.jpg klab_vs_waldo_gt_55\n", + "search_datasets/waldo/gt/gt_56.jpg gt_56.jpg klab_vs_waldo_gt_56\n", + "search_datasets/waldo/gt/gt_57.jpg gt_57.jpg klab_vs_waldo_gt_57\n", + "search_datasets/waldo/gt/gt_58.jpg gt_58.jpg klab_vs_waldo_gt_58\n", + "search_datasets/waldo/gt/gt_59.jpg gt_59.jpg klab_vs_waldo_gt_59\n", + "search_datasets/waldo/gt/gt_60.jpg gt_60.jpg klab_vs_waldo_gt_60\n", + "search_datasets/waldo/gt/gt_61.jpg gt_61.jpg klab_vs_waldo_gt_61\n", + "search_datasets/waldo/gt/gt_62.jpg gt_62.jpg klab_vs_waldo_gt_62\n", + "search_datasets/waldo/gt/gt_63.jpg gt_63.jpg klab_vs_waldo_gt_63\n", + "search_datasets/waldo/gt/gt_64.jpg gt_64.jpg klab_vs_waldo_gt_64\n", + "search_datasets/waldo/gt/gt_65.jpg gt_65.jpg klab_vs_waldo_gt_65\n", + "search_datasets/waldo/gt/gt_66.jpg gt_66.jpg klab_vs_waldo_gt_66\n", + "search_datasets/waldo/gt/gt_67.jpg gt_67.jpg klab_vs_waldo_gt_67\n" + ] + } + ], + "source": [ + "import os\n", + "\n", + "import h5py\n", + "import numpy as np\n", + "import pandas as pd\n", + "import scipy.misc\n", + "import xarray as xr\n", + "from pathlib import Path\n", + "from result_caching import store\n", + "from sklearn.model_selection import StratifiedShuffleSplit\n", + "from tqdm import tqdm\n", + "from scipy.io import loadmat\n", + "from brainio_collection.knownfile import KnownFile as kf\n", + "\n", + "from brainio_base.assemblies import BehavioralAssembly\n", + "from brainio_base.stimuli import StimulusSet\n", + "from brainio_contrib.packaging import package_stimulus_set, package_data_assembly\n", + "\n", + "def collect_stimuli(data_path):\n", + " stimuli = []\n", + "\n", + " # search images\n", + " for i in range(1, 68):\n", + " target_path = os.path.join(data_path / 'stimuli', 's_' + str(i) + '.jpg')\n", + " filename = 's_' + str(i) + '.jpg'\n", + " im_kf = kf(target_path)\n", + " image_id = 'klab_vs_waldo_stimuli_' + str(i)\n", + " image_label = 'stimuli'\n", + " sample_number = i\n", + " \n", + " print(target_path, filename, image_id)\n", + "\n", + "\n", + " stimuli.append({\n", + " 'image_current_local_file_path': target_path,\n", + " 'image_path_within_store': filename,\n", + " 'image_label': image_label,\n", + " 'image_id': image_id,\n", + " 'sample_number': sample_number,\n", + " })\n", + "\n", + " # target images\n", + " for i in range(1, 68):\n", + " target_path = os.path.join(data_path / 'target', 't_' + str(i) + '.jpg')\n", + " filename = 't_' + str(i) + '.jpg'\n", + " im_kf = kf(target_path)\n", + " image_id = 'klab_vs_waldo_target_' + str(i)\n", + " image_label = 'target'\n", + " sample_number = i\n", + " \n", + " print(target_path, filename, image_id)\n", + "\n", + " stimuli.append({\n", + " 'image_current_local_file_path': target_path,\n", + " 'image_path_within_store': filename,\n", + " 'image_label': image_label,\n", + " 'image_id': image_id,\n", + " 'sample_number': sample_number,\n", + " })\n", + "\n", + " # target mask\n", + " for i in range(1, 68):\n", + " target_path = os.path.join(data_path / 'gt', 'gt_' + str(i) + '.jpg')\n", + " filename = 'gt_' + str(i) + '.jpg'\n", + " im_kf = kf(target_path)\n", + " image_id = 'klab_vs_waldo_gt_' + str(i)\n", + " image_label = 'gt'\n", + " sample_number = i\n", + " \n", + " print(target_path, filename, image_id)\n", + " \n", + "\n", + " stimuli.append({\n", + " 'image_current_local_file_path': target_path,\n", + " 'image_path_within_store': filename,\n", + " 'image_label': image_label,\n", + " 'image_id': image_id,\n", + " 'sample_number': sample_number,\n", + " })\n", + "\n", + " stimuli = StimulusSet(stimuli)\n", + "\n", + " stimuli.image_paths = {row.image_id: row.image_current_local_file_path for row in stimuli.itertuples()}\n", + " stimuli['image_file_name']= stimuli['image_path_within_store']\n", + "\n", + " return stimuli\n", + "\n", + "def collect_data(data_path, sub_id):\n", + " image_id = ['stimuli_' + str(i) for i in range(1, 68)]\n", + " subjects = []\n", + " for i in sub_id:\n", + " subjects += [i]*len(image_id)\n", + "\n", + " S_data = np.load(os.path.join(data_path / 'human_data', 'human_all.npy'))\n", + " I_data = np.load(os.path.join(data_path / 'human_data', 'I_human_all.npy'))\n", + " data = np.zeros((67*len(sub_id), 81, 2), dtype=int)\n", + " data[:,:80,:] = S_data\n", + " data[:,80,:] = I_data\n", + "\n", + " assembly = BehavioralAssembly(data,\n", + " coords={'image_id': ('presentation', image_id*len(sub_id)),\n", + " 'subjects': ('presentation', subjects),\n", + " 'fixation': [*range(81)],\n", + " 'position': ['x', 'y']},\n", + " dims=['presentation', 'fixation', 'position'])\n", + " return assembly\n", + "\n", + "\n", + "data_dir = Path().parent / 'search_datasets'\n", + "data_path = data_dir / 'waldo'\n", + "\n", + "# create stimuli\n", + "stimuli = collect_stimuli(data_path)\n", + "stimuli.name = 'klab.Zhang2018.search_waldo'\n", + "\n", + "# create assembly for different subjects\n", + "assembly = collect_data(data_path, [*range(1, 16)])\n", + "assembly.name = 'klab.Zhang2018search_waldo'" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\n", + "array([[[ 542, 653],\n", + " [ 507, 534],\n", + " ...,\n", + " [ 0, 0],\n", + " [ 3, 3]],\n", + "\n", + " [[ 520, 655],\n", + " [ 490, 647],\n", + " ...,\n", + " [ 0, 0],\n", + " [ 9, 9]],\n", + "\n", + " ...,\n", + "\n", + " [[ 520, 654],\n", + " [ 380, 709],\n", + " ...,\n", + " [ 0, 0],\n", + " [ 10, 10]],\n", + "\n", + " [[ 510, 649],\n", + " [ 481, 500],\n", + " ...,\n", + " [ 142, 1157],\n", + " [ 80, 80]]])\n", + "Coordinates:\n", + " * fixation (fixation) int64 0 1 2 3 4 5 6 7 8 ... 73 74 75 76 77 78 79 80\n", + " * position (position) Date: Mon, 15 Jun 2020 18:04:45 +0530 Subject: [PATCH 4/4] remove notebook test file --- mkgu_packaging/klab/Untitled2.ipynb | 663 ---------------------------- 1 file changed, 663 deletions(-) delete mode 100644 mkgu_packaging/klab/Untitled2.ipynb diff --git a/mkgu_packaging/klab/Untitled2.ipynb b/mkgu_packaging/klab/Untitled2.ipynb deleted file mode 100644 index e9fd584..0000000 --- a/mkgu_packaging/klab/Untitled2.ipynb +++ /dev/null @@ -1,663 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "search_datasets/waldo/stimuli/s_1.jpg s_1.jpg klab_vs_waldo_stimuli_1\n", - "search_datasets/waldo/stimuli/s_2.jpg s_2.jpg klab_vs_waldo_stimuli_2\n", - "search_datasets/waldo/stimuli/s_3.jpg s_3.jpg klab_vs_waldo_stimuli_3\n", - "search_datasets/waldo/stimuli/s_4.jpg s_4.jpg klab_vs_waldo_stimuli_4\n", - "search_datasets/waldo/stimuli/s_5.jpg s_5.jpg klab_vs_waldo_stimuli_5\n", - "search_datasets/waldo/stimuli/s_6.jpg s_6.jpg klab_vs_waldo_stimuli_6\n", - "search_datasets/waldo/stimuli/s_7.jpg s_7.jpg klab_vs_waldo_stimuli_7\n", - "search_datasets/waldo/stimuli/s_8.jpg s_8.jpg klab_vs_waldo_stimuli_8\n", - "search_datasets/waldo/stimuli/s_9.jpg s_9.jpg klab_vs_waldo_stimuli_9\n", - "search_datasets/waldo/stimuli/s_10.jpg s_10.jpg klab_vs_waldo_stimuli_10\n", - "search_datasets/waldo/stimuli/s_11.jpg s_11.jpg klab_vs_waldo_stimuli_11\n", - "search_datasets/waldo/stimuli/s_12.jpg s_12.jpg klab_vs_waldo_stimuli_12\n", - "search_datasets/waldo/stimuli/s_13.jpg s_13.jpg klab_vs_waldo_stimuli_13\n", - "search_datasets/waldo/stimuli/s_14.jpg s_14.jpg klab_vs_waldo_stimuli_14\n", - "search_datasets/waldo/stimuli/s_15.jpg s_15.jpg klab_vs_waldo_stimuli_15\n", - "search_datasets/waldo/stimuli/s_16.jpg s_16.jpg klab_vs_waldo_stimuli_16\n", - "search_datasets/waldo/stimuli/s_17.jpg s_17.jpg klab_vs_waldo_stimuli_17\n", - "search_datasets/waldo/stimuli/s_18.jpg s_18.jpg klab_vs_waldo_stimuli_18\n", - "search_datasets/waldo/stimuli/s_19.jpg s_19.jpg klab_vs_waldo_stimuli_19\n", - "search_datasets/waldo/stimuli/s_20.jpg s_20.jpg klab_vs_waldo_stimuli_20\n", - "search_datasets/waldo/stimuli/s_21.jpg s_21.jpg klab_vs_waldo_stimuli_21\n", - "search_datasets/waldo/stimuli/s_22.jpg s_22.jpg klab_vs_waldo_stimuli_22\n", - "search_datasets/waldo/stimuli/s_23.jpg s_23.jpg klab_vs_waldo_stimuli_23\n", - "search_datasets/waldo/stimuli/s_24.jpg s_24.jpg klab_vs_waldo_stimuli_24\n", - "search_datasets/waldo/stimuli/s_25.jpg s_25.jpg klab_vs_waldo_stimuli_25\n", - "search_datasets/waldo/stimuli/s_26.jpg s_26.jpg klab_vs_waldo_stimuli_26\n", - "search_datasets/waldo/stimuli/s_27.jpg s_27.jpg klab_vs_waldo_stimuli_27\n", - "search_datasets/waldo/stimuli/s_28.jpg s_28.jpg klab_vs_waldo_stimuli_28\n", - "search_datasets/waldo/stimuli/s_29.jpg s_29.jpg klab_vs_waldo_stimuli_29\n", - "search_datasets/waldo/stimuli/s_30.jpg s_30.jpg klab_vs_waldo_stimuli_30\n", - "search_datasets/waldo/stimuli/s_31.jpg s_31.jpg klab_vs_waldo_stimuli_31\n", - "search_datasets/waldo/stimuli/s_32.jpg s_32.jpg klab_vs_waldo_stimuli_32\n", - "search_datasets/waldo/stimuli/s_33.jpg s_33.jpg klab_vs_waldo_stimuli_33\n", - "search_datasets/waldo/stimuli/s_34.jpg s_34.jpg klab_vs_waldo_stimuli_34\n", - "search_datasets/waldo/stimuli/s_35.jpg s_35.jpg klab_vs_waldo_stimuli_35\n", - "search_datasets/waldo/stimuli/s_36.jpg s_36.jpg klab_vs_waldo_stimuli_36\n", - "search_datasets/waldo/stimuli/s_37.jpg s_37.jpg klab_vs_waldo_stimuli_37\n", - "search_datasets/waldo/stimuli/s_38.jpg s_38.jpg klab_vs_waldo_stimuli_38\n", - "search_datasets/waldo/stimuli/s_39.jpg s_39.jpg klab_vs_waldo_stimuli_39\n", - "search_datasets/waldo/stimuli/s_40.jpg s_40.jpg klab_vs_waldo_stimuli_40\n", - "search_datasets/waldo/stimuli/s_41.jpg s_41.jpg klab_vs_waldo_stimuli_41\n", - "search_datasets/waldo/stimuli/s_42.jpg s_42.jpg klab_vs_waldo_stimuli_42\n", - "search_datasets/waldo/stimuli/s_43.jpg s_43.jpg klab_vs_waldo_stimuli_43\n", - "search_datasets/waldo/stimuli/s_44.jpg s_44.jpg klab_vs_waldo_stimuli_44\n", - "search_datasets/waldo/stimuli/s_45.jpg s_45.jpg klab_vs_waldo_stimuli_45\n", - "search_datasets/waldo/stimuli/s_46.jpg s_46.jpg klab_vs_waldo_stimuli_46\n", - "search_datasets/waldo/stimuli/s_47.jpg s_47.jpg klab_vs_waldo_stimuli_47\n", - "search_datasets/waldo/stimuli/s_48.jpg s_48.jpg klab_vs_waldo_stimuli_48\n", - "search_datasets/waldo/stimuli/s_49.jpg s_49.jpg klab_vs_waldo_stimuli_49\n", - "search_datasets/waldo/stimuli/s_50.jpg s_50.jpg klab_vs_waldo_stimuli_50\n", - "search_datasets/waldo/stimuli/s_51.jpg s_51.jpg klab_vs_waldo_stimuli_51\n", - "search_datasets/waldo/stimuli/s_52.jpg s_52.jpg klab_vs_waldo_stimuli_52\n", - "search_datasets/waldo/stimuli/s_53.jpg s_53.jpg klab_vs_waldo_stimuli_53\n", - "search_datasets/waldo/stimuli/s_54.jpg s_54.jpg klab_vs_waldo_stimuli_54\n", - "search_datasets/waldo/stimuli/s_55.jpg s_55.jpg klab_vs_waldo_stimuli_55\n", - "search_datasets/waldo/stimuli/s_56.jpg s_56.jpg klab_vs_waldo_stimuli_56\n", - "search_datasets/waldo/stimuli/s_57.jpg s_57.jpg klab_vs_waldo_stimuli_57\n", - "search_datasets/waldo/stimuli/s_58.jpg s_58.jpg klab_vs_waldo_stimuli_58\n", - "search_datasets/waldo/stimuli/s_59.jpg s_59.jpg klab_vs_waldo_stimuli_59\n", - "search_datasets/waldo/stimuli/s_60.jpg s_60.jpg klab_vs_waldo_stimuli_60\n", - "search_datasets/waldo/stimuli/s_61.jpg s_61.jpg klab_vs_waldo_stimuli_61\n", - "search_datasets/waldo/stimuli/s_62.jpg s_62.jpg klab_vs_waldo_stimuli_62\n", - "search_datasets/waldo/stimuli/s_63.jpg s_63.jpg klab_vs_waldo_stimuli_63\n", - "search_datasets/waldo/stimuli/s_64.jpg s_64.jpg klab_vs_waldo_stimuli_64\n", - "search_datasets/waldo/stimuli/s_65.jpg s_65.jpg klab_vs_waldo_stimuli_65\n", - "search_datasets/waldo/stimuli/s_66.jpg s_66.jpg klab_vs_waldo_stimuli_66\n", - "search_datasets/waldo/stimuli/s_67.jpg s_67.jpg klab_vs_waldo_stimuli_67\n", - "search_datasets/waldo/target/t_1.jpg t_1.jpg klab_vs_waldo_target_1\n", - "search_datasets/waldo/target/t_2.jpg t_2.jpg klab_vs_waldo_target_2\n", - "search_datasets/waldo/target/t_3.jpg t_3.jpg klab_vs_waldo_target_3\n", - "search_datasets/waldo/target/t_4.jpg t_4.jpg klab_vs_waldo_target_4\n", - "search_datasets/waldo/target/t_5.jpg t_5.jpg klab_vs_waldo_target_5\n", - "search_datasets/waldo/target/t_6.jpg t_6.jpg klab_vs_waldo_target_6\n", - "search_datasets/waldo/target/t_7.jpg t_7.jpg klab_vs_waldo_target_7\n", - "search_datasets/waldo/target/t_8.jpg t_8.jpg klab_vs_waldo_target_8\n", - "search_datasets/waldo/target/t_9.jpg t_9.jpg klab_vs_waldo_target_9\n", - "search_datasets/waldo/target/t_10.jpg t_10.jpg klab_vs_waldo_target_10\n", - "search_datasets/waldo/target/t_11.jpg t_11.jpg klab_vs_waldo_target_11\n", - "search_datasets/waldo/target/t_12.jpg t_12.jpg klab_vs_waldo_target_12\n", - "search_datasets/waldo/target/t_13.jpg t_13.jpg klab_vs_waldo_target_13\n", - "search_datasets/waldo/target/t_14.jpg t_14.jpg klab_vs_waldo_target_14\n", - "search_datasets/waldo/target/t_15.jpg t_15.jpg klab_vs_waldo_target_15\n", - "search_datasets/waldo/target/t_16.jpg t_16.jpg klab_vs_waldo_target_16\n", - "search_datasets/waldo/target/t_17.jpg t_17.jpg klab_vs_waldo_target_17\n", - "search_datasets/waldo/target/t_18.jpg t_18.jpg klab_vs_waldo_target_18\n", - "search_datasets/waldo/target/t_19.jpg t_19.jpg klab_vs_waldo_target_19\n", - "search_datasets/waldo/target/t_20.jpg t_20.jpg klab_vs_waldo_target_20\n", - "search_datasets/waldo/target/t_21.jpg t_21.jpg klab_vs_waldo_target_21\n", - "search_datasets/waldo/target/t_22.jpg t_22.jpg klab_vs_waldo_target_22\n", - "search_datasets/waldo/target/t_23.jpg t_23.jpg klab_vs_waldo_target_23\n", - "search_datasets/waldo/target/t_24.jpg t_24.jpg klab_vs_waldo_target_24\n", - "search_datasets/waldo/target/t_25.jpg t_25.jpg klab_vs_waldo_target_25\n", - "search_datasets/waldo/target/t_26.jpg t_26.jpg klab_vs_waldo_target_26\n", - "search_datasets/waldo/target/t_27.jpg t_27.jpg klab_vs_waldo_target_27\n", - "search_datasets/waldo/target/t_28.jpg t_28.jpg klab_vs_waldo_target_28\n", - "search_datasets/waldo/target/t_29.jpg t_29.jpg klab_vs_waldo_target_29\n", - "search_datasets/waldo/target/t_30.jpg t_30.jpg klab_vs_waldo_target_30\n", - "search_datasets/waldo/target/t_31.jpg t_31.jpg klab_vs_waldo_target_31\n", - "search_datasets/waldo/target/t_32.jpg t_32.jpg klab_vs_waldo_target_32\n", - "search_datasets/waldo/target/t_33.jpg t_33.jpg klab_vs_waldo_target_33\n", - "search_datasets/waldo/target/t_34.jpg t_34.jpg klab_vs_waldo_target_34\n", - "search_datasets/waldo/target/t_35.jpg t_35.jpg klab_vs_waldo_target_35\n", - "search_datasets/waldo/target/t_36.jpg t_36.jpg klab_vs_waldo_target_36\n", - "search_datasets/waldo/target/t_37.jpg t_37.jpg klab_vs_waldo_target_37\n", - "search_datasets/waldo/target/t_38.jpg t_38.jpg klab_vs_waldo_target_38\n", - "search_datasets/waldo/target/t_39.jpg t_39.jpg klab_vs_waldo_target_39\n", - "search_datasets/waldo/target/t_40.jpg t_40.jpg klab_vs_waldo_target_40\n", - "search_datasets/waldo/target/t_41.jpg t_41.jpg klab_vs_waldo_target_41\n", - "search_datasets/waldo/target/t_42.jpg t_42.jpg klab_vs_waldo_target_42\n", - "search_datasets/waldo/target/t_43.jpg t_43.jpg klab_vs_waldo_target_43\n", - "search_datasets/waldo/target/t_44.jpg t_44.jpg klab_vs_waldo_target_44\n", - "search_datasets/waldo/target/t_45.jpg t_45.jpg klab_vs_waldo_target_45\n", - "search_datasets/waldo/target/t_46.jpg t_46.jpg klab_vs_waldo_target_46\n", - "search_datasets/waldo/target/t_47.jpg t_47.jpg klab_vs_waldo_target_47\n", - "search_datasets/waldo/target/t_48.jpg t_48.jpg klab_vs_waldo_target_48\n", - "search_datasets/waldo/target/t_49.jpg t_49.jpg klab_vs_waldo_target_49\n", - "search_datasets/waldo/target/t_50.jpg t_50.jpg klab_vs_waldo_target_50\n", - "search_datasets/waldo/target/t_51.jpg t_51.jpg klab_vs_waldo_target_51\n", - "search_datasets/waldo/target/t_52.jpg t_52.jpg klab_vs_waldo_target_52\n", - "search_datasets/waldo/target/t_53.jpg t_53.jpg klab_vs_waldo_target_53\n", - "search_datasets/waldo/target/t_54.jpg t_54.jpg klab_vs_waldo_target_54\n", - "search_datasets/waldo/target/t_55.jpg t_55.jpg klab_vs_waldo_target_55\n", - "search_datasets/waldo/target/t_56.jpg t_56.jpg klab_vs_waldo_target_56\n", - "search_datasets/waldo/target/t_57.jpg t_57.jpg klab_vs_waldo_target_57\n", - "search_datasets/waldo/target/t_58.jpg t_58.jpg klab_vs_waldo_target_58\n", - "search_datasets/waldo/target/t_59.jpg t_59.jpg klab_vs_waldo_target_59\n", - "search_datasets/waldo/target/t_60.jpg t_60.jpg klab_vs_waldo_target_60\n", - "search_datasets/waldo/target/t_61.jpg t_61.jpg klab_vs_waldo_target_61\n", - "search_datasets/waldo/target/t_62.jpg t_62.jpg klab_vs_waldo_target_62\n", - "search_datasets/waldo/target/t_63.jpg t_63.jpg klab_vs_waldo_target_63\n", - "search_datasets/waldo/target/t_64.jpg t_64.jpg klab_vs_waldo_target_64\n", - "search_datasets/waldo/target/t_65.jpg t_65.jpg klab_vs_waldo_target_65\n", - "search_datasets/waldo/target/t_66.jpg t_66.jpg klab_vs_waldo_target_66\n", - "search_datasets/waldo/target/t_67.jpg t_67.jpg klab_vs_waldo_target_67\n", - "search_datasets/waldo/gt/gt_1.jpg gt_1.jpg klab_vs_waldo_gt_1\n", - "search_datasets/waldo/gt/gt_2.jpg gt_2.jpg klab_vs_waldo_gt_2\n", - "search_datasets/waldo/gt/gt_3.jpg gt_3.jpg klab_vs_waldo_gt_3\n", - "search_datasets/waldo/gt/gt_4.jpg gt_4.jpg klab_vs_waldo_gt_4\n", - "search_datasets/waldo/gt/gt_5.jpg gt_5.jpg klab_vs_waldo_gt_5\n", - "search_datasets/waldo/gt/gt_6.jpg gt_6.jpg klab_vs_waldo_gt_6\n", - "search_datasets/waldo/gt/gt_7.jpg gt_7.jpg klab_vs_waldo_gt_7\n", - "search_datasets/waldo/gt/gt_8.jpg gt_8.jpg klab_vs_waldo_gt_8\n", - "search_datasets/waldo/gt/gt_9.jpg gt_9.jpg klab_vs_waldo_gt_9\n", - "search_datasets/waldo/gt/gt_10.jpg gt_10.jpg klab_vs_waldo_gt_10\n", - "search_datasets/waldo/gt/gt_11.jpg gt_11.jpg klab_vs_waldo_gt_11\n", - "search_datasets/waldo/gt/gt_12.jpg gt_12.jpg klab_vs_waldo_gt_12\n", - "search_datasets/waldo/gt/gt_13.jpg gt_13.jpg klab_vs_waldo_gt_13\n", - "search_datasets/waldo/gt/gt_14.jpg gt_14.jpg klab_vs_waldo_gt_14\n", - "search_datasets/waldo/gt/gt_15.jpg gt_15.jpg klab_vs_waldo_gt_15\n", - "search_datasets/waldo/gt/gt_16.jpg gt_16.jpg klab_vs_waldo_gt_16\n", - "search_datasets/waldo/gt/gt_17.jpg gt_17.jpg klab_vs_waldo_gt_17\n", - "search_datasets/waldo/gt/gt_18.jpg gt_18.jpg klab_vs_waldo_gt_18\n", - "search_datasets/waldo/gt/gt_19.jpg gt_19.jpg klab_vs_waldo_gt_19\n", - "search_datasets/waldo/gt/gt_20.jpg gt_20.jpg klab_vs_waldo_gt_20\n", - "search_datasets/waldo/gt/gt_21.jpg gt_21.jpg klab_vs_waldo_gt_21\n", - "search_datasets/waldo/gt/gt_22.jpg gt_22.jpg klab_vs_waldo_gt_22\n", - "search_datasets/waldo/gt/gt_23.jpg gt_23.jpg klab_vs_waldo_gt_23\n", - "search_datasets/waldo/gt/gt_24.jpg gt_24.jpg klab_vs_waldo_gt_24\n", - "search_datasets/waldo/gt/gt_25.jpg gt_25.jpg klab_vs_waldo_gt_25\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "search_datasets/waldo/gt/gt_26.jpg gt_26.jpg klab_vs_waldo_gt_26\n", - "search_datasets/waldo/gt/gt_27.jpg gt_27.jpg klab_vs_waldo_gt_27\n", - "search_datasets/waldo/gt/gt_28.jpg gt_28.jpg klab_vs_waldo_gt_28\n", - "search_datasets/waldo/gt/gt_29.jpg gt_29.jpg klab_vs_waldo_gt_29\n", - "search_datasets/waldo/gt/gt_30.jpg gt_30.jpg klab_vs_waldo_gt_30\n", - "search_datasets/waldo/gt/gt_31.jpg gt_31.jpg klab_vs_waldo_gt_31\n", - "search_datasets/waldo/gt/gt_32.jpg gt_32.jpg klab_vs_waldo_gt_32\n", - "search_datasets/waldo/gt/gt_33.jpg gt_33.jpg klab_vs_waldo_gt_33\n", - "search_datasets/waldo/gt/gt_34.jpg gt_34.jpg klab_vs_waldo_gt_34\n", - "search_datasets/waldo/gt/gt_35.jpg gt_35.jpg klab_vs_waldo_gt_35\n", - "search_datasets/waldo/gt/gt_36.jpg gt_36.jpg klab_vs_waldo_gt_36\n", - "search_datasets/waldo/gt/gt_37.jpg gt_37.jpg klab_vs_waldo_gt_37\n", - "search_datasets/waldo/gt/gt_38.jpg gt_38.jpg klab_vs_waldo_gt_38\n", - "search_datasets/waldo/gt/gt_39.jpg gt_39.jpg klab_vs_waldo_gt_39\n", - "search_datasets/waldo/gt/gt_40.jpg gt_40.jpg klab_vs_waldo_gt_40\n", - "search_datasets/waldo/gt/gt_41.jpg gt_41.jpg klab_vs_waldo_gt_41\n", - "search_datasets/waldo/gt/gt_42.jpg gt_42.jpg klab_vs_waldo_gt_42\n", - "search_datasets/waldo/gt/gt_43.jpg gt_43.jpg klab_vs_waldo_gt_43\n", - "search_datasets/waldo/gt/gt_44.jpg gt_44.jpg klab_vs_waldo_gt_44\n", - "search_datasets/waldo/gt/gt_45.jpg gt_45.jpg klab_vs_waldo_gt_45\n", - "search_datasets/waldo/gt/gt_46.jpg gt_46.jpg klab_vs_waldo_gt_46\n", - "search_datasets/waldo/gt/gt_47.jpg gt_47.jpg klab_vs_waldo_gt_47\n", - "search_datasets/waldo/gt/gt_48.jpg gt_48.jpg klab_vs_waldo_gt_48\n", - "search_datasets/waldo/gt/gt_49.jpg gt_49.jpg klab_vs_waldo_gt_49\n", - "search_datasets/waldo/gt/gt_50.jpg gt_50.jpg klab_vs_waldo_gt_50\n", - "search_datasets/waldo/gt/gt_51.jpg gt_51.jpg klab_vs_waldo_gt_51\n", - "search_datasets/waldo/gt/gt_52.jpg gt_52.jpg klab_vs_waldo_gt_52\n", - "search_datasets/waldo/gt/gt_53.jpg gt_53.jpg klab_vs_waldo_gt_53\n", - "search_datasets/waldo/gt/gt_54.jpg gt_54.jpg klab_vs_waldo_gt_54\n", - "search_datasets/waldo/gt/gt_55.jpg gt_55.jpg klab_vs_waldo_gt_55\n", - "search_datasets/waldo/gt/gt_56.jpg gt_56.jpg klab_vs_waldo_gt_56\n", - "search_datasets/waldo/gt/gt_57.jpg gt_57.jpg klab_vs_waldo_gt_57\n", - "search_datasets/waldo/gt/gt_58.jpg gt_58.jpg klab_vs_waldo_gt_58\n", - "search_datasets/waldo/gt/gt_59.jpg gt_59.jpg klab_vs_waldo_gt_59\n", - "search_datasets/waldo/gt/gt_60.jpg gt_60.jpg klab_vs_waldo_gt_60\n", - "search_datasets/waldo/gt/gt_61.jpg gt_61.jpg klab_vs_waldo_gt_61\n", - "search_datasets/waldo/gt/gt_62.jpg gt_62.jpg klab_vs_waldo_gt_62\n", - "search_datasets/waldo/gt/gt_63.jpg gt_63.jpg klab_vs_waldo_gt_63\n", - "search_datasets/waldo/gt/gt_64.jpg gt_64.jpg klab_vs_waldo_gt_64\n", - "search_datasets/waldo/gt/gt_65.jpg gt_65.jpg klab_vs_waldo_gt_65\n", - "search_datasets/waldo/gt/gt_66.jpg gt_66.jpg klab_vs_waldo_gt_66\n", - "search_datasets/waldo/gt/gt_67.jpg gt_67.jpg klab_vs_waldo_gt_67\n" - ] - } - ], - "source": [ - "import os\n", - "\n", - "import h5py\n", - "import numpy as np\n", - "import pandas as pd\n", - "import scipy.misc\n", - "import xarray as xr\n", - "from pathlib import Path\n", - "from result_caching import store\n", - "from sklearn.model_selection import StratifiedShuffleSplit\n", - "from tqdm import tqdm\n", - "from scipy.io import loadmat\n", - "from brainio_collection.knownfile import KnownFile as kf\n", - "\n", - "from brainio_base.assemblies import BehavioralAssembly\n", - "from brainio_base.stimuli import StimulusSet\n", - "from brainio_contrib.packaging import package_stimulus_set, package_data_assembly\n", - "\n", - "def collect_stimuli(data_path):\n", - " stimuli = []\n", - "\n", - " # search images\n", - " for i in range(1, 68):\n", - " target_path = os.path.join(data_path / 'stimuli', 's_' + str(i) + '.jpg')\n", - " filename = 's_' + str(i) + '.jpg'\n", - " im_kf = kf(target_path)\n", - " image_id = 'klab_vs_waldo_stimuli_' + str(i)\n", - " image_label = 'stimuli'\n", - " sample_number = i\n", - " \n", - " print(target_path, filename, image_id)\n", - "\n", - "\n", - " stimuli.append({\n", - " 'image_current_local_file_path': target_path,\n", - " 'image_path_within_store': filename,\n", - " 'image_label': image_label,\n", - " 'image_id': image_id,\n", - " 'sample_number': sample_number,\n", - " })\n", - "\n", - " # target images\n", - " for i in range(1, 68):\n", - " target_path = os.path.join(data_path / 'target', 't_' + str(i) + '.jpg')\n", - " filename = 't_' + str(i) + '.jpg'\n", - " im_kf = kf(target_path)\n", - " image_id = 'klab_vs_waldo_target_' + str(i)\n", - " image_label = 'target'\n", - " sample_number = i\n", - " \n", - " print(target_path, filename, image_id)\n", - "\n", - " stimuli.append({\n", - " 'image_current_local_file_path': target_path,\n", - " 'image_path_within_store': filename,\n", - " 'image_label': image_label,\n", - " 'image_id': image_id,\n", - " 'sample_number': sample_number,\n", - " })\n", - "\n", - " # target mask\n", - " for i in range(1, 68):\n", - " target_path = os.path.join(data_path / 'gt', 'gt_' + str(i) + '.jpg')\n", - " filename = 'gt_' + str(i) + '.jpg'\n", - " im_kf = kf(target_path)\n", - " image_id = 'klab_vs_waldo_gt_' + str(i)\n", - " image_label = 'gt'\n", - " sample_number = i\n", - " \n", - " print(target_path, filename, image_id)\n", - " \n", - "\n", - " stimuli.append({\n", - " 'image_current_local_file_path': target_path,\n", - " 'image_path_within_store': filename,\n", - " 'image_label': image_label,\n", - " 'image_id': image_id,\n", - " 'sample_number': sample_number,\n", - " })\n", - "\n", - " stimuli = StimulusSet(stimuli)\n", - "\n", - " stimuli.image_paths = {row.image_id: row.image_current_local_file_path for row in stimuli.itertuples()}\n", - " stimuli['image_file_name']= stimuli['image_path_within_store']\n", - "\n", - " return stimuli\n", - "\n", - "def collect_data(data_path, sub_id):\n", - " image_id = ['stimuli_' + str(i) for i in range(1, 68)]\n", - " subjects = []\n", - " for i in sub_id:\n", - " subjects += [i]*len(image_id)\n", - "\n", - " S_data = np.load(os.path.join(data_path / 'human_data', 'human_all.npy'))\n", - " I_data = np.load(os.path.join(data_path / 'human_data', 'I_human_all.npy'))\n", - " data = np.zeros((67*len(sub_id), 81, 2), dtype=int)\n", - " data[:,:80,:] = S_data\n", - " data[:,80,:] = I_data\n", - "\n", - " assembly = BehavioralAssembly(data,\n", - " coords={'image_id': ('presentation', image_id*len(sub_id)),\n", - " 'subjects': ('presentation', subjects),\n", - " 'fixation': [*range(81)],\n", - " 'position': ['x', 'y']},\n", - " dims=['presentation', 'fixation', 'position'])\n", - " return assembly\n", - "\n", - "\n", - "data_dir = Path().parent / 'search_datasets'\n", - "data_path = data_dir / 'waldo'\n", - "\n", - "# create stimuli\n", - "stimuli = collect_stimuli(data_path)\n", - "stimuli.name = 'klab.Zhang2018.search_waldo'\n", - "\n", - "# create assembly for different subjects\n", - "assembly = collect_data(data_path, [*range(1, 16)])\n", - "assembly.name = 'klab.Zhang2018search_waldo'" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "\n", - "array([[[ 542, 653],\n", - " [ 507, 534],\n", - " ...,\n", - " [ 0, 0],\n", - " [ 3, 3]],\n", - "\n", - " [[ 520, 655],\n", - " [ 490, 647],\n", - " ...,\n", - " [ 0, 0],\n", - " [ 9, 9]],\n", - "\n", - " ...,\n", - "\n", - " [[ 520, 654],\n", - " [ 380, 709],\n", - " ...,\n", - " [ 0, 0],\n", - " [ 10, 10]],\n", - "\n", - " [[ 510, 649],\n", - " [ 481, 500],\n", - " ...,\n", - " [ 142, 1157],\n", - " [ 80, 80]]])\n", - "Coordinates:\n", - " * fixation (fixation) int64 0 1 2 3 4 5 6 7 8 ... 73 74 75 76 77 78 79 80\n", - " * position (position)