質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
PyTorch

PyTorchは、オープンソースのPython向けの機械学習ライブラリ。Facebookの人工知能研究グループが開発を主導しています。強力なGPUサポートを備えたテンソル計算、テープベースの自動微分による柔軟なニューラルネットワークの記述が可能です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

2042閲覧

Tensorboardでpytorchモデルを可視化する際のエラー

YoheiYamasaki

総合スコア17

PyTorch

PyTorchは、オープンソースのPython向けの機械学習ライブラリ。Facebookの人工知能研究グループが開発を主導しています。強力なGPUサポートを備えたテンソル計算、テープベースの自動微分による柔軟なニューラルネットワークの記述が可能です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/09/06 03:24

編集2020/09/06 04:59

概要

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知見がある方、教えていただけますと幸いです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問