2017-10-16 15 views
0

我正在用tensorflow學習CNN的LSTM。 我想將一些標量標籤放入LSTM網絡中作爲條件。 有誰知道我的意思是哪個LSTM? 如果有,請讓我知道那個的用法LSTM條件

謝謝。

+0

您能否詳細說明「將一些標量標籤放入LSTM網絡作爲條件」是什麼意思? – amirbar

+0

@amirbar這意味着網絡被構建成2個部分 - 分類和LSTM。因此將分類結果放入LSTM網絡作爲提高LSTM性能的條件。 –

+0

只是爲了確保我理解這個問題 - 所以你想要一個使用LSTM和CNN的時間序列預測圖像的例子嗎?您是否試圖在時間序列中預測每個圖像系列圖像或標籤的單個標籤? – amirbar

回答

1

繼承人申請CNN和LSTM一個序列的輸出概率,像你這樣的例子問:

def build_model(inputs): 

    BATCH_SIZE = 4 
    NUM_CLASSES = 2 
    NUM_UNITS = 128 
    H = 224 
    W = 224 
    C = 3 
    TIME_STEPS = 4 
    # inputs is assumed to be of shape (BATCH_SIZE, TIME_STEPS, H, W, C) 
    # reshape your input such that you can apply the CNN for all images 
    input_cnn_reshaped = tf.reshape(inputs, (-1, H, W, C)) 

    # define CNN, for instance vgg 16 
    cnn_logits_output, _ = vgg_16(input_cnn_reshaped, num_classes=NUM_CLASSES) 
    cnn_probabilities_output = tf.nn.softmax(cnn_logits_output) 

    # reshape back to time series convention 
    cnn_probabilities_output = tf.reshape(cnn_probabilities_output, (BATCH_SIZE, TIME_STEPS, NUM_CLASSES)) 

    # perform LSTM over the probabilities per image 
    cell = tf.contrib.rnn.LSTMCell(NUM_UNITS) 
    _, state = tf.nn.dynamic_rnn(cell, cnn_probabilities_output) 

    # employ FC layer over the last state 
    logits = tf.layers.dense(state, NUM_UNITS) 

    # logits is of shape (BATCH_SIZE, NUM_CLASSES) 
    return logits 

順便說一句,一個更好的辦法是聘請LSTM過去隱藏層,即使用CNN作爲特徵提取器並對特徵序列進行預測。

+0

非常感謝!這是我真正想要的。我打算更多地研究LSTM和TF的用法來實現上述概念。謝謝 –