-
-
Save andrewssobral/bda5e1480c47f7b3d2d8c7ea669b6b42 to your computer and use it in GitHub Desktop.
tensorflow_test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import numpy as np | |
import time | |
from tensorflow.contrib.rnn import BasicLSTMCell | |
# https://github.com/tensorflow/tensorflow/issues/24828 | |
try: | |
from tensorflow.compat.v1 import ConfigProto | |
from tensorflow.compat.v1 import InteractiveSession | |
config = ConfigProto() | |
config.gpu_options.allow_growth = True | |
session = InteractiveSession(config=config) | |
except: | |
pass | |
N = 1 | |
L = 500 | |
d = 10 | |
k = 1 | |
V = 1000 | |
inputs = tf.placeholder('int64', [N, L]) | |
emb_mat = tf.get_variable('emb_mat', shape=[V, d]) | |
x = tf.nn.embedding_lookup(emb_mat, inputs) | |
lstm_cell = BasicLSTMCell(d) | |
a, (c, h) = tf.nn.dynamic_rnn(lstm_cell, x, dtype='float') | |
init_op = tf.global_variables_initializer() | |
with tf.Session() as sess: | |
sess.run(init_op) | |
inputs_val = np.zeros([N, L], dtype='int64') | |
t0 = time.time() | |
for _ in range(k): | |
out = sess.run(h, feed_dict={inputs: inputs_val}) | |
t1 = time.time() | |
print(t1 - t0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment