我想為時變資料創建一個使用 TLSTM 的多模式機器學習模型。為了將時變資料與時不變資料連接起來,我需要獲取 TLSTM 的輸出向量。
我正在使用這個 TLSTM 模型:https : //github.com/illidanlab/T-LSTM
我更新了 repo 以與 Tensorflow 1.14 和 Python 3.7.12 兼容。
我假設您可以在 get_output 函式中提取輸出向量:
def get_output(self, state):
output = tf.nn.relu(tf.matmul(state, self.Wo) self.bo)
output = tf.nn.dropout(output, self.keep_prob)
output = tf.matmul(output, self.W_softmax) self.b_softmax
return output
如果我列印輸出,我會得到一個張量:
output = tf.nn.relu(tf.matmul(state, self.Wo) self.bo)
print(output)
-> Tensor("map_5/while/Relu:0", shape=(?, 64), dtype=float32)
print(output[0])
-> Tensor("map_5/while/strided_slice:0", shape=(64,), dtype=float32)
print(output[0, 0])
-> Tensor("map_5/while/strided_slice_1:0", shape=(), dtype=float32)
64 維似乎是我正在尋找的輸出,我該如何訪問它?
解決方案:tf.print()
請注意,在會話內部,它必須被稱為 control_dependence:
def get_output(self, state):
output = tf.nn.relu(tf.matmul(state, self.Wo) self.bo)
print_op = tf.print(
output,
summarize=-1,
output_stream="file://C:/Users/my_path/T-LSTM-master/features/foo.out")
with tf.control_dependencies([print_op]):
output = tf.nn.dropout(output, self.keep_prob)
output = tf.matmul(output, self.W_softmax) self.b_softmax
return output
此示例直接將特征保存為檔案。Summarize=-1 保存/列印整個張量。
uj5u.com熱心網友回復:
如果你只想列印你的output張量,大多數時候tf.print(output)會給你所需的結果。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/409761.html
標籤:
上一篇:我怎樣才能對這個輸出進行排序?
