簡體   English   中英

如何使用循環將操作存儲在tensorflow中?

[英]How to store operations in tensorflow using a loop?

我在想編碼的地方遇到以下問題

 W_hidden = tf.Variable(tf.random_normal(shape = [hidden_size1, hidden_size2], stddev = 0.1), name = "weights_hidden", trainable = True)
 b = tf.Variable(tf.zeros([1, hidden_size2]), name="bias", trainable = True)

 hidden_relu_0 = tf.nn.relu(tf.matmul(BN1[0], W_hidden)+b)
 hidden_relu_1 = tf.nn.relu(tf.matmul(BN1[1], W_hidden)+b)

依此類推,BN1具有一定大小,例如n。 我試圖使用numpy數組,列表,Tensorarray和tf.concat,但是我沒有設法使其工作。

理想情況下,它相當於

 tensor_list = []
 for index in range(0,window_size):
     hidden_relu = tf.nn.relu(tf.matmul(BN1[index], W_hidden)+b)
     tensor_list.append(hidden_relu)

非常感謝你的幫助

好了,您可以在使用循環時使用循環,循環之后,可以使用tf.convert_to_tensor將列表轉換為張量

tf.convert_to_tensor(tensor_list, dtype=tf.float32)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM