tensorflow去掉某一维度_在Python中解压缩(取消堆栈)一个输入(占位符),在tensorflow中有一个None维度...
我正在嘗試使用具有不同時間步長(不同幀數)的輸入的LSTM. rnn.static_rnn的輸入應該是tf(不是tf!)的序列.所以,我應該將輸入轉換為序列.我試圖使用tf.unstack和tf.split,但是他們都需要知道輸入的確切大小,而我的輸入的一個維度(時間步長)正在通過不同的輸入改變.以下是我的代碼的一部分:
n_input = 256*256 # data input (img shape: 256*256)
n_steps = None # timesteps
batch_size = 1
# tf Graph input
x = tf.placeholder("float", [ batch_size , n_input,n_steps])
y = tf.placeholder("float", [batch_size, n_classes])
# Permuting batch_size and n_steps
x1 = tf.transpose(x, [2, 1, 0])
x1 = tf.transpose(x1, [0, 2, 1])
x3=tf.unstack(x1,axis=0)
#or x3 = tf.split(x2, ?, 0)
# Define a lstm cell with tensorflow
lstm_cell = rnn.BasicLSTMCell(num_units=n_hidden, forget_bias=1.0)
# Get lstm cell output
outputs, states = rnn.static_rnn(lstm_cell, x3, dtype=tf.float32,sequence_length=None)
當我使用tf.unstack時出現以下錯誤:
ValueError: Cannot infer num from shape (?, 1, 65536)
此外,還有一些討論here和here,但沒有一個對我有用.任何幫助表示贊賞.
如
here中所述,如果參數未指定且不可推斷,則tf.unstack不起作用.
在代碼中,在轉置之后,x1的形狀為[n_steps,batch_size,n_input],其在axis = 0處的值設置為None.
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的tensorflow去掉某一维度_在Python中解压缩(取消堆栈)一个输入(占位符),在tensorflow中有一个None维度...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: geotif 添加坐标_python –
- 下一篇: python内置函数 pdf_关于Pyt