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 / starship.toml
Created May 26, 2025 20:50
Starship config with modules for uv
[python]
python_binary = ".venv/bin/python"
[custom.uv-version]
description = "The currently installed version of uv"
shell = "bash"
detect_files = [
".python-version",
"Pipfile",
"__init__.py",
@fepegar
fepegar / starship.toml
Created May 26, 2025 20:50
Starship config with modules for uv
[python]
python_binary = ".venv/bin/python"
[custom.uv-version]
description = "The currently installed version of uv"
shell = "bash"
detect_files = [
".python-version",
"Pipfile",
"__init__.py",
@fepegar
fepegar / run_rad_dino.py
Last active May 25, 2025 12:52
Script to extract features from chest X-rays using RAD-DINO. Try `uv run run_rad_dino.py --help`.
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "einops",
# "loguru",
# "numpy",
# "pillow",
# "procex",
# "torch",
# "transformers",
@fepegar
fepegar / jtry
Last active February 18, 2025 13:41
Create a temporary Python environment with uv and open a Jupyter notebook with VS Code
#!/bin/bash
PYTHON_VERSION="3.13"
tmp_dir=$(mktemp -d)
uv init \
--bare \
--quiet \
--python $PYTHON_VERSION \
@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.