Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd50135

Browse files
committed
add yaml_load
1 parentb0ee3c8 commitdd50135

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

‎basicsr/utils/__init__.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .img_utilimportcrop_border,imfrombytes,img2tensor,imwrite,tensor2img
66
from .loggerimportAvgTimer,MessageLogger,get_env_info,get_root_logger,init_tb_logger,init_wandb_logger
77
from .miscimportcheck_resume,get_time_str,make_exp_dirs,mkdir_and_rename,scandir,set_random_seed,sizeof_fmt
8+
from .optionsimportyaml_load
89

910
__all__= [
1011
# color_util.py
@@ -40,5 +41,7 @@
4041
'DiffJPEG',
4142
# img_process_util
4243
'USMSharp',
43-
'usm_sharp'
44+
'usm_sharp',
45+
# options
46+
'yaml_load'
4447
]

‎basicsr/utils/options.py‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
importargparse
2+
importos
23
importrandom
34
importtorch
45
importyaml
@@ -13,7 +14,7 @@ def ordered_yaml():
1314
"""Support OrderedDict for yaml.
1415
1516
Returns:
16-
yaml Loader and Dumper.
17+
tuple:yaml Loader and Dumper.
1718
"""
1819
try:
1920
fromyamlimportCDumperasDumper
@@ -34,6 +35,22 @@ def dict_constructor(loader, node):
3435
returnLoader,Dumper
3536

3637

38+
defyaml_load(f):
39+
"""Load yaml file or string.
40+
41+
Args:
42+
f (str): File path or a python string.
43+
44+
Returns:
45+
dict: Loaded dict.
46+
"""
47+
ifos.path.isfile(f):
48+
withopen(f,'r')asf:
49+
returnyaml.load(f,Loader=ordered_yaml()[0])
50+
else:
51+
returnyaml.load(f,Loader=ordered_yaml()[0])
52+
53+
3754
defdict2str(opt,indent_level=1):
3855
"""dict to string for printing options.
3956
@@ -91,8 +108,7 @@ def parse_options(root_path, is_train=True):
91108
args=parser.parse_args()
92109

93110
# parse yml to dict
94-
withopen(args.opt,mode='r')asf:
95-
opt=yaml.load(f,Loader=ordered_yaml()[0])
111+
opt=yaml_load(args.opt)
96112

97113
# distributed settings
98114
ifargs.launcher=='none':

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp