Skip to content

Instantly share code, notes, and snippets.

@JosephDavidsonKSWH
Last active December 18, 2016 19:20
Show Gist options
  • Save JosephDavidsonKSWH/1404e5ea0886a442c2982fae70a4a243 to your computer and use it in GitHub Desktop.
Save JosephDavidsonKSWH/1404e5ea0886a442c2982fae70a4a243 to your computer and use it in GitHub Desktop.
import keras.backend as K
import tensorflow as tf
import numpy as np
import theano
import theano.tensor as T
a = np.ndarray.astype(np.random.rand(4), dtype=np.float32)
b = np.ndarray.astype(np.random.rand(4, 14), dtype=np.float32)
def tftest():
tfa = tf.placeholder(tf.float32, [4])
tfb = tf.placeholder(tf.float32, [4, 14])
try:
result = K.dot(tfa, tfb)
with tf.Session() as sess:
res = sess.run(result, feed_dict={tfa: a, tfb: b})
print(res.shape)
except:
print("Tensorflow Breaks")
def theanotest():
tha = T.fvector()
thb = T.fmatrix()
# Abridged version of the theano backend version
# Because I don't know how to import both backends
def keras_dot_theano(x, y):
return T.dot(x, y)
result = keras_dot_theano(tha, thb)
fun = theano.function([tha, thb], result)
try:
res = fun(a, b)
print(res.shape) # (14L,)
except:
print("Theano Breaks")
if __name__ == "__main__":
tftest()
theanotest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment