简体   繁体   中英

How to access the channel dimensions of a tensor

I have an output of tensor shape [32,24,24,6] ie [batch_size,height,width,channel dimension]. I want to access the channel dimension values and work on it, maybe get it as a tuple or list of tensors which i plan to use in the elems of tf.map_fn. I tried using indexing([-1, -1, -1, 0:6]) but i am not sure if it is right way. Is there a right way in which i can access the channel dimension? Can i try tensor.get_shape().as_list() and then access by using for loop?I am confused, any suggestions will be appreciated.

You can use the keras backend, which also works in graph mode. Here an example:

import tensorflow as tf
testTensor = tf.random.uniform(shape = (32,128,128,3))
shape = tf.keras.backend.int_shape(testTensor) # (32,128,128,3)

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