Skip to content

Instantly share code, notes, and snippets.

View Multihuntr's full-sized avatar

Brandon Victor Multihuntr

  • La Trobe University
View GitHub Profile
@Multihuntr
Multihuntr / mean_avg_precision.py
Created July 28, 2021 11:36
Mean average precision for object detection
# Reimplementation of: https://github.com/aladdinpersson/Machine-Learning-Collection/blob/master/ML/Pytorch/object_detection/metrics/mean_avg_precision.py
# Now with more vectorisation!
def precision_recall_curve_th(is_tp, confs, n_true, eps=1e-8):
# Sort by confs
order = (-confs).argsort()
is_tp = is_tp[order]
confs = confs[order]
# Cumulative sum true positives and number of predictions
@Multihuntr
Multihuntr / mat3.py
Last active January 7, 2022 01:31
Random Affine Crop in the style of Albumentations for a Rasterio Dataset with minimal dependencies
# Utility functions for managing 3x3 matrices for cv2.warpAffine in pure numpy
import numpy as np
def identity():
return np.eye(3, dtype=np.float64)
def affine(A=None, t=None):
@Multihuntr
Multihuntr / wrapper.py
Created April 24, 2020 10:38
Generic Pytorch Module Wrapper - When nn.Sequential just isn't enough
# I keep properties on my main nn.Modules. e.g. a list of the training statistics the model is tracking.
# I wanted to perform a set of extra actions across multiple different modules without having to
# - write those steps into each of the 5+ different model definitions, or
# - explicitly expose those values on the wrapper module.
# It's fairly trivial, but if you don't use the try: super(), it doesn't keep the `wrapped` property.
import torch
import torch.nn as nn
class Wrapper(nn.Module):