简体   繁体   中英

How to convert tf.Tensor from max pooling layer into numpy array?

The steps

layer_name = 'avg_pool'
activations = result_model.get_layer(layer_name).get_output_at(0)

give activations which are of following datatype.

How can I obtain the values from it or convert it to numpy aray? The goal is to obtain the intermediate outputs from this layer.

I am not sure about your problem meaning. Do you just want to get value from Tensor? If so, it can be derived easily by activations.eval() or sess.run(activations) . Make sure you have created session by sess = tf.Session() .

While you are debugging tensorflow codes, I suggest you to turn on eager execution mode by put tf.enable_eager_execution() after importing tensorflow. Which will make tensorflow derive values of Tensors in-place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM