我想在Tensorflow中设计单层RNN,以便最后输出(y(t-1))参与更新隐藏状态.
h(t) = tanh(W_{ih} * x(t) + W_{hh} * h(t) + **W_{oh}y(t - 1)**)
y(t) = W_{ho}*h(t)
Run Code Online (Sandbox Code Playgroud)
如何将最后输入y(t - 1)作为输入提供以更新隐藏状态?
有没有人能够在Tensorflow中混合前馈层和重复层?
例如:input-> conv-> GRU-> linear-> output
我可以想象一个人可以用前馈层定义他自己的单元格而没有可以使用MultiRNNCell函数堆叠的状态,如:
cell = tf.nn.rnn_cell.MultiRNNCell([conv_cell,GRU_cell,linear_cell])
这会让生活变得更轻松......
python tensorflow recurrent-neural-network gated-recurrent-unit
我是RNN的新手,我正在试图找出LSTM细胞的细节,它们与TensorFlow有关:Colah GitHub
与TensorFlow相比,GitHub网站的示例使用相同的LSTM单元吗?我在TensorFlow网站上唯一得到的是基本LSTM单元使用以下架构:Paper如果它是相同的架构,那么我可以手工计算LSTM单元的数字并查看它是否匹配.
此外,当我们在张量流中设置基本LSTM单元时,它会num_units根据:TensorFlow文档获取
tf.nn.rnn_cell.GRUCell.__init__(num_units, input_size=None, activation=tanh)
Run Code Online (Sandbox Code Playgroud)
这个隐藏状态(h_t)和细胞状态(C_t)的数量是多少?
根据GitHub网站,没有提到细胞状态和隐藏状态的数量.我假设他们必须是相同的号码?
我想知道如何在Tensorflow中使用多层双向LSTM.
我已经实现了双向LSTM的内容,但我想将此模型与添加的多层模型进行比较.
我该如何在这部分中添加一些代码?
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_fw_cell, lstm_bw_cell, x,
dtype=tf.float32)
except Exception: # Old TensorFlow version only returns outputs not states
outputs = rnn.static_bidirectional_rnn(lstm_fw_cell, lstm_bw_cell, x,
dtype=tf.float32)
# Linear activation, using rnn inner loop last output
outputs = tf.stack(outputs, axis=1)
outputs = tf.reshape(outputs, (batch_size*n_steps, …Run Code Online (Sandbox Code Playgroud) bidirectional multi-layer lstm tensorflow recurrent-neural-network
我正在构建一个用于分类的RNN(在RNN之后有一个softmax层)。要进行正则化的选项有很多,我不确定是否只尝试所有这些,效果会一样吗?在什么情况下我应该规范哪些组件?
这些组件是:
python regularized deep-learning keras recurrent-neural-network
我试图用keras编写一个非常简单的RNN示例,但结果并不像预期的那样.
我的X_train是一个长度为6000的重复列表,如: 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, ...
我将其格式化为: (6000, 1, 1)
我的y_train是一个长度为6000的重复列表,如: 1, 0.8, 0.6, 0, 0, 0, 1, 0.8, 0.6, 0, ...
我将其格式化为: (6000, 1)
根据我的理解,递归神经网络应该学会正确地预测0.8和0.6,因为它可以记住两个时间段前X_train中的1.
我的模特:
model=Sequential()
model.add(SimpleRNN(input_dim=1, output_dim=50))
model.add(Dense(output_dim=1, activation = "sigmoid"))
model.compile(loss="mse", optimizer="rmsprop")
model.fit(X_train, y_train, nb_epoch=10, batch_size=32)
Run Code Online (Sandbox Code Playgroud)
该模型可以成功训练,损失最小〜0.1015但结果不如预期.
test case --------------------------------------------- model result -------------expected result
model.predict(np.array([[[1]]])) --------------------0.9825--------------------1
model.predict(np.array([[[1],[0]]])) ----------------0.2081--------------------0.8
model.predict(np.array([[[1],[0],[0]]])) ------------0.2778 -------------------0.6
model.predict(np.array([[[1],[0],[0],[0]]]))---------0.3186--------------------0
Run Code Online (Sandbox Code Playgroud)
我在这里有什么误解吗?
我正在尝试开发一个神经网络来预测时间序列.
据我所知,我正在训练我的神经网络训练集并用测试集验证它.
当我对我的结果感到满意时,我可以使用我的神经网络来预测新值,而神经网络本身基本上只是我使用训练集调整的所有权重.
它是否正确?
如果是这样,我应该只训练我的网络一次,然后只使用我的网络(权重)来预测未来的价值.您通常如何避免重新计算整个网络?我是否应该将所有权重保存在数据库或其他内容中,以便我可以随时访问它而无需再次训练?
如果我的理解是正确的,我可以在专用计算机(例如超级计算机)上进行大量计算,然后在网络服务器,iPhone应用程序或类似的东西上使用我的网络,但我不知道如何存储它.
python machine-learning neural-network heavy-computation recurrent-neural-network
我将有状态LSTM定义为顺序模型:
model = Sequential()
model.add(LSTM(..., stateful=True))
...
Run Code Online (Sandbox Code Playgroud)
后来,我将它用作功能模型:
input_1, input_2 = Input(...), Input(...)
output_1 = model(input_1)
output_2 = model(input_2) # Is the state from input_1 preserved?
Run Code Online (Sandbox Code Playgroud)
input_1当我们model再次申请时,input_2是否保留了州 ?如果是,我如何在呼叫之间重置模型状态?
python machine-learning neural-network keras recurrent-neural-network
这是我的问题,我想在 TimeDistributed 层中使用预训练 CNN 网络之一。但是我在实施它时遇到了一些问题。
这是我的模型:
def bnn_model(max_len):
# sequence length and resnet input size
x = Input(shape=(maxlen, 224, 224, 3))
base_model = ResNet50.ResNet50(weights='imagenet', include_top=False)
for layer in base_model.layers:
layer.trainable = False
som = TimeDistributed(base_model)(x)
#the ouput of the model is [1, 1, 2048], need to squeeze
som = Lambda(lambda x: K.squeeze(K.squeeze(x,2),2))(som)
bnn = Bidirectional(LSTM(300))(som)
bnn = Dropout(0.5)(bnn)
pred = Dense(1, activation='sigmoid')(bnn)
model = Model(input=x, output=pred)
model.compile(optimizer=Adam(lr=1.0e-5), loss="mse", metrics=["accuracy"])
return model
Run Code Online (Sandbox Code Playgroud)
编译模型时我没有错误。但是当我开始训练时,我收到以下错误:
tensorflow/core/framework/op_kernel.cc:975] Invalid argument: You must feed a value …Run Code Online (Sandbox Code Playgroud) 给定具有维度的X (m个样本,n个序列和k个特征),以及具有维度的y个标签(m个样本,0/1):
假设我想训练一个有状态的LSTM(通过keras定义,其中"stateful = True"意味着每个样本的序列之间没有重置单元状态 - 如果我错了请纠正我!),是否应该重置状态在每个时期或每个样本的基础上?
例:
for e in epoch:
for m in X.shape[0]: #for each sample
for n in X.shape[1]: #for each sequence
#train_on_batch for model...
#model.reset_states() (1) I believe this is 'stateful = False'?
#model.reset_states() (2) wouldn't this make more sense?
#model.reset_states() (3) This is what I usually see...
Run Code Online (Sandbox Code Playgroud)
总之,我不确定是否在每个序列或每个时期之后重置状态(在所有m个样本都在X中训练之后).
建议非常感谢.