apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.77k stars 6.8k forks source link

TypeError: Compose expect `Symbol` as arguments #20329

Open Light-- opened 3 years ago

Light-- commented 3 years ago

Description

i want to use the output layer by layer to visualize the attention map of the mxnet model, simply use the grad_cam method. pytorch models are eaisly to use it, but how about mxnet?

Error Message

Traceback (most recent call last):
  File "/home/user1/batch_vis_mxnet.py", line 708, in <module>
    batch_vis(image_path=imgDir, modelPrefix=modelPrefix, fc7Prefix=fc7Prefix, iterNum=iterNum, frameWork='mxnet')
  File "/home/user1/batch_vis_mxnet.py", line 642, in batch_vis
    generate_heatmap(i, grad_cam, savePath, gb_model)
  File "/home/user1/batch_vis_mxnet.py", line 417, in generate_heatmap
    mask = grad_cam(input, target_index)
  File "/home/user1/batch_vis_mxnet.py", line 170, in __call__
    features, output = self.extractor(input.cuda())
  File "/home/user1/batch_vis_mxnet.py", line 122, in __call__
    target_activations, output = self.feature_extractor(x)
  File "/home/user1/batch_vis_mxnet.py", line 85, in __call__
    x = module(x)
  File "/home/user1/miniconda3/lib/python3.7/site-packages/mxnet/symbol/symbol.py", line 454, in __call__
    s._compose(*args, **kwargs)
  File "/home/user1/miniconda3/lib/python3.7/site-packages/mxnet/symbol/symbol.py", line 497, in _compose
    raise TypeError('Compose expect `Symbol` as arguments')
TypeError: Compose expect `Symbol` as arguments

Process finished with exit code 1

To Reproduce

all_layers = self.model.symbol.get_internals()  # list all symbol
names = all_layers.list_outputs()

for name in names:
    module = all_layers[name]
    x = module(x)

Environment

mxnet 1.6.0

github-actions[bot] commented 3 years ago

Welcome to Apache MXNet (incubating)! We are on a mission to democratize AI, and we are glad that you are contributing to it by opening this issue. Please make sure to include all the relevant context, and one of the @apache/mxnet-committers will be here shortly. If you are interested in contributing to our project, let us know! Also, be sure to check out our guide on contributing to MXNet and our development guides wiki.