Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 可视化功能映射:索引器错误:数组的索引太多_Python_Matplotlib_Error Handling_Conv Neural Network_Index Error - Fatal编程技术网

Python 可视化功能映射:索引器错误:数组的索引太多

Python 可视化功能映射:索引器错误:数组的索引太多,python,matplotlib,error-handling,conv-neural-network,index-error,Python,Matplotlib,Error Handling,Conv Neural Network,Index Error,在本教程之后,我将尝试可视化要素地图 我的模型如下所示: model.summary() Model: "model_3" __________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to

在本教程之后,我将尝试可视化要素地图

我的模型如下所示:

model.summary()
Model: "model_3"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_5 (InputLayer)            [(None, 224, 224, 3) 0                                            
__________________________________________________________________________________________________
efficientnet-b0 (Functional)    (None, 7, 7, 1280)   4049564     input_5[0][0]                    
__________________________________________________________________________________________________
flatten_4 (Flatten)             (None, 62720)        0           efficientnet-b0[0][0]            
__________________________________________________________________________________________________
branch_0_Dense_16000 (Dense)    (None, 256)          16056576    flatten_4[0][0]                  
__________________________________________________________________________________________________
branch_1_Dense_16000 (Dense)    (None, 256)          16056576    flatten_4[0][0]                  
__________________________________________________________________________________________________
branch_2_Dense_16000 (Dense)    (None, 256)          16056576    flatten_4[0][0]                  
__________________________________________________________________________________________________
branch_3_Dense_16000 (Dense)    (None, 256)          16056576    flatten_4[0][0]                  
__________________________________________________________________________________________________
branch_4_Dense_16000 (Dense)    (None, 256)          16056576    flatten_4[0][0]                  
__________________________________________________________________________________________________
branch_5_Dense_16000 (Dense)    (None, 256)          16056576    flatten_4[0][0]                  
__________________________________________________________________________________________________
branch_6_Dense_16000 (Dense)    (None, 256)          16056576    flatten_4[0][0]                  
__________________________________________________________________________________________________
branch_0_output (Dense)         (None, 35)           8995        branch_0_Dense_16000[0][0]       
__________________________________________________________________________________________________
branch_1_output (Dense)         (None, 35)           8995        branch_1_Dense_16000[0][0]       
__________________________________________________________________________________________________
branch_2_output (Dense)         (None, 35)           8995        branch_2_Dense_16000[0][0]       
__________________________________________________________________________________________________
branch_3_output (Dense)         (None, 35)           8995        branch_3_Dense_16000[0][0]       
__________________________________________________________________________________________________
branch_4_output (Dense)         (None, 35)           8995        branch_4_Dense_16000[0][0]       
__________________________________________________________________________________________________
branch_5_output (Dense)         (None, 35)           8995        branch_5_Dense_16000[0][0]       
__________________________________________________________________________________________________
branch_6_output (Dense)         (None, 35)           8995        branch_6_Dense_16000[0][0]       
__________________________________________________________________________________________________
concatenate_4 (Concatenate)     (None, 245)          0           branch_0_output[0][0]            
                                                                 branch_1_output[0][0]            
                                                                 branch_2_output[0][0]            
                                                                 branch_3_output[0][0]            
                                                                 branch_4_output[0][0]            
                                                                 branch_5_output[0][0]            
                                                                 branch_6_output[0][0]            
__________________________________________________________________________________________________
reshape_4 (Reshape)             (None, 7, 35)        0           concatenate_4[0][0]              
==================================================================================================
Total params: 116,508,561
Trainable params: 116,466,545
Non-trainable params: 42,016
现在,我想可视化索引为10的层:
10分支\u 0\u输出(无,35)

我按照教程中所述的代码,对图像进行了预处理,现在我想绘制该层的35(?)特征图: 我在教程中使用了代码并修改了平方数,这里是1,但我尝试了几种:

# plot all 35 maps
square = 1
ix = 1
for _ in range(square):
    for _ in range(square):
        # specify subplot and turn of axis
        ax = pyplot.subplot(square, square, ix)
        ax.set_xticks([])
        ax.set_yticks([])
        # plot filter channel in grayscale
        pyplot.imshow(feature_maps[0, :, :, ix-1], cmap='gray')
        ix += 1
# show the figure
pyplot.show()
独立于我尝试的号码,我收到以下错误消息:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-28-4c1f464f6978> in <module>()
      9                 ax.set_yticks([])
     10                 # plot filter channel in grayscale
---> 11                 pyplot.imshow(feature_maps[0, :, ix-1], cmap='gray')
     12                 ix += 1
     13 # show the figure

IndexError: too many indices for array
---------------------------------------------------------------------------
索引器回溯(最后一次最近调用)
在()
9 ax.设置锁定([])
10#以灰度绘制过滤器通道
--->11 pyplot.imshow(功能映射[0,:,ix-1],cmap='gray')
12 ix+=1
13#显示该图
索引器:数组的索引太多
有人能帮我修改一下吗


非常感谢

错误显示第11行中数组的索引过多。发生这种情况是因为您在要素地图中错误地传递索引。在这里,您尝试在1*1网格中绘制35张地图,因为您已经给出了square=1


假设您需要绘制
64
地图,那么我们将取
square=8
,然后输出为8*8网格。

错误显示
第11行中数组的索引太多。发生这种情况是因为您在要素地图中错误地传递索引。在这里,您尝试在1*1网格中绘制35张地图,因为您已经给出了square=1


假设您需要绘制
64
地图,那么我们将取
square=8
,然后输出将是一个8*8的网格。

好的,这意味着在我的例子中,它应该是
功能图[0:17,18:35]
?或者你会推荐什么?我已经编辑了我的答案,请参考,看看这是否有效。好的,这意味着在我的例子中,它应该是
功能图[0:17,18:35]
?或者你会推荐什么?我已经编辑了我的答案,请参考,看看这是否有效。
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-28-4c1f464f6978> in <module>()
      9                 ax.set_yticks([])
     10                 # plot filter channel in grayscale
---> 11                 pyplot.imshow(feature_maps[0, :, ix-1], cmap='gray')
     12                 ix += 1
     13 # show the figure

IndexError: too many indices for array