### Install TRIBE v2 with Plotting Source: https://github.com/facebookresearch/tribev2/blob/main/tribe_demo.ipynb Installs the TRIBE v2 library, including plotting utilities, from its GitHub repository. Restart your environment after installation. ```bash !uv pip install "tribev2[plotting] @ git+https://github.com/facebookresearch/tribev2.git" ``` -------------------------------- ### Install TRIBE v2 with Training Dependencies Source: https://github.com/facebookresearch/tribev2/blob/main/README.md Install TRIBE v2 with all dependencies needed for training, including PyTorch Lightning and Weights & Biases. ```bash pip install -e ".[training]" ``` -------------------------------- ### Install TRIBE v2 (Inference Only) Source: https://github.com/facebookresearch/tribev2/blob/main/README.md Install TRIBE v2 with basic dependencies for inference purposes. ```bash pip install -e . ``` -------------------------------- ### Install TRIBE v2 with Brain Visualization Source: https://github.com/facebookresearch/tribev2/blob/main/README.md Install TRIBE v2 with additional dependencies required for brain visualization features. ```bash pip install -e ".[plotting]" ``` -------------------------------- ### Run Local Training Test Source: https://github.com/facebookresearch/tribev2/blob/main/README.md Execute a quick local test run of the training pipeline to verify setup and basic functionality. ```bash python -m tribev2.grids.test_run ``` -------------------------------- ### Prepare Text Input for Prediction Source: https://github.com/facebookresearch/tribev2/blob/main/tribe_demo.ipynb Converts text to speech using gTTS, then transcribes it to get word-level timings. This is necessary for predicting brain responses to text. The resulting events dataframe is used as input for the model. ```python text = """ To be or not to be, that is the question. Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles And by opposing end them. To die, to sleep, No more; and by a sleep to say we end The heartache and the thousand natural shocks """ text_path = CACHE_FOLDER / "shakespeare.txt" text_path.write_text(text) df = model.get_events_dataframe(text_path=text_path) display(df.head(8)[["type", "start", "duration", "filepath", "text", "context"]]) ``` -------------------------------- ### Download Video and Create Events Dataframe Source: https://github.com/facebookresearch/tribev2/blob/main/tribe_demo.ipynb Downloads a sample video and processes it to create an events dataframe. This involves extracting audio, transcribing speech, and adding context to words. Ensure CACHE_FOLDER is defined. ```python video_path = CACHE_FOLDER / "sample_video.mp4" url = "https://download.blender.org/durian/trailer/sintel_trailer-480p.mp4" download_file(url, video_path) df = model.get_events_dataframe(video_path=video_path) display(df.head(8)[["type", "start", "duration", "filepath", "text", "context"]]) ``` -------------------------------- ### Set Environment Variables for Training Source: https://github.com/facebookresearch/tribev2/blob/main/README.md Configure essential environment variables for data and output paths before running training scripts. Alternatively, these can be set directly in 'tribev2/grids/defaults.py'. ```bash export DATAPATH="/path/to/studies" export SAVEPATH="/path/to/output" ``` -------------------------------- ### Run Grid Search on Slurm Source: https://github.com/facebookresearch/tribev2/blob/main/README.md Initiate a grid search for training models on a Slurm cluster. Use separate commands for cortical and subcortical training. ```bash python -m tribev2.grids.run_cortical python -m tribev2.grids.run_subcortical ``` -------------------------------- ### Load TRIBE v2 Model and Plotter Source: https://github.com/facebookresearch/tribev2/blob/main/tribe_demo.ipynb Loads a pretrained TRIBE v2 model from HuggingFace Hub and initializes a PlotBrain object for 3D brain surface visualization. The model checkpoint is downloaded on the first run. ```python from tribev2.demo_utils import TribeModel, download_file from tribev2.plotting import PlotBrain from pathlib import Path CACHE_FOLDER = Path("./cache") model = TribeModel.from_pretrained( "facebook/tribev2", cache_folder=CACHE_FOLDER, ) plotter = PlotBrain(mesh="fsaverage5") ``` -------------------------------- ### Load Pretrained Model and Predict Brain Responses Source: https://github.com/facebookresearch/tribev2/blob/main/README.md Load a pretrained TRIBE v2 model from HuggingFace and predict brain responses to a video. Ensure the 'cache_folder' is set to your desired directory. Predictions are for the 'average' subject and use the 'fsaverage5' cortical mesh. ```python from tribev2 import TribeModel model = TribeModel.from_pretrained("facebook/tribev2", cache_folder="./cache") df = model.get_events_dataframe(video_path="path/to/video.mp4") preds, segments = model.predict(events=df) print(preds.shape) # (n_timesteps, n_vertices) ``` -------------------------------- ### Visualize Visual Stimulus Predictions Source: https://github.com/facebookresearch/tribev2/blob/main/tribe_demo.ipynb Plots predicted fMRI activity for visual stimuli on the fsaverage5 cortical mesh. Predictions are offset to compensate for hemodynamic lag. Use this to visualize model output for visual inputs. ```python n_timesteps = 15 fig = plotter.plot_timesteps(preds[:n_timesteps], segments=segments[:n_timesteps], cmap="fire", norm_percentile=99, vmin=.6, alpha_cmap=(0, .2), show_stimuli=True) ``` -------------------------------- ### Run TRIBE v2 Prediction Model Source: https://github.com/facebookresearch/tribev2/blob/main/tribe_demo.ipynb Feeds the events dataframe into the TRIBE v2 model to predict brain activity. This step requires access to the Llama-3.2 model. The output contains predictions and corresponding time segments. ```python preds, segments = model.predict(events=df) print(f"Predictions shape: {preds.shape} (n_timesteps, n_vertices)") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.