Skip to content

Instantly share code, notes, and snippets.

View pbloem's full-sized avatar

Peter Bloem pbloem

View GitHub Profile
import numpy as np
import torch
from urllib import request
import gzip
import pickle
import os
def load_mnist(final=False, flatten=True, verbose=False, normalize=True):
"""
Load the MNIST data.
@pbloem
pbloem / infinite_dataset.py
Created May 29, 2022 12:29
Pytorch: use an IterableDataset to create an infinite stream of batched data
from torch.utils.data import IterableDataset, DataLoader
# The dataset has no length
class TestDataset(IterableDataset):
def __iter__(self): # __iter__() can be a generator
while True:
yield 5
# The loader is called as normal
@pbloem
pbloem / data_rnn.py
Created September 2, 2021 14:33
Data loaders for DLVU assignment 3B (recurrent neural nets)
import wget, os, gzip, pickle, random, re, sys
IMDB_URL = 'http://dlvu.github.io/data/imdb.{}.pkl.gz'
IMDB_FILE = 'imdb.{}.pkl.gz'
PAD, START, END, UNK = '.pad', '.start', '.end', '.unk'
def load_imdb(final=False, val=5000, seed=0, voc=None, char=False):
cst = 'char' if char else 'word'
package org.submassive;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pbloem
pbloem / data.py
Last active November 15, 2023 17:13
# -- assignment 1 --
import numpy as np
from urllib import request
import gzip
import pickle
import os
def load_synth(num_train=60_000, num_val=10_000, seed=0):
"""
Load some very basic synthetic data that should be easy to classify. Two features, so that we can plot the
@pbloem
pbloem / kemeny.py
Last active October 6, 2020 10:06
Gradient estimators
import torch
from torch import nn
import torch.distributions as dist
## REINFORCE
adjacencies, num_edges, targets = load_data(...)
opt = ...
@pbloem
pbloem / rgcn.py
Created April 30, 2020 01:43
RGCN implementation from scratch. Untested in gist form. Let me know if you need this for something.
import torch, os, sys
from torch import nn
import torch.nn.functional as F
import torch.distributions as ds
from math import sqrt, ceil
import layers, util
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
from torch.autograd import Variable
from torchvision.transforms import CenterCrop, ToTensor, Compose, Lambda, Resize, Grayscale
from torchvision.datasets import coco
import roslib #; roslib.load_manifest('sr_example')
import rospy
from geometry_msgs.msg import Twist
from std_msgs.msg import Float64, String
rospy.init_node('turtlebot_controller', anonymous=True)
def move(dist, angle):
pub = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)