Skip to content

Instantly share code, notes, and snippets.

View fepegar's full-sized avatar

Fernando Pérez-García fepegar

View GitHub Profile
@fepegar
fepegar / visualize-positional-embeddings-in-dinov2-vit.ipynb
Created October 17, 2023 22:48
Visualize positional embeddings in DINOv2 ViT.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fepegar
fepegar / aoc_input_to_mesh.py
Created December 12, 2022 23:50
Script to convert the input of day 12 of Advent of Code 2022 to an STL file
"""
Convert the input of day 12 of Advent of Code 2022 to an STL file.
To install requirements, run:
pip install scikit-image numpy-stl
Usage:
python input_to_mesh.py input.txt output.stl
Example content of input.txt:
import torch
import torchio as tio
from einops import rearrange
rows = 16
cols = 28
dataset = tio.datasets.OrganMNIST3D('train')
batch_size = rows * cols
loader = torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=True)
@fepegar
fepegar / TorchIO Resize demo.ipynb
Created October 14, 2021 16:04
TorchIO Resize demo
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fepegar
fepegar / dropout.md
Created September 30, 2021 18:37
Gist for MICCAI 2021
import torch
import torchio as tio

image4d = tio.Resample()(tio.datasets.FPG().dmri)
collater = torch.utils.data.DataLoader([image4d])
batch = next(iter(collater))
tensor = batch[tio.DATA].float()
dropped = torch.nn.Dropout3d()(tensor)
for i, channel in enumerate(dropped[0]):
@fepegar
fepegar / test-label-sampler.ipynb
Created February 10, 2021 15:52
Test label sampler.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from pathlib import Path
import torch
import torchvision
import numpy as np
from PIL import Image
import torchio as tio
from tqdm import trange
output_dir = Path('/tmp/transformed')
@fepegar
fepegar / SITK_PT.ipynb
Last active October 20, 2020 21:28
Possible bug in SimpleITK or in PyTorch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fepegar
fepegar / parcellation_slicer.py
Created October 1, 2020 18:36
Run a brain parcellation deep learning model within 3D Slicer
# Paste this code into the Slicer Python console
pip_install('highresnet')
import SampleData
from highresnet.inference import infer
from highresnet.cli.download_oasis import download_oasis
input_path = download_oasis()
loadVolume(input_path)
@fepegar
fepegar / functions.py
Created June 24, 2020 14:49
Functions for experimental TorchIO notebooks
import numpy as np
import matplotlib.pyplot as plt
def fourier_transform(array: np.ndarray):
transformed = np.fft.fftn(array)
fshift = np.fft.fftshift(transformed)
return fshift
def inv_fourier_transform(fshift: np.ndarray):
f_ishift = np.fft.ifftshift(fshift)