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
import math | |
import torch | |
import numpy as np | |
class Sphere: | |
def __init__(self, position, radius): | |
self.position = position | |
self.radius = radius | |
def reflect(self, rays, points): |
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
from functools import partial | |
import torch | |
from torch import nn | |
from torch.autograd import grad | |
from torch.autograd.functional import jacobian, jvp | |
def rand_cov(vector): | |
"""Create a covariance matrix from the specs of a given vector.""" |
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
#!/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 |
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
"""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'] |
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
from typing import Tuple, Optional, Union, List | |
import torch | |
import torch.nn as nn | |
__all__ = [ | |
'dot', 'get_neighbors', 'gather_features', 'point_sparsity', | |
'weighted_sampling' | |
] |
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
"""Matrix square root: https://github.com/pytorch/pytorch/issues/25481""" | |
import torch | |
def psd_matrix_sqrt(matrix, num_iterations=20): | |
"""Compute the square root of a PSD matrix using Newton's method. | |
This implementation was adopted from code by @JonathanVacher. | |
https://gist.github.com/ModarTensai/7c4aeb3d75bf1e0ab99b24cf2b3b37a3 | |
""" |
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
from torch import nn | |
class Generator(nn.Module): | |
def __init__(self, input_dim, image_shape, memory): | |
super().__init__() | |
self.memory = memory | |
self.input_dim = input_dim | |
self.image_shape = image_shape |
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
import numpy as np | |
from PIL import Image | |
from skimage.color import lab2rgb, rgb2lab | |
class RandomColorToning: | |
def __init__(self, scale_mean, scale_std, shift_mean, shift_std): | |
self.scale_mean = scale_mean | |
self.scale_std = scale_std |
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
import json | |
import math | |
from argparse import ArgumentParser | |
from contextlib import contextmanager | |
from pathlib import Path | |
import torch | |
import torchvision.transforms as T | |
from torch import nn | |
from torch.optim import lr_scheduler |
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
class LARC: | |
"""Layer-wise Adaptive Rate Control. | |
LARC is LARS that supports clipping along with scaling: | |
https://arxiv.org/abs/1708.03888 | |
This implementation is inspired by: | |
https://github.com/NVIDIA/apex/blob/master/apex/parallel/LARC.py | |
See also: |