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
# prompt: https://twitter.com/francoisfleuret/status/1783479122418716805 | |
import os | |
os.environ['TORCH_LOGS'] = 'output_code' # shows all the bmms | |
import torch | |
torch.set_float32_matmul_precision('high') | |
N, T, D, U, C = 3, 128, 5, 32, 32 # batch, time, heads, head_dim, dim | |
S = T | |
A = torch.randn(N, T, D, U) / U**0.5 |
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 python | |
import math | |
import matplotlib.pyplot as plt | |
import torch | |
import torch.nn as nn | |
from sklearn.datasets import make_moons | |
from torch import Tensor | |
from tqdm import tqdm |
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 geoopt | |
def spherical_avg(p, w=None, tol=1e-6): | |
sphere = geoopt.Sphere() | |
if w is None: | |
w = p.new_ones([p.shape[0]]) | |
assert p.ndim == 2 and w.ndim == 1 and len(p) == len(w) | |
w = w / w.sum() | |
p = sphere.projx(p) |
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 abc | |
import torch | |
from torch import nn, optim | |
class Constraint(nn.Module, metaclass=abc.ABCMeta): | |
def __init__(self, fn, damping): | |
super().__init__() | |
self.fn = fn |
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
# git clone https://github.com/NVlabs/stylegan2 | |
import os | |
import numpy as np | |
from scipy.interpolate import interp1d | |
from scipy.io import wavfile | |
import matplotlib.pyplot as plt | |
import PIL.Image | |
import moviepy.editor | |
import dnnlib |
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 python | |
# -*- coding: utf-8 -*- | |
import glob | |
import librosa | |
import numpy as np | |
import os | |
import sklearn.mixture | |
import sys |
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 python | |
'''Crop an image to just the portions containing text. | |
Usage: | |
./crop_morphology.py path/to/image.jpg | |
This will place the cropped image in path/to/image.crop.png. | |
For details on the methodology, see |
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 contextlib import contextmanager | |
import numpy as np | |
import torch | |
from torch import Tensor, ByteTensor | |
import torch.nn.functional as F | |
from torch.autograd import Variable | |
import pycuda.driver | |
from pycuda.gl import graphics_map_flags | |
from glumpy import app, gloo, gl |