Skip to content

Instantly share code, notes, and snippets.

View YannDubs's full-sized avatar
🦙

Yann Dubois YannDubs

🦙
View GitHub Profile
@YannDubs
YannDubs / interactive_bezier_curves.py
Created September 5, 2022 02:11
Interactive Bezier curve builder for jupyter notebook
%matplotlib widget # need to install ipympl
import numpy as np
from matplotlib.lines import Line2D
from matplotlib.artist import Artist
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
import numpy as np
# Now available here: https://github.com/y0ast/pytorch-snippets/tree/main/minimal_cifar
@phimachine
phimachine / train_valid_split.py
Last active April 10, 2020 12:29
This is a pytorch generic function that takes a data.Dataset object and splits it to validation and training efficiently.
import np
from torch.utils.data import Dataset
class GenHelper(Dataset):
def __init__(self, mother, length, mapping):
# here is a mapping from this index to the mother ds index
self.mapping=mapping
self.length=length
self.mother=mother
@kaniblu
kaniblu / rnn_init.py
Created October 26, 2017 05:14
PyTorch LSTM and GRU Orthogonal Initialization and Positive Bias
def init_gru(cell, gain=1):
cell.reset_parameters()
# orthogonal initialization of recurrent weights
for _, hh, _, _ in cell.all_weights:
for i in range(0, hh.size(0), cell.hidden_size):
I.orthogonal(hh[i:i + cell.hidden_size], gain=gain)
def init_lstm(cell, gain=1):