Skip to content

Instantly share code, notes, and snippets.

View bayerj's full-sized avatar

Justin Bayer bayerj

View GitHub Profile
@bayerj
bayerj / gist:f659687cd7cbc78ca043
Created July 14, 2014 12:20
Theano reshape with -1 does not work on GPU in case of tensor3
from theano import tensor as T
import theano
import numpy as np
x = T.tensor3('')
xf = x.flatten()
xr1 = x.reshape((x.shape[0] * x.shape[1], x.shape[-1]))
xr2 = x.reshape((-1, x.shape[-1]))
ff = theano.function([x], xf)
======================================================================
ERROR: learn.test_cnn.test_cnn_fit
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/bayerj/anaconda/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/bayerj/devel/breze/tests/learn/test_cnn.py", line 52, in test_cnn_fit
m.fit(X, Z)
File "/Users/bayerj/devel/breze/breze/learn/base.py", line 235, in fit
for i, info in enumerate(itr):
@bayerj
bayerj / gist:8842275
Created February 6, 2014 11:13
gensim errors on import of h5py and the neigbors module of sklearn
Error compiling Cython file:
------------------------------------------------------------
...
(H5E_ARGS, H5E_BADTYPE): ValueError, # Invalid location in file
(H5E_REFERENCE, H5E_CANTINIT): ValueError, # Dereferencing invalid ref
}
cdef struct err_data_t:
H5E_error_t err
import theano
import theano.tensor as T
import theano.sandbox.cuda as cuda
from theano.printing import pydotprint
from theano.misc import pycuda_utils
from pycuda.gpuarray import zeros
import pycuda.driver as drv
import pycuda.autoinit
from pycuda.compiler import SourceModule
@bayerj
bayerj / theanodeter.py
Created August 28, 2013 11:20
Tell whether an expression is deterministic, ie it does not use a random number generator.
import theano, theano.tensor as T
from theano.tensor.shared_randomstreams import RandomStreams
def theano_expr_bfs(expr):
stack = [expr]
while True:
if not stack:
break
expr = stack.pop()
dot = (target[:, :, 3:7] * prediction[:, :, 6:10]).sum(axis=2).dimshuffle(0, 1, 'x')
dot = T.clip(dot, -.99, .99)
angle_loss = T.arccos(dot)
return residuals ** 2 + c * angle_loss
numpydoc>=0.4
@bayerj
bayerj / error
Last active December 20, 2015 03:48
Traceback (most recent call last):
File "theanorngclone.py", line 12, in <module>
f = theano.function([x_sub], samples_sub)
File "/Users/bayerj/devel/Theano/theano/compile/function.py", line 222, in function
profile=profile)
File "/Users/bayerj/devel/Theano/theano/compile/pfunc.py", line 506, in pfunc
on_unused_input=on_unused_input)
File "/Users/bayerj/devel/Theano/theano/compile/function_module.py", line 1298, in orig_function
on_unused_input=on_unused_input).create(
File "/Users/bayerj/devel/Theano/theano/compile/function_module.py", line 994, in __init__
@bayerj
bayerj / quaternions.py
Created July 17, 2013 07:15
Some quaternion code for numpy/Theano.
def q_mult(q1, q2):
w1, x1, y1, z1 = q1[:, 0], q1[:, 1], q1[:, 2], q1[:, 3]
w2, x2, y2, z2 = q2[:, 0], q2[:, 1], q2[:, 2], q2[:, 3]
w = w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2
x = w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2
y = w1 * y2 + y1 * w2 + z1 * x2 - x1 * z2
z = w1 * z2 + z1 * w2 + x1 * y2 - y1 * x2
if isinstance(q1, np.ndarray):
w = w[:, np.newaxis]
import theano
import theano.tensor as T
import gnumpy
import theano.misc.gnumpy_utils as gput
g = gnumpy.zeros((1, 2))
g += np.array([[2, 1]])
x = T.matrix()
expr = 2 * x