概要
torchvisionにある、deeplabv3モデルの可視化を試そうとしています。
こちらを参考にして、可視化を試しています。
https://pytorch.org/tutorials/intermediate/tensorboard_tutorial.html
やった事
python
1import torch 2from torch import nn 3from torchvision import models 4from torch.utils.tensorboard import SummaryWriter 5 6deeplabv3 = models.segmentation.deeplabv3_resnet50(pretrained=True) 7# default `log_dir` is "runs" - we'll be more specific here 8writer = SummaryWriter('runs/deeplabv3') 9x = torch.rand(1,3,512,512) 10writer.add_graph(deeplabv3, x)
ここで以下のエラーが出ます。
bash
1--------------------------------------------------------------------------- 2RuntimeError Traceback (most recent call last) 3~/Documents/4.自学自習/DeepLearning/SemanticSegmentation/torch_test.py in 4----> 293 writer.add_graph(deeplabv3, x) 5 6~/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torch/utils/tensorboard/writer.py in add_graph(self, model, input_to_model, verbose) 7 712 if hasattr(model, 'forward'): 8 713 # A valid PyTorch model should have a 'forward' method 9--> 714 self._get_file_writer().add_graph(graph(model, input_to_model, verbose)) 10 715 else: 11 716 # Caffe2 models do not have the 'forward' method 12 13~/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torch/utils/tensorboard/_pytorch_graph.py in graph(model, args, verbose) 14 289 print(e) 15 290 print('Error occurs, No graph saved') 16--> 291 raise e 17 292 18 293 if verbose: 19 20~/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torch/utils/tensorboard/_pytorch_graph.py in graph(model, args, verbose) 21 283 with torch.onnx.select_model_mode_for_export(model, torch.onnx.TrainingMode.EVAL): # TODO: move outside of torch.onnx? 22 284 try: 23--> 285 trace = torch.jit.trace(model, args) 24 286 graph = trace.graph 25 287 torch._C._jit_pass_inline(graph) 26 27~/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torch/jit/__init__.py in trace(func, example_inputs, optimize, check_trace, check_inputs, check_tolerance, strict, _force_outplace, _module_class, _compilation_unit) 28 953 return trace_module(func, {'forward': example_inputs}, None, 29 954 check_trace, wrap_check_inputs(check_inputs), 30--> 955 check_tolerance, strict, _force_outplace, _module_class) 31 956 32 957 if (hasattr(func, '__self__') and isinstance(func.__self__, torch.nn.Module) and 33 34~/.pyenv/versions/3.7.4/lib/python3.7/site-packages/torch/jit/__init__.py in trace_module(mod, inputs, optimize, check_trace, check_inputs, check_tolerance, strict, _force_outplace, _module_class, _compilation_unit) 35 1107 func = mod if method_name == "forward" else getattr(mod, method_name) 36 1108 example_inputs = make_tuple(example_inputs) 37-> 1109 module._c._create_method_from_trace(method_name, func, example_inputs, var_lookup_fn, strict, _force_outplace) 38 1110 check_trace_method = module._c._get_method(method_name) 39 1111 40 41RuntimeError: Encountering a dict at the output of the tracer might cause the trace to be incorrect, this is only valid if the container structure does not change based on the module's inputs. Consider using a constant container instead (e.g. for `list`, use a `tuple` instead. for `dict`, use a `NamedTuple` instead). If you absolutely need this and know the side effects, pass strict=False to trace() to allow this behavior.
ちなみに、vgg16などで試したところエラーが出ませんでした。
deeplabv3は複雑な構造をしており、本来ならModuleが入るところにOrderedDictが入ってるからなのかな、という想定ではあります。
しかし、どこをどう変えたらいいのか詳しくわかりません。
こちらについて解決法or知見
がある方、教えていただけますと幸いです。
あなたの回答
tips
プレビュー