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
# adapted from https://github.com/autonomousvision/giraffe (MIT License)
class Renderer(object):
# ...
def render_full_visualization(self, img_out_path,
render_program=['object_rotation']):
for rp in render_program:
# ...
# APPEND THIS TO THE END OF render_full_visualization
if rp == 'object_wipeout':
self.set_random_seed()
# adapted from https://github.com/autonomousvision/giraffe (MIT License)
inherit_from: configs/256res/cars_256.yaml
training:
out_dir: out/cars256_pretrained
test:
model_file: https://s3.eu-central-1.amazonaws.com/avg-projects/giraffe/models/checkpoint_cars256-d9ea5e11.pt
rendering:
render_dir: rendering
render_program: ['object_wipeout']
# adapted from https://github.com/autonomousvision/giraffe (MIT License)
inherit_from: configs/256res/cars_256.yaml
training:
out_dir: out/cars256_pretrained
test:
model_file: https://s3.eu-central-1.amazonaws.com/avg-projects/giraffe/models/checkpoint_cars256-d9ea5e11.pt
rendering:
render_dir: rendering
render_program: ['render_camera_elevation', 'render_add_cars']
@Mason-McGough
Mason-McGough / pointer_network.py
Last active October 2, 2023 09:55
Pointer network attention architecture in PyTorch
class PointerNetwork(nn.Module):
"""
From "Pointer Networks" by Vinyals et al. (2017)
Adapted from pointer-networks-pytorch by ast0414:
https://github.com/ast0414/pointer-networks-pytorch
Args:
n_hidden: The number of features to expect in the inputs.
"""
@Mason-McGough
Mason-McGough / grad_tracker.py
Last active June 14, 2021 17:19
Simple gradient tracker for PyTorch
class GradTracker():
def __init__(
self,
model: nn.Module
):
self.model = model
self.reset_history()
self.reset_buffer()
def __getitem__(
@Mason-McGough
Mason-McGough / mesh_features.py
Last active June 2, 2021 15:51
MeshCNN: input features
# From models/layers/mesh_conv.py in https://github.com/ranahanocka/MeshCNN
def dihedral_angle(mesh, edge_points):
"""
Angle between two faces connected to edge.
"""
normals_a = get_normals(mesh, edge_points, 0)
normals_b = get_normals(mesh, edge_points, 3)
dot = np.sum(normals_a * normals_b, axis=1).clip(-1, 1)
angles = np.expand_dims(np.pi - np.arccos(dot), axis=0)
@Mason-McGough
Mason-McGough / mesh_conv.py
Last active June 2, 2021 14:13
MeshCNN: symmetric features for equivariant convolution
# Simplified from models/layers/mesh_conv.py in https://github.com/ranahanocka/MeshCNN
class MeshCov(nn.Module):
def __init__(self, in_c, out_c, k=5, bias=True):
super(MeshConv, self).__init__()
self.conv = nn.Conv2d(in_channels=in_c, out_channels=out_c, kernel_size=(1, k), bias=bias)
def forward(self, x)
"""
Forward pass given a feature tensor x with shape (N, C, E, 5):
@Mason-McGough
Mason-McGough / Dockerfile
Last active January 6, 2021 17:05
Dockerfile for Anaconda
# From https://towardsdatascience.com/docker-for-data-science-9c0ce73e8263
# We will use Ubuntu for our image
FROM ubuntu
# Updating Ubuntu packages
RUN apt-get update && yes|apt-get upgrade
# Adding wget and bzip2
RUN apt-get install -y wget bzip2
@Mason-McGough
Mason-McGough / fix_broken_installs.sh
Created June 17, 2020 22:44
FIX: `apt --fix-broken install` does nothing
# "If you want to ignore the file conflict and let dpkg take over the file (even without the Replaces),
# you can pass the --force-overwrite command-line option."
# (https://raphaelhertzog.com/2011/08/01/understanding-dpkgs-file-overwrite-error/)
sudo apt-get -o Dpkg::Options::="--force-overwrite" install --fix-broken
@Mason-McGough
Mason-McGough / dzi_tools.py
Last active March 15, 2019 03:40
A collection of functions for reading, writing, and converting Deep Zoom images
from __future__ import division
from math import sqrt
from os.path import basename, splitext, join
from PIL import Image
import deepzoom
from openslide import open_slide
try:
from functools import reduce
except ImportError: