Skip to content

Instantly share code, notes, and snippets.

View pbloem's full-sized avatar

Peter Bloem pbloem

View GitHub Profile
from datetime import datetime
import numpy as np
from keras import Input
import keras.backend as K
from keras.callbacks import TensorBoard
from keras.engine import Model
from keras.layers import LSTM, TimeDistributed, Dense, Reshape, Flatten, LeakyReLU, Lambda
from keras.optimizers import Adam, sgd
import torch
from torch.autograd import Variable
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import torchvision
import torchvision.transforms as transforms
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)
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
@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
@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 / data.py
Last active November 14, 2025 13:24
# -- 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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;
@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'