Load the mosaic dataset (Lahner et al.) and the associated pre-trained models
pip install mosaic-dataset
import mosaic
dataset = mosaic.load(
names_and_subjects={
"NaturalScenesDataset": [1], ## set this to "all" if you want to download data for all subjects
# "THINGS": "all"
},
folder="./MOSAIC",
# if set to False, dataset[i]["betas"] will return a tensor containing the betas for all ROIs concatenated together
parse_betas=True
)
print(dataset[0].keys())
Visualization
import mosaic
from mosaic.utils import visualize
visualize(
betas=dataset[0]["betas"],
## set rois to None if you want to visualize all of the rois
rois=[
"L_FFC",
"R_FFC",
"L_PHA2",
"R_PHA2",
"L_V1",
"R_V1",
],
## other modes are: 'white', 'midthickness', 'pial', 'inflated', 'very_inflated', 'flat', 'sphere'
mode = "inflated",
save_as = "plot.html",
)
Loading pre-trained models
import mosaic
model = mosaic.from_pretrained(
backbone_name='ResNet18',
framework='multihead',
subjects='all',
vertices='visual',
folder='./mosaic_models/'
)
## or load a single subject model
single_subject_model = mosaic.from_pretrained(
backbone_name="CNN8",
framework="singlehead",
subjects="sub-05_NSD",
vertices="visual",
)
Running inference with pre-trained models:
from mosaic.utils.inference import MosaicInference
inference = MosaicInference(
model=model,
batch_size=32,
device="cpu"
)
results = inference.run(
images = [
Image.open("face.jpg").convert("RGB"),
],
names_and_subjects={"NaturalScenesDataset": "all"}
)
Visualizing model predictions
#note responses to the face are highest in the ventral stream
inference.plot(
image=Image.open("face.jpg").convert("RGB"),
save_as="predicted_voxel_responses.html",
dataset_name="NaturalScenesDataset",
subject_id=1,
## other modes are: 'white', 'midthickness', 'pial', 'inflated', 'very_inflated', 'flat', 'sphere'
mode="inflated"
)
Loading up stimulus info:
stim_info = mosaic.get_stiminfo(
dataset_name="deeprecon",
folder="./MOSAIC"
)
print(stim_info.head())
Merging files for easier loading
from mosaic.utils.merging import merge_hdf5_files
from mosaic.datasets import MergedDataset
merge_hdf5_files(
files=[
'./MOSAIC/NSD/sub-01_NSD.hdf5',
'./MOSAIC/deep_recon/sub-01_deeprecon.hdf5'
],
save_as="./merged-test.hdf5"
)
dataset = MergedDataset(
filename="./merged-test.hdf5"
)
print(len(dataset))
Downloading resting state data
from mosaic.datasets.resting_state import download_resting_state_data
download_resting_state_data(
dataset="BMD", ## or "NSD" or "THINGS"
subject=1,
session=1,
run=1,
folder="./MOSAIC"
)
Downloading time series data
from mosaic.datasets.timeseries import download_timeseries_data
download_timeseries_data(
folder = "./mosaic-timeseries",
dataset_name = "deeprecon"
)
Dev Setup
git clone git+https://github.com/Mayukhdeb/mosaic-dataset.git
cd mosaic-dataset
python setup.py develop
Running tests
Note: Before you start running tests, open tests/tesing_config.json and make the following changes
- Rename the
dataset_folderandmodels_folderto wherever you already have the files or where you'd like to download them - set
download_pretrained_modelstotrueif you want to test the models with their actual trained weights. It's set tofalseby default to avoid spamming the AWS bucket with requests.
pytest -vvx tests/
And to make the tests more verbose (with the prints displayed)
pytest -vvx --capture=no tests/
Metadata
Release files for mosaic-dataset 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mosaic_dataset-0.0.6.tar.gz | 44.0 kB | Without provenance | Details for mosaic_dataset-0.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mosaic_dataset-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for mosaic_dataset-0.0.6-py3-none-any.whl |
Total release size: 91.2 kB
Release files / mosaic_dataset-0.0.6.tar.gz
| Download URL | mosaic_dataset-0.0.6.tar.gz |
|---|---|
| Size | 44.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2bfc2ee16515f7045163ddeb08e185ff92146f4cb12e8f50dadf07ebb8a0ff4f
|
|
BLAKE2b-256 checksum How to use checksums |
976417d252a1129c4b10e6144968712de73f5a7e03f28498f9ffe100895a1a7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Release files / mosaic_dataset-0.0.6-py3-none-any.whl
| Download URL | mosaic_dataset-0.0.6-py3-none-any.whl |
|---|---|
| Size | 47.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
286e74d9ea8af1b20a98716eaf6642698477c83bd41a4c27af40a6252ddc4fcb
|
|
BLAKE2b-256 checksum How to use checksums |
18e88cbd0de1a321b1cc5f3134ff26f7746ac8a0d1f4942ee03238cadd8a8f32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Security for mosaic-dataset 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.