{{ message }}

Instantly share code, notes, and snippets.

Last active Jul 31, 2021
Memics einops.rearrange for simple cases. Can be simplified with named_tensors. Can be optimized with tracing.
View rearrange.py
 import math def chunk_dim(tensor, chunks, dim=0): """Split a dimension of a tensor into two dimensions""" shape = list(tensor.shape) shape[dim] //= chunks shape.insert(dim, chunks) return tensor.view(shape)
Last active Apr 17, 2021
Frechet's distance entirely in PyTorch with data batches streaming support.
View frechet.py
 """Frechet's distance between two multi-variate Gaussians""" import torch import torch.nn as nn class FrechetDistance: """Frechet's distance between two multi-variate Gaussians https://www.sciencedirect.com/science/article/pii/0047259X8290077X """ def __init__(self, double=True, num_iterations=20, eps=1e-12):
Last active Apr 7, 2021
View neighbors.py
 from typing import Tuple, Optional, Union, List import torch import torch.nn as nn __all__ = [ 'dot', 'get_neighbors', 'gather_features', 'point_sparsity', 'weighted_sampling' ]
Last active Apr 7, 2021
View torch_benchmark.py
 import itertools from typing import Tuple, Optional from contextlib import contextmanager import torch from torch.utils import benchmark # @torch.jit.script def nearest_neighbors(
Last active Apr 7, 2021
View grid_utils.py
 """Utilities for argparse arguments.""" import os import sys from argparse import Namespace from collections import OrderedDict from itertools import product, chain from typing import Union, Dict __all__ = ['parse_grid']
Last active Apr 7, 2021
View video_box_blur.py
 #!/usr/bin/env python3 """Ego4D video box blur.""" import gc import json from pathlib import Path from argparse import ArgumentParser # conda install av pillow tqdm -c conda-forge -c anaconda import av # used versions: av=8.0.3 and ffmpeg=4.3.1 from tqdm import tqdm # used versions: tqdm=4.59.0
Created Feb 27, 2021
View yolov3.py
 """YOLOv3 object detector.""" import math from pathlib import Path from urllib.request import urlopen from PIL import Image from PIL import ImageColor, ImageOps import matplotlib.pyplot as plt import matplotlib.patches as patches
Last active Apr 7, 2021