import tensorflow as tf
import numpy as np
import keras
from keras.layers import convlstm2d
lstm_input = np.random.random((4,6,30,30,3)).astype(np.float32)
lstm_input = tf.convert_to_tensor(lstm_input)
lstm_out1 = convlstm2d(filters=1,kernel_size=[5,5],strides=(1,1),padding='valid',activation='relu',
input_shape=(6,30,30,3),return_sequences=true)(lstm_input)
lstm_out2 = convlstm2d(filters=2,kernel_size=[5,5],strides=(1,1),padding='valid',activation='relu',
return_sequences=true)(lstm_out1)
lstm_out3 = convlstm2d(filters=3,kernel_size=[5,5],strides=(1,1),padding='valid',activation='relu',
return_sequences=true)(lstm_out2)
with tf.session() as sess:
sess.run(tf.global_variables_initializer())
lstm_out1_,lstm_out2_,lstm_out3_ = sess.run([lstm_out1,lstm_out2,lstm_out3])
print(lstm_out1_.shape)
print(lstm_out2_.shape)
print(lstm_out3_.shape)
"""返回:
(4, 6, 26, 26, 1)
(4, 6, 22, 22, 2)
(4, 6, 18, 18, 3)
"""
備註:
return_sequences: 預設是false,控制lstm的輸出:
用return_state=true控制
import tensorflow as tf
import numpy as np
import keras
from keras.layers import convlstm2d
lstm_input = np.random.random((4,6,30,30,3)).astype(np.float32)
lstm_input = tf.convert_to_tensor(lstm_input)
lstm_out,state_h,state_c = convlstm2d(filters=1,kernel_size=[5,5],strides=(1,1),padding='valid',activation='relu',
batch_input_shape=(-1,6,30,30,3),return_sequences=false,return_state=true)(lstm_input)
with tf.session() as sess:
sess.run(tf.global_variables_initializer())
lstm_out_,state_h_,state_c_= sess.run([lstm_out,state_h,state_c])
print(lstm_out_==state_h_)
print(lstm_out_.shape)
print(state_h_.shape)
print(state_c_.shape)
"""返回:
[ true]]]]
(4, 26, 26, 1)
(4, 26, 26, 1)
(4, 26, 26, 1)
"""
綜上:
return_sequences: 決定是否返回所有時刻的狀態
return_state:決定是否返回最後乙個時刻的cell狀態,由示例2結果可見,最後乙個時刻的state = [h,c]
注意:在keras 中文文件中,在介紹convlstm2d時,沒有介紹 return_state 引數,該引數在lstm的介紹中介紹,但是在convlstm2d中通用。。。自己差點以為convlstm2d中沒有這個功能。。。
D2D技術介紹
一 d2d技術概述 d2d device to device 通訊是由3gpp組織提出的一種在通訊系統的控制下,允許lte終端之間在沒有基礎網路設施的情況下,利用小區資源直接進行通訊的新技術。它能夠提公升通訊系統的頻譜效率,在一定程度上解決無線通訊系統頻譜資源匱乏的問題。與此同時,它還可以有效降低終...
2d 2d對極幾何約束
include iostream include include include include include extra.h use this if in opencv2 using namespace std using namespace cv void find feature match...
2D遊戲開發(2)
每次給遊戲新增新功能時,通常也會引入一些新設定。為了讓所有的設定進行統一管理,我們可以配置乙個名為 setting的模組,這個模組中包含乙個setting的類,用來儲存所有的設定。usr bin env python3.5 filename setting 儲存所有的設定 class setting...