Skip to content

Instantly share code, notes, and snippets.

View Mason-McGough's full-sized avatar
⛰️
Living in the right balance

Mason McGough Mason-McGough

⛰️
Living in the right balance
View GitHub Profile
@Mason-McGough
Mason-McGough / torch_memory_utils.py
Last active September 30, 2024 20:13
Simple reference functions to estimate memory usage in torch.
import functools
import torch
import psutil
def process_memory() -> float:
"""
Estimate total memory usage of the current process.
"""
@Mason-McGough
Mason-McGough / crop_images.py
Created August 27, 2024 17:44
Crop all images in a given directory to the same size
"""
Crop all images in a given directory to the same size
"""
import argparse
import os
import concurrent.futures
from glob import glob
from enum import Enum
@Mason-McGough
Mason-McGough / tnet.py
Created March 20, 2024 13:05
PyTorch implementation of a T-Net module from PointNet
from typing import Callable
import torch
from torch import nn
import torch.nn.functional as F
class TNet(nn.Module):
"""
Transformation network module of PointNet
@Mason-McGough
Mason-McGough / modelnet10_subset_test_list.txt
Last active March 12, 2024 00:31
Filtered test subset of ModelNet10 for "3D Object Classification with PointNet and PyTorch3D"
ModelNet10/sofa/test/sofa_0780.off,sofa
ModelNet10/bed/test/bed_0545.off,bed
ModelNet10/dresser/test/dresser_0264.off,dresser
ModelNet10/dresser/test/dresser_0239.off,dresser
ModelNet10/table/test/table_0420.off,table
ModelNet10/table/test/table_0425.off,table
ModelNet10/monitor/test/monitor_0535.off,monitor
ModelNet10/table/test/table_0428.off,table
ModelNet10/dresser/test/dresser_0211.off,dresser
ModelNet10/monitor/test/monitor_0553.off,monitor
@Mason-McGough
Mason-McGough / modelnet10_subset_train_list.txt
Last active March 12, 2024 00:30
Filtered train subset of ModelNet10 for "3D Object Classification with PointNet and PyTorch3D"
ModelNet10/chair/train/chair_0381.off,chair
ModelNet10/bed/train/bed_0463.off,bed
ModelNet10/bathtub/train/bathtub_0031.off,bathtub
ModelNet10/monitor/train/monitor_0101.off,monitor
ModelNet10/sofa/train/sofa_0128.off,sofa
ModelNet10/dresser/train/dresser_0115.off,dresser
ModelNet10/sofa/train/sofa_0250.off,sofa
ModelNet10/dresser/train/dresser_0104.off,dresser
ModelNet10/sofa/train/sofa_0579.off,sofa
ModelNet10/bed/train/bed_0062.off,bed
@Mason-McGough
Mason-McGough / inpaint-person.py
Last active January 9, 2024 22:23
A simple script that removes people from photos using the stable-diffusion-webui API
"""
Remove a person from an image using a stable diffusion server
This short demo accompanies the Medium article "Stable Diffusion as an API: Make a Person-Removing Microservice".
The full article can be found here: https://towardsdatascience.com/stable-diffusion-as-an-api-5e381aec1f6
Example usage:
python inpaint-person.py my-image.jpg -W 768 -H 768 -o my-output.png
"""
@Mason-McGough
Mason-McGough / nerf_sample_hierarchical.py
Created April 23, 2022 17:50
Hierarchical sampling for NeRF
def sample_hierarchical(
rays_o: torch.Tensor,
rays_d: torch.Tensor,
z_vals: torch.Tensor,
weights: torch.Tensor,
n_samples: int,
perturb: bool = False
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
r"""
Apply hierarchical sampling to the rays.
@Mason-McGough
Mason-McGough / nerf_sample_stratified.py
Created April 23, 2022 17:47
Stratified sampling for NeRF
def sample_stratified(
rays_o: torch.Tensor,
rays_d: torch.Tensor,
near: float,
far: float,
n_samples: int,
perturb: Optional[bool] = True,
inverse_depth: bool = False
) -> Tuple[torch.Tensor, torch.Tensor]:
r"""
@Mason-McGough
Mason-McGough / nerf_module.py
Created April 23, 2022 17:46
The NeRF PyTorch module.
class NeRF(nn.Module):
r"""
Neural radiance fields module.
"""
def __init__(
self,
d_input: int = 3,
n_layers: int = 8,
d_filter: int = 256,
skip: Tuple[int] = (4,),
@Mason-McGough
Mason-McGough / nerf_volume_render.py
Created April 23, 2022 17:41
Volume rendering function for NeRF.
def raw2outputs(
raw: torch.Tensor,
z_vals: torch.Tensor,
rays_d: torch.Tensor,
raw_noise_std: float = 0.0,
white_bkgd: bool = False
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
r"""
Convert the raw NeRF output into RGB and other maps.
"""