This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
OlderNewer