SEG-GRAD-CAM icon indicating copy to clipboard operation
SEG-GRAD-CAM copied to clipboard

Error of a layer with multi input

Open HXLH50K opened this issue 3 years ago • 2 comments

I want to draw a heatmap for "Attention UNet", which has attention gate need two input. When code run the loop in class FeatureExtractor:

for name, module in self.model._modules.items():
      x = module(x)
      if name in self.target_layers:
          x.register_hook(self.save_gradient)
          outputs += [x]

when it run to attention gate: TypeError: forward() missing 1 required positional argument: 'x'

Code of attunet is:

    def forward(self, x):
        e1 = self.inc(x)
        e2 = self.down1(e1)
        e3 = self.down2(e2)
        e4 = self.down3(e3)
        e5 = self.down4(e4)

        d4 = self.Up4(e5)
        x4 = self.Att4(g=d4, x=e4) #Error happened
        ……

How to make the code support this network?Hope your reply.

HXLH50K avatar Apr 26 '21 00:04 HXLH50K

Has your problem been solved? I also encountered a similar problem. Thank you!

cloudyliy avatar Aug 24 '21 04:08 cloudyliy

I want to draw a heatmap for "Attention UNet", which has attention gate need two input. When code run the loop in class FeatureExtractor:

for name, module in self.model._modules.items():
      x = module(x)
      if name in self.target_layers:
          x.register_hook(self.save_gradient)
          outputs += [x]

when it run to attention gate: TypeError: forward() missing 1 required positional argument: 'x'

Code of attunet is:

    def forward(self, x):
        e1 = self.inc(x)
        e2 = self.down1(e1)
        e3 = self.down2(e2)
        e4 = self.down3(e3)
        e5 = self.down4(e4)

        d4 = self.Up4(e5)
        x4 = self.Att4(g=d4, x=e4) #Error happened
        ……

How to make the code support this network?Hope your reply.

Has your problem been solved? I also encountered a similar problem. Thank you!

cloudyliy avatar Aug 24 '21 06:08 cloudyliy