UnboundLocalError: local variable 'ret' referenced before assignmentを解決したいです。

実現したいこと

UnboundLocalError: local variable 'ret' referenced before assignmentのエラーを解決したいです。

10-20、44-49行目で変数retに対して代入が行われているはずですが、分かりません。

前提

DCLGAN実装中に以下のエラーメッセージが発生しました。

発生している問題・エラーメッセージ

Traceback (most recent call last): File "train.py", line 14, in <module> model = create_model(opt) # create a model given opt.model and other options File "C:\Users\DCLGAN-main\models\__init__.py", line 65, in create_model instance = model(opt) File "C:\Users\DCLGAN-main\models\dcl_model.py", line 102, in __init__ self.criterionSim = torch.nn.L1Loss('sum').to(self.device) File "C:\Users\rt-pc\anaconda3\envs\DCLGAN\lib\site-packages\torch\nn\modules\loss.py", line 90, in __init__ super(L1Loss, self).__init__(size_average, reduce, reduction) File "C:\Users\rt-pc\anaconda3\envs\DCLGAN\lib\site-packages\torch\nn\modules\loss.py", line 17, in __init__ self.reduction = _Reduction.legacy_get_string(size_average, reduce) File "C:\Users\rt-pc\anaconda3\envs\DCLGAN\lib\site-packages\torch\nn\_reduction.py", line 44, in legacy_get_string warnings.warn(warning.format(ret)) UnboundLocalError: local variable 'ret' referenced before assignment

該当のソースコード

import warnings from typing import Optional # NB: Keep this file in sync with enums in aten/src/ATen/core/Reduction.h def get_enum(reduction): # type: (str) -> int if reduction == 'none': ret = 0 elif reduction == 'mean': ret = 1 elif reduction == 'elementwise_mean': warnings.warn("reduction='elementwise_mean' is deprecated, please use reduction='mean' instead.") ret = 1 elif reduction == 'sum': ret = 2 else: ret = -1 # TODO: remove once JIT exceptions support control flow raise ValueError("{} is not a valid value for reduction".format(reduction)) return ret # In order to support previous versions, accept boolean size_average and reduce # and convert them into the new constants for now # We use these functions in torch/legacy as well, in which case we'll silence the warning def legacy_get_string(size_average, reduce, emit_warning=True): # type: (Optional[bool], Optional[bool], bool) -> str warning = "size_average and reduce args will be deprecated, please use reduction='{}' instead." if size_average is None: size_average = True if reduce is None: reduce = True if size_average and reduce: reduce = 'mean' elif reduce: ret = 'sum' else: ret = 'none' if emit_warning: warnings.warn(warning.format(ret)) return ret def legacy_get_enum(size_average, reduce, emit_warning=True): # type: (Optional[bool], Optional[bool], bool) -> int return get_enum(legacy_get_string(size_average, reduce, emit_warning))

補足情報(FW/ツールのバージョンなど)

https://github.com/JunlinHan/DCLGAN

コメントを投稿

0 コメント