Home > Enterprise >  Get output layer Tensorflow 1.14
Get output layer Tensorflow 1.14

Time:01-13

I want to create an multi-modal machine learning model using TLSTM for time-variant data. In order to concatinate time-variant with time-invariant data I need to get the output vector of the TLSTM.
I´m using this TLSTM Model: https://github.com/illidanlab/T-LSTM
I updated the repo to be compatible with Tensorflow 1.14 and Python 3.7.12.

I assume you can exreact the output vector at the get_output function:

    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

If I print the output I get an tensor:

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)

The 64 dimension seems to be the output I´m looking for, how can I access it?

Solution: tf.print()

Note that inside of a session it must be called as 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

This example directly saves the feature as a file. Summarize=-1 to save/print the entire tensor.

CodePudding user response:

If you just want to print your output tensor, most of the time tf.print(output) would give you the required result.

  •  Tags:  
  • Related