例如(我可以用Theano做到这一点而没有问题):
# log_var has shape --> (num, )
# Mean has shape --> (?, num)
std_var = T.repeat(T.exp(log_var)[None, :], Mean.shape[0], axis=0)
Run Code Online (Sandbox Code Playgroud)
使用TensorFlow我可以做到这一点:
std_var = tf.tile(tf.reshape(tf.exp(log_var), [1, -1]), (tf.shape(Mean)[0], 1))
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何为Keras做同样的事情,可能是这样的:
std_var = K.repeat(K.reshape(K.exp(log_var), [1, -1]), Mean.get_shape()[0])
Run Code Online (Sandbox Code Playgroud)
要么
std_var = K.repeat_elements(K.exp(log_var), Mean.get_shape()[0], axis=0)
Run Code Online (Sandbox Code Playgroud)
...,因为Mean
在轴0处的尺寸未知。
我需要此用于自定义图层输出:
return K.concatenate([Mean, Std], axis=1)
Run Code Online (Sandbox Code Playgroud) 我的输入状态形状 = (84,84,4)
state = Input(shape=(84,84,4), dtype="float")
Run Code Online (Sandbox Code Playgroud)
它是连续帧的堆叠序列。
我想将此状态传递给 keras 模型作为输入,首先传递给 TimeDistributed 层,然后传递给 LSTM
据我了解,时间步长是第一个维度,我需要适当地重塑我的状态
shape=(4, 84, 84)
Run Code Online (Sandbox Code Playgroud)
并将帧保持在自己的尺寸和拓扑结构中
machine-learning neural-network deep-learning keras tensorflow