Skip to content

Instantly share code, notes, and snippets.

Will Price willprice

Block or report user

Report or block willprice

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@willprice
willprice / collate.py
Created Mar 20, 2020
Collate a list of dictionaries into a dictionary of lists
View collate.py
__all__ = ['collate_dicts']
from typing import List, Dict, Any
from collections import defaultdict
def collate_dicts(ds: List[Dict[Any, Any]]) -> Dict[Any, List[Any]]:
"""
Args:
ds: A list of dictionarys all with the same keys.
@willprice
willprice / charades_csv_reader.py
Last active Feb 12, 2020
Script to read Charades CSV files (Charades_v1_train.csv, Charades_v1_test.csv) into a pandas DataFrame where each row represents a single action
View charades_csv_reader.py
import pandas as pd
from csv import DictReader
from collections import defaultdict
import numpy as np
def read_charades_csv(path):
def parse_action(action_str):
cls, start, stop = action_str.split(' ')
return {
'class': int(cls[1:]),
'start': float(start),
@willprice
willprice / grid_show.py
Created Oct 9, 2019
Matplotlib snippet for visualising matrices nicely.
View grid_show.py
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(context='paper', style='whitegrid')
def grid_show(grid, horizontal_labels, vertical_labels=None, cmap='binary', grid_color='#efefef'):
ax = plt.gca()
image = ax.imshow(grid,
@willprice
willprice / stack.py
Created Oct 1, 2019
PIL Image stacking
View stack.py
from PIL import Image
def vstack(images):
if len(images) == 0:
raise ValueError("Need 0 or more images")
if isinstance(images[0], np.ndarray):
images = [Image.fromarray(img) for img in images]
width = max([img.size[0] for img in images])
height = sum([img.size[1] for img in images])
@willprice
willprice / remove_old_kernels.sh
Created Sep 9, 2019
Remove old kernels from ubuntu
View remove_old_kernels.sh
#!/bin/bash
set +ex
KEEP_LAST_N=2
OLD_KERNELS=$(dpkg -l | grep -i 'linux-image-[[:digit:]]' | awk '{ print $2 }' | sort -rV | tail -n "+$(($KEEP_LAST_N + 1))")
if [ -n "$OLD_KERNELS" ]; then
apt-get -qy remove --purge $OLD_KERNELS
fi
apt-get -qy autoremove --purge
View PBS_PRO_CHEAT_SHEET.md

PBS Pro command cheat sheet

List nodes and their features

$ pbsnodes

@willprice
willprice / KINETICS_LABELS.md
Last active Mar 1, 2020
Kinetics Dataset Labels (name to ID)
View KINETICS_LABELS.md

Kinetics Numeric/String labels

These are mapping files that go between class IDs to class names. These are generated from the training CSV files from each dataset by collecting the unique classes, sorting them, and then numbering them from 0 upwards.

@willprice
willprice / axis_tick_spacing.py
Created Jul 22, 2019
Set tick spacing on matplotlib axis
View axis_tick_spacing.py
from matplotlib import ticker
ax.yaxis.set_major_locator(ticker.MultipleLocator(tick_spacing))
View SLURM_CHEATSHEET.md

Find the node assigned to a job

$ sacct -j <jobid> --format NodeList
       NodeList
---------------
         dgj213
         dgj213
You can’t perform that action at this time.