Keras-vis给出以下错误:AttributeError:多个入站节点 [英] Keras-vis gives following error: AttributeError: Multiple inbound nodes

查看:228
本文介绍了Keras-vis给出以下错误:AttributeError:多个入站节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循此示例带有我自己的模型,如下所示:

I'm trying to follow this example with my own model which looks like this:

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_2 (InputLayer)         (None, 150, 150, 3)       0         
_________________________________________________________________
block1_conv1 (Conv2D)        (None, 150, 150, 64)      1792      
_________________________________________________________________
block1_conv2 (Conv2D)        (None, 150, 150, 64)      36928     
_________________________________________________________________
block1_pool (MaxPooling2D)   (None, 75, 75, 64)        0         
_________________________________________________________________
block2_conv1 (Conv2D)        (None, 75, 75, 128)       73856     
_________________________________________________________________
block2_conv2 (Conv2D)        (None, 75, 75, 128)       147584    
_________________________________________________________________
block2_pool (MaxPooling2D)   (None, 37, 37, 128)       0         
_________________________________________________________________
block3_conv1 (Conv2D)        (None, 37, 37, 256)       295168    
_________________________________________________________________
block3_conv2 (Conv2D)        (None, 37, 37, 256)       590080    
_________________________________________________________________
block3_conv3 (Conv2D)        (None, 37, 37, 256)       590080    
_________________________________________________________________
block3_pool (MaxPooling2D)   (None, 18, 18, 256)       0         
_________________________________________________________________
block4_conv1 (Conv2D)        (None, 18, 18, 512)       1180160   
_________________________________________________________________
block4_conv2 (Conv2D)        (None, 18, 18, 512)       2359808   
_________________________________________________________________
block4_conv3 (Conv2D)        (None, 18, 18, 512)       2359808   
_________________________________________________________________
block4_pool (MaxPooling2D)   (None, 9, 9, 512)         0         
_________________________________________________________________
block5_conv1 (Conv2D)        (None, 9, 9, 512)         2359808   
_________________________________________________________________
block5_conv2 (Conv2D)        (None, 9, 9, 512)         2359808   
_________________________________________________________________
block5_conv3 (Conv2D)        (None, 9, 9, 512)         2359808   
_________________________________________________________________
block5_pool (MaxPooling2D)   (None, 4, 4, 512)         0         
_________________________________________________________________
sequential_1 (Sequential)    (None, 1)                 2097665   
=================================================================

但是我得到这个错误:

AttributeError:层sequence_2具有多个入站节点,因此层输出"的概念定义不明确.改为使用get_output_at(node_index).

我不知道从哪里开始.经过一些搜索,我认为这与最后一层是顺序层而不是示例中的VGG16模型中的密集层有关.

I am clueless where to start. After some searching I think it has to do with the last layer being a Sequential layer instead of a Dense layer which it is in the VGG16 model in the example.

该模型的制作类似于Keras的Cat或Dog实例,并进行了微调.

The model is made like the Cat or Dog example from Keras with finetuning.

任何帮助或想法,如我可以从这里继续进行,将不胜感激!

Any help or ideas how I could proceed from here would be much appreciated!

万一有助于查看代码:

In case it helps to see the code:

model = load_model('final_finetuned_model.h5')

layer_idx = utils.find_layer_idx(model, 'sequential_1')

model.layers[layer_idx].activation = activations.linear
model = utils.apply_modifications(model)

plt.rcParams['figure.figsize'] = (18, 6)

img1 = utils.load_img('test1/cat/5.jpg', target_size=(150, 150))
img2 = utils.load_img('test1/cat/6.jpg', target_size=(150, 150))

for modifier in [None, 'guided', 'relu']:
    plt.figure()
    f, ax = plt.subplots(1, 2)
    plt.suptitle("vanilla" if modifier is None else modifier)
    for i, img in enumerate([img1, img2]):
        # 20 is the imagenet index corresponding to `ouzel`
        grads = visualize_cam(model, layer_idx, filter_indices=20,
                              seed_input=img, backprop_modifier=modifier)
        # Lets overlay the heatmap onto original image.
        jet_heatmap = np.uint8(cm.jet(grads)[..., :3] * 255)
        ax[i].imshow(overlay(jet_heatmap, img))

plt.show()

推荐答案

对于一个非常相似的网络,我有一个类似的错误,该网络具有两个输出节点密集_1_1/Relu:0和顺序_2/dense_1/Relu:0.对我来说,解决方案是转到losss.py,然后将layer_output = self.layer.output更改为layer_output = self.layer.get_output_at(-1).这不是解决方案,而是更多解决方法.当有一个输出节点时,采用最后一个[-1]就可以了,而当有两个节点时,采用最后一个对我有用.但是,这应该带给您领先的机会.如果有,请尝试layer_output = self.layer.get_output_at(0)或其他节点. 此处.

I had a similar error for a very similar network with two nodes of output, dense_1_1/Relu:0 and sequential_2/dense_1/Relu:0 . The solution for me was to go to losses.py and change layer_output = self.layer.output to layer_output = self.layer.get_output_at(-1). This is more of a workaround than a solution. When there is one output node, taking the last one [-1] is fine, and when there are two nodes taking the last one worked for me. But this should give you the lead. Try also layer_output = self.layer.get_output_at(0) or other nodes if you have them. There is a relevant open issue here.

这篇关于Keras-vis给出以下错误:AttributeError:多个入站节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆