recurrent-neural-network

Keras - Input a 3 channel image into LSTM

霸气de小男生 提交于 2019-12-03 12:22:43
I have read a sequence of images into a numpy array with shape (7338, 225, 1024, 3) where 7338 is the sample size, 225 are the time steps and 1024 (32x32) are flattened image pixels, in 3 channels (RGB). I have a sequential model with an LSTM layer: model = Sequential() model.add(LSTM(128, input_shape=(225, 1024, 3)) But this results in the error: Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=4 The documentation mentions that the input tensor for LSTM layer should be a 3D tensor with shape (batch_size, timesteps, input_dim) , but in my case my input_dim is 2D. What is

TensorFlow: Performing this loss computation

ⅰ亾dé卋堺 提交于 2019-12-03 11:45:28
My question and problem is stated below the two blocks of code. Loss Function def loss(labels, logits, sequence_lengths, label_lengths, logit_lengths): scores = [] for i in xrange(runner.batch_size): sequence_length = sequence_lengths[i] for j in xrange(length): label_length = label_lengths[i, j] logit_length = logit_lengths[i, j] # get top k indices <==> argmax_k(labels[i, j, 0, :], label_length) top_labels = np.argpartition(labels[i, j, 0, :], -label_length)[-label_length:] top_logits = np.argpartition(logits[i, j, 0, :], -logit_length)[-logit_length:] scores.append(edit_distance(top_labels,

Keras Masking for RNN with Varying Time Steps

好久不见. 提交于 2019-12-03 10:55:44
I'm trying to fit an RNN in Keras using sequences that have varying time lengths. My data is in a Numpy array with format (sample, time, feature) = (20631, max_time, 24) where max_time is determined at run-time as the number of time steps available for the sample with the most time stamps. I've padded the beginning of each time series with 0 , except for the longest one, obviously. I've initially defined my model like so... model = Sequential() model.add(Masking(mask_value=0., input_shape=(max_time, 24))) model.add(LSTM(100, input_dim=24)) model.add(Dense(2)) model.add(Activation(activate))

What is the upside of using `tf.nn.rnn` instead of `tf.nn.dynamic_rnn` in TensorFlow?

人走茶凉 提交于 2019-12-03 08:37:21
What is the upside of using tf.nn.rnn instead of tf.nn.dynamic_rnn ? The documentation says : [ dynamic_rnn ] is functionally identical to the function rnn above, but performs fully dynamic unrolling of inputs. Is there any case where one might prefer to use tf.nn.rnn instead of tf.nn.dynamic_rnn ? 来源: https://stackoverflow.com/questions/42356027/what-is-the-upside-of-using-tf-nn-rnn-instead-of-tf-nn-dynamic-rnn-in-tensor

How to use multilayered bidirectional LSTM in Tensorflow?

旧城冷巷雨未停 提交于 2019-12-03 06:51:06
I want to know how to use multilayered bidirectional LSTM in Tensorflow. I have already implemented the contents of bidirectional LSTM, but I wanna compare this model with the model added multi-layers. How should I add some code in this part? x = tf.unstack(tf.transpose(x, perm=[1, 0, 2])) #print(x[0].get_shape()) # Define lstm cells with tensorflow # Forward direction cell lstm_fw_cell = rnn.BasicLSTMCell(n_hidden, forget_bias=1.0) # Backward direction cell lstm_bw_cell = rnn.BasicLSTMCell(n_hidden, forget_bias=1.0) # Get lstm cell output try: outputs, _, _ = rnn.static_bidirectional_rnn(lstm

Stream Output of Predictions in Keras

荒凉一梦 提交于 2019-12-03 06:48:23
I have an LSTM in Keras that I am training to predict on time series data. I want the network to output predictions on each timestep, as it will receive a new input every 15 seconds. So what I am struggling with is the proper way to train it so that it will output h_0, h_1, ..., h_t, as a constant stream as it receives x_0, x_1, ...., x_t as a stream of inputs. Is there a best practice for doing this? You can enable statefulness in your LSTM layers by setting stateful=True . This changes the behavior of the layer to always use the state of the previous invocation of the layer instead of

Shuffling training data with LSTM RNN

感情迁移 提交于 2019-12-03 05:09:07
问题 Since an LSTM RNN uses previous events to predict current sequences, why do we shuffle the training data? Don't we lose the temporal ordering of the training data? How is it still effective at making predictions after being trained on shuffled training data? 回答1: In general, when you shuffle the training data (a set of sequences), you shuffle the order in which sequences are fed to the RNN, you don't shuffle the ordering within individual sequences. This is fine to do when your network is

Tensorflow Sequence to sequence model using the seq2seq API ( ver 1.1 and above)

前提是你 提交于 2019-12-03 05:04:42
问题 I'm using TensorFlow v:1.1 , and I would like to implement a sequence to sequence model using tf.contrib.seq2seq api. However I have hard time understanding how to use all the functions (BasicDecoder, Dynamic_decode, Helper, Training Helper ...) provided to build my model. Here is my setup: I would like to "translate" a sequence of feature vector: (batch_size, encoder_max_seq_len, feature_dim) into a sequence of a different length (batch_size, decoder_max_len, 1) . I already have the encoder

doubts regarding batch size and time steps in RNN

依然范特西╮ 提交于 2019-12-03 04:35:09
问题 In Tensorflow's tutorial of RNN: https://www.tensorflow.org/tutorials/recurrent . It mentions two parameters: batch size and time steps. I am confused by the concepts. In my opinion, RNN introduces batch is because the fact that the to-train sequence can be very long such that backpropagation cannot compute that long(exploding/vanishing gradients). So we divide the long to-train sequence into shorter sequences, each of which is a mini-batch and whose size is called "batch size". Am I right

Tensorflow dynamic RNN (LSTM): how to format input?

耗尽温柔 提交于 2019-12-03 03:58:41
问题 I have been given some data of this format and the following details: person1, day1, feature1, feature2, ..., featureN, label person1, day2, feature1, feature2, ..., featureN, label ... person1, dayN, feature1, feature2, ..., featureN, label person2, day1, feature1, feature2, ..., featureN, label person2, day2, feature1, feature2, ..., featureN, label ... person2, dayN, feature1, feature2, ..., featureN, label ... there is always the same number of features but each feature might be a 0