Skip to content

Instantly share code, notes, and snippets.

View skaae's full-sized avatar

Søren Kaae Sønderby skaae

View GitHub Profile
def adam(loss, all_params, learning_rate=0.001, b1=0.9, b2=0.999, e=1e-8,
gamma=1-1e-8):
"""
ADAM update rules
Default values are taken from [Kingma2014]
References:
[Kingma2014] Kingma, Diederik, and Jimmy Ba.
"Adam: A Method for Stochastic Optimization."
arXiv preprint arXiv:1412.6980 (2014).
import tensorflow as tf
data_arr = [
{
"img": np.random.randn(10, 30)
},
{
"img": np.random.randn(10, 30)
}
]
@skaae
skaae / data.py
Created August 29, 2019 14:01
tf.data
# Skriv records fil med et sample og forsoeg at loade det igen med tf.data
import numpy as np
import tensorflow as tf
## WRITE SINGLE EXAMPLE
label = 1
FILEPATH = "TEST_RECORDS"
import numpy as np
class ConfusionMatrix:
"""
Simple confusion matrix class
row is the true class, column is the predicted class
"""
def __init__(self, n_classes, class_names=None):
self.n_classes = n_classes
if class_names is None:
self.class_names = map(str, range(n_classes))
@skaae
skaae / gist:f434450b16df01739bada8a92fcfba97
Created March 18, 2017 12:57
build cudnn 6.05 -> torch report 5.15
(pytorch_build) sorson@hyperion:~$ git clone https://github.com/pytorch/pytorch.git
Cloning into 'pytorch'...
remote: Counting objects: 24898, done.
remote: Compressing objects: 100% (38/38), done.
remote: Total 24898 (delta 8), reused 0 (delta 0), pack-reused 24860
Receiving objects: 100% (24898/24898), 15.81 MiB | 7.68 MiB/s, done.
Resolving deltas: 100% (18207/18207), done.
Checking connectivity... done.
(pytorch_build) sorson@hyperion:~$ cd pytorch
(pytorch_build) sorson@hyperion:~/pytorch$ export CUDA_HOME=/usr/local/cuda
@skaae
skaae / MyConfusionMatrix.Lua
Created August 8, 2015 16:19
confusion matrix for torch
--[[ A Confusion Matrix class
Example:
conf = optim.ConfusionMatrix( {'cat','dog','person'} ) -- new matrix
conf:zero() -- reset matrix
for i = 1,N do
conf:add( neuralnet:forward(sample), label ) -- accumulate errors
end
print(conf) -- print matrix
import numpy as np
import theano
import theano.tensor as T
import lasagne.nonlinearities as nonlinearities
import lasagne.init as init
from lasagne.utils import unroll_scan
from lasagne.layers import *
import lasagne.layers.helper as helper
@skaae
skaae / adam.py
Created February 26, 2015 14:53
def adam(loss, all_params, learning_rate=0.0002, beta1=0.1, beta2=0.001,
epsilon=1e-8, gamma=1-1e-7):
"""
ADAM update rules
Default values are taken from [Kingma2014]
References:
[Kingma2014] Kingma, Diederik, and Jimmy Ba.
"Adam: A Method for Stochastic Optimization."
arXiv preprint arXiv:1412.6980 (2014).
import numpy as np
import theano
import theano.tensor as T
from theano import ifelse
from .. import init
from .. import nonlinearities
from .base import Layer
from __future__ import print_function
import gzip
import itertools
import pickle
import os
import sys
PY2 = sys.version_info[0] == 2