Skip to content

Instantly share code, notes, and snippets.

View afspies's full-sized avatar
🐐

Alex Spies afspies

🐐
View GitHub Profile
@afspies
afspies / iclp_schedule_spec.json
Last active May 31, 2023 22:22
ICLP Schedule Spec
{
"url": "https://calendar.google.com/calendar/ical/a0743f85a7e10fa90a0dabedbc0742ffd67995ae7ad5a8d90ed0ed35efacdf5e%40group.calendar.google.com/public/basic.ics",
"title": "ICLP 2023 Schedule",
"date": "2023-07-09",
"starting_hour": "8",
"ending_hour": "20",
"hour_division": "2",
"target": "_self",
"start_of_week": "su",
"timezone": "Europe/London",
@afspies
afspies / printarr
Last active February 26, 2023 11:23 — forked from nmwsharp/printarr
Pretty print tables summarizing properties of tensor arrays in numpy, pytorch, jax, etc.
Pretty print tables summarizing properties of tensor arrays in numpy, pytorch, jax, etc.
@afspies
afspies / q.uiver_tex_colors.tex
Created April 15, 2022 12:01
q.uiver matplotlib color scheme
// Color definitions to override the quiver web color scheme with matplotlib colors defined as tex macros
// This allows easy creation of stylistically consistent Tikz diagrams with relative ease
@afspies
afspies / gpu_allocation.py
Last active March 14, 2024 02:02
Automatic GPU Allocation
# EDIT 10/04/2022 - This version was provided by @jayelm who fixed some bugs and made the function much more robust
import os
import subprocess
import time
def assign_free_gpus(threshold_vram_usage=1500, max_gpus=2, wait=False, sleep_time=10):
"""
Assigns free gpus to the current process via the CUDA_AVAILABLE_DEVICES env variable
This function should be called after all imports,
@afspies
afspies / set_seed.py
Last active April 13, 2022 13:30 — forked from rish-16/tf_seed.py
Experiment Seeding for GPUs
import os
import numpy as np
import random
import tensorflow as tf
# from tfdeterminism import patch - only in older versions (<2?) of Tensorflow
# import torch
def seed(seed=42):
@afspies
afspies / shape_conventions.py
Created December 25, 2021 14:46
Python Library Shape Conventions
# Originally taken from Xander Steenbrugge
# cv2:
height, width, _ = img.shape
img_resized = cv2.resize(img, (new_width, new_height))
img_pixel_values = img[top:down, left:right, :]
# PIL
width, height = img.size
img_resized = img.resize((new_width, new_height))
@afspies
afspies / drawio_matplotlib_cols.yaml
Last active February 15, 2023 20:41
Draw.io Matplotlib Colorscheme
// Light Mode
{
"customColorSchemes": [[
{"fill": "#2282bc", "stroke": "none"}, // blue
{"fill": "#17c6d5", "stroke": "none"}, // cyan
{"fill": "#c4c526", "stroke": "none"}, // yellow
{"fill": "#e782c9", "stroke": "none"}, // pink
{"fill": "#9e72c5", "stroke": "none"}, // purple
{"fill": "#db2c2d", "stroke": "none"}, // red
{"fill": "#32aa32", "stroke": "none"}, // green
@afspies
afspies / gdrive_wget.sh
Created August 9, 2021 19:06
Google Drive Download
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=FILEID" -O FILENAME && rm -rf /tmp/cookies.txt
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@afspies
afspies / configlib.py
Last active January 17, 2021 17:39 — forked from nuric/configlib.py
"""Configuration library for experiments.
Based on version by Nuri C. https://gist.github.com/nuric/e9df5e38c34c804ec6c298ffca7e2d9b
-- USAGE --
In Header:
import config.configlib as configlib
from config.configlib import config as C
parser = configlib.add_parser("File Spec Config")
parser.add_argument("--mlp_size", default=128, type=int, help="Size of Output MLP")