fmri-fm / README.md
AshwinKM2005's picture
feat: Add dataset card and loading script
2dfe372
|
Raw
History Blame
19.2 kB
metadata
pretty_name: 'MindEye: fMRI-to-Image Reconstruction Dataset'
license: mit
tags:
  - neuroscience
  - fMRI
  - brain-decoding
  - image-reconstruction
  - contrastive-learning
  - diffusion-models
  - CLIP
  - natural-scenes
task_categories:
  - image-to-image
  - feature-extraction
size_categories:
  - 10K<n<100K
configs:
  - config_name: nsd-brain-trials
    data_files: datasets/flat-clips/nsd-train-task-clips-16t/*.pt
    default: true
    dataset_info:
      features:
        - name: subject_id
          dtype: string
          description: Subject identifier (e.g., 'subj01')
        - name: session
          dtype: int32
          description: Scanning session number (1-40)
        - name: run
          dtype: int32
          description: fMRI run number within session
        - name: n_frames
          dtype: int32
          description: Total frames in the fMRI run (~301)
        - name: fmri_data
          sequence:
            sequence: float16
          description: Brain activity tensor
        - name: start_frame
          dtype: int32
          description: Frame index where stimulus presentation begins
        - name: onset_time
          dtype: float32
          description: Stimulus onset time in seconds
        - name: duration
          dtype: float32
          description: Stimulus presentation duration (3.0s)
        - name: trial_type
          dtype: string
          description: Always 'nsd' for this dataset
        - name: nsd_image_id
          dtype: int32
          description: NSD image identifier (links to COCO dataset)
        - name: target_class
          dtype: int32
          description: Target class/category for the stimulus
  - config_name: hcp-brain-trials
    data_files: datasets/flat-clips/hcp-train-task-clips-16t/*.pt
    dataset_info:
      features:
        - name: subject_id
          dtype: string
          description: HCP subject identifier (6-digit code)
        - name: modality
          dtype: string
          description: Imaging modality ('tfMRI' or 'rfMRI')
        - name: task
          dtype: string
          description: HCP task name (e.g., RELATIONAL, SOCIAL, WM, REST1)
        - name: field_strength
          dtype: string
          description: Magnetic field strength ('3T' or '7T')
        - name: phase_encoding
          dtype: string
          description: Phase encoding direction ('LR', 'RL', 'PA', 'AP')
        - name: n_frames
          dtype: int32
          description: Total frames in the fMRI run (126-918)
        - name: fmri_data
          sequence:
            sequence: float16
          description: Brain activity tensor
        - name: start_frame
          dtype: int32
          description: Frame index where trial begins
        - name: onset_time
          dtype: float32
          description: Trial onset time in seconds
        - name: duration
          dtype: float32
          description: Trial duration in seconds
        - name: trial_type
          dtype: string
          description: Specific trial condition (e.g., relation, mental, story)
        - name: target_class
          dtype: int32
          description: Target class mapped via hcp-task-mapping config
  - config_name: hcp-flat-archives
    data_files: datasets/hcp-flat/*.tar
  - config_name: clip-image-embeddings
    data_files: datasets/nsd_clip_embeds.npy
    dataset_info:
      features:
        - name: image_embeddings
          sequence:
            sequence: float32
          description: CLIP ViT-L/14 embeddings for 73,000 NSD stimulus images
  - config_name: semantic-clusters
    data_files: datasets/nsd_coco_73k_semantic_cluster_ids.npy
    dataset_info:
      features:
        - name: cluster_ids
          sequence: int64
          description: 'Semantic cluster assignments for COCO/NSD images (range: 0-40)'
  - config_name: brain-parcellations
    data_files:
      - datasets/Schaefer2018_400Parcels_7Networks_order.flat.npy
      - datasets/Yeo2011_RSFC_7Networks.flat.npy
    dataset_info:
      features:
        - name: parcellation_type
          dtype: string
          description: >-
            Atlas type ('Schaefer2018_400Parcels_7Networks' or
            'Yeo2011_RSFC_7Networks')
        - name: parcellation_map
          sequence:
            sequence: int64
          description: Brain region mapping
        - name: max_regions
          dtype: int32
          description: Maximum number of regions (400 for Schaefer, 7 for Yeo)
  - config_name: hcp-task-mapping
    data_files: datasets/hcp_trial_type_target_id_map.json
    dataset_info:
      features:
        - name: trial_type
          dtype: string
          description: HCP task condition name
        - name: target_id
          dtype: int32
          description: Mapped numerical identifier (0-20)
  - config_name: hcp-session-metadata
    data_files: datasets/session_metadata.json
    dataset_info:
      features:
        - name: session_key
          dtype: string
          description: >-
            Session identifier (e.g.,
            'sub-349244_mod-tfMRI_task-RELATIONAL_mag-3T_dir-RL')
        - name: subject_id
          dtype: string
          description: HCP subject identifier (6-digit code)
        - name: task
          dtype: string
          description: HCP task name
        - name: modality
          dtype: string
          description: Imaging modality ('tfMRI' or 'rfMRI')
        - name: field_strength
          dtype: string
          description: Magnetic field strength ('3T' or '7T')
        - name: phase_encoding
          dtype: string
          description: Phase encoding direction ('LR', 'RL', 'PA', 'AP')
        - name: n_frames
          dtype: int32
          description: Total frames in session (126-918)
        - name: n_voxels
          dtype: int32
          description: Total voxels in session (77,763)

🧠 MindEye: fMRI-to-Image Reconstruction Dataset

Paper License: MIT Hugging Face Discord

MindEye is a groundbreaking fMRI-to-image dataset that enables state-of-the-art reconstruction and retrieval of viewed natural scene images from human brain activity.

  • πŸŽ₯ Built on the Natural Scenes Dataset (NSD), containing brain responses from 4 participants who passively viewed MS-COCO natural scenes during 7-Tesla fMRI scanning
  • πŸ† Achieves >90% accuracy across multiple reconstruction metrics and >93% top-1 retrieval accuracy, marking a major breakthrough in neural decoding
  • πŸ”— Maps fMRI brain activity to CLIP image embeddings through specialized contrastive learning frameworks and diffusion-based generative models
  • 🎨 Combines high-level semantic information with low-level perceptual features, enabling fine-grained decoding that can distinguish between highly similar images (e.g., different zebras)
  • 🌍 Demonstrates scalability to billion-image retrieval tasks using LAION-5B, extending its impact to internet-scale benchmarks

Example: Original stimulus (left) and MindEye reconstruction (right)

Figure: Paired side-by-side example β€” Left: MS-COCO stimulus shown during scanning; Right: MindEye reconstruction (Subject 01) derived from fmri_voxels + clip_embeddings.


πŸ“‘ Table of Contents


πŸš€ Quickstart

from datasets import load_dataset

# 1. Load the default NSD brain trials (streaming recommended for large configs)
nsd_ds = load_dataset("medarc/fmri-fm", name="nsd-brain-trials", streaming=True, split="train")
example = next(iter(nsd_ds))

print(f"Subject: {example['subject_id']}, Session: {example['session']}, NSD Image ID: {example['nsd_image_id']}")
print(f"fMRI Data (first 5 values of first frame): {example['fmri_data'][0][:5]}")

# 2. Load the supplementary HCP brain trials (streaming)
hcp_ds = load_dataset("medarc/fmri-fm", name="hcp-brain-trials", streaming=True, split="train")
hcp_example = next(iter(hcp_ds))

print(f"HCP Subject: {hcp_example['subject_id']}, Task: {hcp_example['task']}")

# 3. Load CLIP image embeddings for all NSD stimuli (dense table, non-streaming)
clip_ds = load_dataset("medarc/fmri-fm", name="clip-image-embeddings", split="train")
print(f"Total embeddings: {len(clip_ds)}")
print(f"Embedding vector length (first image): {len(clip_ds[0]['image_embeddings'])}")

# 4. Load HCP session metadata
metadata_ds = load_dataset("medarc/fmri-fm", name="hcp-session-metadata", split="train")
meta_example = next(iter(metadata_ds))

print(f"Example Session Key: {meta_example['session_key']}")
print(f"Number of voxels in session: {meta_example['n_voxels']}")

# πŸ“¦ Dataset Configurations

πŸ”Ή nsd-brain-trials (Default)

Contains the primary fMRI signals from the Natural Scenes Dataset, used as the main inputs for the MindEye model.

Field Name Type Description
subject_id string Subject identifier (e.g., "subj01")
session int32 Scanning session number (1-40)
run int32 fMRI run number within session
fmri_data sequence[sequence[float16]] Brain activity tensor
nsd_image_id int32 NSD image identifier (links to COCO dataset)

πŸ”Ή hcp-brain-trials

Contains supplementary fMRI data from the Human Connectome Project (HCP) for various cognitive tasks.

Field Name Type Description
subject_id string HCP subject identifier (6-digit code)
modality string Imaging modality ("tfMRI" or "rfMRI")
task string HCP task name (RELATIONAL, SOCIAL, WM, etc.)
fmri_data sequence[sequence[float16]] Brain activity tensor
trial_type string Specific trial condition (relation, mental, etc.)

πŸ”Ή clip-image-embeddings

Contains the target CLIP (ViT-L/14) image embeddings for the 73,000 NSD stimulus images.

Field Name Type Description
image_embeddings sequence[sequence[float32]] CLIP ViT-L/14 embeddings for NSD images

πŸ”Ή hcp-session-metadata

Detailed metadata for each fMRI session in the HCP dataset.

Field Name Type Description
session_key string Unique session identifier
subject_id string HCP subject identifier
task string HCP task name
n_voxels int32 Total voxels in session (77,763)

πŸ”Ή Other Configurations

  • hcp-session-archives: Raw .tar archives of preprocessed fMRI data from the HCP dataset.
  • semantic-clusters: Semantic cluster assignments for the 73k COCO/NSD images.
  • brain-parcellations: Brain atlas files (Schaefer 2018, Yeo 2011) used for feature engineering.
  • hcp-task-mapping: JSON file mapping HCP task conditions to numerical target IDs.

πŸ”¬ Provenance & Processing

This dataset is constructed from two major sources:

  • Natural Scenes Dataset (NSD)
  • Human Connectome Project (HCP)

The primary neuroimaging data was collected using a 7-Tesla (7T) fMRI scanner. All fMRI data underwent rigorous preprocessing including:

  • GLMsingle: General Linear Model single-trial estimation
  • Z-scoring: Session-wise normalization of signals
  • Brain parcellation: Feature vectors constructed via atlases such as the Schaefer 2018 (400 Parcels) and **Yeo 2011 (7 Networks)**β€”reducing volumetric brain data into region-wise summaries suitable for machine learning tasks.

βœ… Intended Uses & Limitations

Recommended Uses

  • Neuroscience Research: Understanding visual cortex representations, brain-computer interfaces, and neural mechanisms of visual perception
  • Computer Vision: Developing novel multimodal learning approaches between brain signals and visual data, contrastive learning research
  • AI Model Development: Training and benchmarking brain decoding models, diffusion-based reconstruction systems
  • Medical Applications: Research into locked-in syndrome communication, depression assessment through visual bias analysis, neurological disorder diagnosis

Out-of-Scope Uses

  • ⚠️ Clinical Diagnosis: Not validated for medical diagnosis without extensive additional clinical validation and regulatory approval
  • ⚠️ Cross-subject Generalization: Models are subject-specific and do not generalize across individuals without additional training data
  • ⚠️ Non-consensual Applications: Requires active participant compliance; easily defeated by head movement, unrelated thinking, or non-compliance

Known Limitations

  • Subject Specificity: Each participant requires individual model training with extensive fMRI data (up to 40 hours scanning)
  • Compliance Requirement: Non-invasive neuroimaging requires participant cooperation and cannot be used covertly
  • Single-trial Degradation: Performance significantly degrades when using single-trial vs. averaged responses

βš–οΈ Bias & Fairness Considerations

  • Sampling Biases: Limited to 4 participants, all capable of undergoing extensive MRI scanning. Geographic and cultural representation not specified.

  • Image Distribution: Images limited to MS-COCO natural scenes, which may not represent diverse visual experiences across cultures, environments, or individual visual preferences.

  • Technical Access: Requires expensive 7-Tesla MRI equipment and substantial computational resources, limiting accessibility and reproducibility across research groups.

πŸ“Š Results

Representative reconstruction and retrieval results.

Category Best Prior SOTA MindEye
Pixel Correlation 0.254 (Ozcelik) 0.309
SSIM 0.356 (Ozcelik) 0.323
Image Retrieval (top-1) 94.2% (Ozcelik) 97.8%
Brain Retrieval (top-1) 30.3% (Ozcelik) 90.1%
CLIP Identification 91.5% (Ozcelik) 94.1%
Parameter Efficiency 1.45B (Ozcelik LL) 206M

πŸ“ Dataset Scale:

  • Training samples: 24,980 across 4 subjects (individual trials preserved)
  • Test samples: 982 (averaged across 3 repetitions per image)
  • Voxels per subject: 13,000-16,000 from nsdgeneral brain region

πŸ“– Citation

Please cite:

@article{scotti2023reconstructing,
title={Reconstructing the Mind's Eye: fMRI-to-Image with Contrastive Learning and Diffusion Priors},
author={Paul S. Scotti and Atmadeep Banerjee and Jimmie Goode and Stepan Shabalin and Alex Nguyen and Ethan Cohen and Aidan J. Dempster and Nathalie Verlinde and Elad Yundler and David Weisberg and Kenneth A. Norman and Tanishq Mathew Abraham},
journal={arXiv preprint arXiv:2305.18274},
year={2023},
url={[https://arxiv.org/abs/2305.18274v2}](https://arxiv.org/abs/2305.18274v2%7D)
}

πŸ“œ License

MIT License  
Copyright (c) 2022 MEDARC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.