Home>

There are 2048 channels without the Conv layer in the middle of the CNN, and the shape is (7,7,2048). When calculating the total value of all channels, it is possible to do it with one image, but I do not know how to do it with multiple images (eg, 8 images (8,7,7,2048)).

Data shape and code
print (layer_outputs.shape) # (8,7,7,2048)
# After specifying the shape, pad h and w with zero.
h, w, ch = layer_outputs.shape [1:]
res = np.zeros ((h, w))
# 1 image can be extracted below
for i in range (ch):
    img_res = layer_outputs [0 ,:,:, i] # 0
    res = res + img_res
#Trial with multiple images
lst = []
for i in range (ch):
    for n in range (len (layer_outputs)):
        img_res = layer_outputs [n,:,:, i]
        res = res + img_res
        lst.append (res)
#The result is 16384 (8 * 2048), which is not classified by the number of images.
np.array (lst) .shape # (16384, 7, 7)

Other

img_res = layer_outputs [n,:,:, i]
img_res = layer_outputs [n] [:,:, i]
I tried it with, but the result was the same as above.


The desired shape is (8,7,7).
How can I calculate the total value for each image?
I would be grateful if you could teach me. Thank you.

  • Answer # 1

    understood. I entered if I divided it into two stages. I apologize to you for a fuss over.

    lst = []
    for img_idx in range (len (X)):
        layer_output = layer_outputs [img_idx]
        h, w, ch = layer_output.shape
        res = np.zeros ((h, w))
        for i in range (ch):
            img_res = layer_output [:,:, i]
            res = res + img_res
        lst.append (res)