initial state in a dynamic_rnn as a placeholder










0















I'd like to enter the tensor to the intial_state of an LSTM as a placeholder so that later on I assign it's value myself during the learning process.



I wrote the following:



import tensorflow as tf
class PGNetwork:
def __init__(self, inpsize, name='PGNetwork'):
tf.reset_default_graph()
self.inpsize = inpsize

with tf.variable_scope(name):
# We create the placeholders
self.inputs_vec = tf.placeholder(tf.float32, [None,
self.inpsize], name="inputs_vec")
self.in_state = tf.placeholder(tf.float32, [1, 16], name="in_state")

self.lstm_layer = tf.contrib.rnn.BasicLSTMCell(16,forget_bias=1)
# self.in_state = self.lstm_layer.zero_state(1, dtype=tf.float32) # By uncommenting this line the error is no longer there.
self.out_rnn, self.rnn_state = tf.nn.dynamic_rnn(self.lstm_layer,
tf.expand_dims(self.inputs_vec, 1), initial_state=self.in_state)

self.output = tf.layers.dense(inputs = self.out_rnn,
kernel_initializer=tf.contrib.layers.xavier_initializer(),
units = 5,
activation=None, name="output")

self.action_distribution = tf.nn.softmax(self.output, name="softmax")

PGNetwork = PGNetwork(8)


I get this error :
Tensor objects are not iterable when eager execution is not enabled. To iterate over this tensor use tf.map_fn.



Which is actually there because of the initial_state in tf.nn.dynamic_rnn() since it is not accepted to be a placeholder.



Is it possible to convert the placeholder to something accepted by the dynamic_rnn????










share|improve this question






















  • if it is defined as a placeholder, you need to feed a value while training. Check here. Initial state can be initialized from zero and cell state/hidden state should be a tuple.

    – ARAT
    Nov 18 '18 at 16:40











  • The network itself is erroneous , this is shown as it gives the error even before running the session. Anyway I knew how to deal with and I will post an answer for it shortly.

    – mahmoud fathy
    Nov 18 '18 at 23:25
















0















I'd like to enter the tensor to the intial_state of an LSTM as a placeholder so that later on I assign it's value myself during the learning process.



I wrote the following:



import tensorflow as tf
class PGNetwork:
def __init__(self, inpsize, name='PGNetwork'):
tf.reset_default_graph()
self.inpsize = inpsize

with tf.variable_scope(name):
# We create the placeholders
self.inputs_vec = tf.placeholder(tf.float32, [None,
self.inpsize], name="inputs_vec")
self.in_state = tf.placeholder(tf.float32, [1, 16], name="in_state")

self.lstm_layer = tf.contrib.rnn.BasicLSTMCell(16,forget_bias=1)
# self.in_state = self.lstm_layer.zero_state(1, dtype=tf.float32) # By uncommenting this line the error is no longer there.
self.out_rnn, self.rnn_state = tf.nn.dynamic_rnn(self.lstm_layer,
tf.expand_dims(self.inputs_vec, 1), initial_state=self.in_state)

self.output = tf.layers.dense(inputs = self.out_rnn,
kernel_initializer=tf.contrib.layers.xavier_initializer(),
units = 5,
activation=None, name="output")

self.action_distribution = tf.nn.softmax(self.output, name="softmax")

PGNetwork = PGNetwork(8)


I get this error :
Tensor objects are not iterable when eager execution is not enabled. To iterate over this tensor use tf.map_fn.



Which is actually there because of the initial_state in tf.nn.dynamic_rnn() since it is not accepted to be a placeholder.



Is it possible to convert the placeholder to something accepted by the dynamic_rnn????










share|improve this question






















  • if it is defined as a placeholder, you need to feed a value while training. Check here. Initial state can be initialized from zero and cell state/hidden state should be a tuple.

    – ARAT
    Nov 18 '18 at 16:40











  • The network itself is erroneous , this is shown as it gives the error even before running the session. Anyway I knew how to deal with and I will post an answer for it shortly.

    – mahmoud fathy
    Nov 18 '18 at 23:25














0












0








0








I'd like to enter the tensor to the intial_state of an LSTM as a placeholder so that later on I assign it's value myself during the learning process.



I wrote the following:



import tensorflow as tf
class PGNetwork:
def __init__(self, inpsize, name='PGNetwork'):
tf.reset_default_graph()
self.inpsize = inpsize

with tf.variable_scope(name):
# We create the placeholders
self.inputs_vec = tf.placeholder(tf.float32, [None,
self.inpsize], name="inputs_vec")
self.in_state = tf.placeholder(tf.float32, [1, 16], name="in_state")

self.lstm_layer = tf.contrib.rnn.BasicLSTMCell(16,forget_bias=1)
# self.in_state = self.lstm_layer.zero_state(1, dtype=tf.float32) # By uncommenting this line the error is no longer there.
self.out_rnn, self.rnn_state = tf.nn.dynamic_rnn(self.lstm_layer,
tf.expand_dims(self.inputs_vec, 1), initial_state=self.in_state)

self.output = tf.layers.dense(inputs = self.out_rnn,
kernel_initializer=tf.contrib.layers.xavier_initializer(),
units = 5,
activation=None, name="output")

self.action_distribution = tf.nn.softmax(self.output, name="softmax")

PGNetwork = PGNetwork(8)


I get this error :
Tensor objects are not iterable when eager execution is not enabled. To iterate over this tensor use tf.map_fn.



Which is actually there because of the initial_state in tf.nn.dynamic_rnn() since it is not accepted to be a placeholder.



Is it possible to convert the placeholder to something accepted by the dynamic_rnn????










share|improve this question














I'd like to enter the tensor to the intial_state of an LSTM as a placeholder so that later on I assign it's value myself during the learning process.



I wrote the following:



import tensorflow as tf
class PGNetwork:
def __init__(self, inpsize, name='PGNetwork'):
tf.reset_default_graph()
self.inpsize = inpsize

with tf.variable_scope(name):
# We create the placeholders
self.inputs_vec = tf.placeholder(tf.float32, [None,
self.inpsize], name="inputs_vec")
self.in_state = tf.placeholder(tf.float32, [1, 16], name="in_state")

self.lstm_layer = tf.contrib.rnn.BasicLSTMCell(16,forget_bias=1)
# self.in_state = self.lstm_layer.zero_state(1, dtype=tf.float32) # By uncommenting this line the error is no longer there.
self.out_rnn, self.rnn_state = tf.nn.dynamic_rnn(self.lstm_layer,
tf.expand_dims(self.inputs_vec, 1), initial_state=self.in_state)

self.output = tf.layers.dense(inputs = self.out_rnn,
kernel_initializer=tf.contrib.layers.xavier_initializer(),
units = 5,
activation=None, name="output")

self.action_distribution = tf.nn.softmax(self.output, name="softmax")

PGNetwork = PGNetwork(8)


I get this error :
Tensor objects are not iterable when eager execution is not enabled. To iterate over this tensor use tf.map_fn.



Which is actually there because of the initial_state in tf.nn.dynamic_rnn() since it is not accepted to be a placeholder.



Is it possible to convert the placeholder to something accepted by the dynamic_rnn????







python tensorflow machine-learning lstm recurrent-neural-network






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 22:42









mahmoud fathymahmoud fathy

101111




101111












  • if it is defined as a placeholder, you need to feed a value while training. Check here. Initial state can be initialized from zero and cell state/hidden state should be a tuple.

    – ARAT
    Nov 18 '18 at 16:40











  • The network itself is erroneous , this is shown as it gives the error even before running the session. Anyway I knew how to deal with and I will post an answer for it shortly.

    – mahmoud fathy
    Nov 18 '18 at 23:25


















  • if it is defined as a placeholder, you need to feed a value while training. Check here. Initial state can be initialized from zero and cell state/hidden state should be a tuple.

    – ARAT
    Nov 18 '18 at 16:40











  • The network itself is erroneous , this is shown as it gives the error even before running the session. Anyway I knew how to deal with and I will post an answer for it shortly.

    – mahmoud fathy
    Nov 18 '18 at 23:25

















if it is defined as a placeholder, you need to feed a value while training. Check here. Initial state can be initialized from zero and cell state/hidden state should be a tuple.

– ARAT
Nov 18 '18 at 16:40





if it is defined as a placeholder, you need to feed a value while training. Check here. Initial state can be initialized from zero and cell state/hidden state should be a tuple.

– ARAT
Nov 18 '18 at 16:40













The network itself is erroneous , this is shown as it gives the error even before running the session. Anyway I knew how to deal with and I will post an answer for it shortly.

– mahmoud fathy
Nov 18 '18 at 23:25






The network itself is erroneous , this is shown as it gives the error even before running the session. Anyway I knew how to deal with and I will post an answer for it shortly.

– mahmoud fathy
Nov 18 '18 at 23:25













0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328905%2finitial-state-in-a-dynamic-rnn-as-a-placeholder%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328905%2finitial-state-in-a-dynamic-rnn-as-a-placeholder%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線