import os
import numpy as np
import matplotlib.pyplot as plt
# @title Download the data
import os, requests, tarfile
fnames = ["kay_labels.npy", "kay_labels_val.npy", "kay_images.npz"]
urls = ["https://osf.io/r638s/download",
"https://osf.io/yqb3e/download",
"https://osf.io/ymnjv/download"]
for fname, url in zip(fnames, urls):
if not os.path.isfile(fname):
try:
r = requests.get(url)
except requests.ConnectionError:
print("!!! Failed to download data !!!")
else:
if r.status_code != requests.codes.ok:
print("!!! Failed to download data !!!")
else:
print(f"Downloading {fname}...")
with open(fname, "wb") as fid:
fid.write(r.content)
print(f"Download {fname} completed!")
Downloading kay_labels.npy... Download kay_labels.npy completed! Downloading kay_labels_val.npy... Download kay_labels_val.npy completed! Downloading kay_images.npz... Download kay_images.npz completed!
with np.load(fname) as dobj:
dat = dict(**dobj)
labels = np.load('kay_labels.npy')
val_labels = np.load('kay_labels_val.npy')
labels
is a 4 by stim array of class names:
print(labels[:, :4])
[['artifact' 'entity' 'animal' 'animal'] ['instrumentality' 'round shape' 'vertebrate' 'vertebrate'] ['equipment' 'sphere' 'mammal' 'amphibian'] ['croquet ball' 'bubble' 'komondor' 'tailed frog']]
print(dat.keys())
dict_keys(['stimuli', 'stimuli_test', 'responses', 'responses_test', 'roi', 'roi_names'])
dat
has the following fields:
stimuli
: stim x i x j array of grayscale stimulus imagesstimuli_test
: stim x i x j array of grayscale stimulus images in the test setresponses
: stim x voxel array of z-scored BOLD response amplituderesponses_test
: stim x voxel array of z-scored BOLD response amplitude in the test setroi
: array of voxel labelsroi_names
: array of names corresponding to voxel labelsprint(dat["stimuli"].shape)
(1750, 128, 128)
print(dat["responses"].shape)
(1750, 8428)
This is the number of voxels in each ROI. Note that "Other"
voxels have been removed from this version of the dataset:
dict(zip(dat["roi_names"], np.bincount(dat["roi"])))
{'LatOcc': 928, 'Other': 0, 'V1': 1294, 'V2': 2083, 'V3': 1790, 'V3A': 484, 'V3B': 314, 'V4': 1535}
Each stimulus is a 128 x 128 grayscale array:
fig, axs = plt.subplots(2, 4, figsize=(12, 6), sharex=True, sharey=True)
for ax, im, lbl in zip(axs.flat, dat["stimuli"], labels[-1, :]):
ax.imshow(im, cmap="gray")
ax.set_title(lbl)
fig.tight_layout()
fig.show()
Each stimulus is associated with a pattern of BOLD response across voxels in visual cortex:
fig, ax = plt.subplots(figsize=(12, 5))
ax.set(xlabel="Voxel", ylabel="Stimulus")
heatmap = ax.imshow(dat["responses"],
aspect="auto", vmin=-1, vmax=1, cmap="bwr")
fig.colorbar(heatmap, shrink=.5, label="Response amplitude (Z)")
fig.tight_layout()
fig.show()