Commit ·
849d787
1
Parent(s): ae82992
Delete dlhammer
Browse files- dlhammer/.gitignore +0 -3
- dlhammer/LICENSE +0 -201
- dlhammer/README.md +0 -2
- dlhammer/dlhammer/.ipynb_checkpoints/argparser-checkpoint.py +0 -110
- dlhammer/dlhammer/.ipynb_checkpoints/bootstrap-checkpoint.py +0 -33
- dlhammer/dlhammer/__init__.py +0 -1
- dlhammer/dlhammer/__pycache__/__init__.cpython-37.pyc +0 -0
- dlhammer/dlhammer/__pycache__/argparser.cpython-37.pyc +0 -0
- dlhammer/dlhammer/__pycache__/bootstrap.cpython-37.pyc +0 -0
- dlhammer/dlhammer/__pycache__/logger.cpython-37.pyc +0 -0
- dlhammer/dlhammer/argparser.py +0 -109
- dlhammer/dlhammer/bootstrap.py +0 -33
- dlhammer/dlhammer/logger.py +0 -66
- dlhammer/dlhammer/test/config.yml +0 -32
- dlhammer/dlhammer/test/test_args.py +0 -20
- dlhammer/dlhammer/test/test_logger.py +0 -22
- dlhammer/dlhammer/utils/__init__.py +0 -0
- dlhammer/dlhammer/utils/__pycache__/__init__.cpython-37.pyc +0 -0
- dlhammer/dlhammer/utils/__pycache__/misc.cpython-37.pyc +0 -0
- dlhammer/dlhammer/utils/__pycache__/system.cpython-37.pyc +0 -0
- dlhammer/dlhammer/utils/misc.py +0 -125
- dlhammer/dlhammer/utils/system.py +0 -25
dlhammer/.gitignore
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
*.log
|
| 2 |
-
.vim-arsync
|
| 3 |
-
__pycache__/
|
|
|
|
|
|
|
|
|
|
|
|
dlhammer/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
| 1 |
-
Apache License
|
| 2 |
-
Version 2.0, January 2004
|
| 3 |
-
http://www.apache.org/licenses/
|
| 4 |
-
|
| 5 |
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
-
|
| 7 |
-
1. Definitions.
|
| 8 |
-
|
| 9 |
-
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
-
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
-
|
| 12 |
-
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
-
the copyright owner that is granting the License.
|
| 14 |
-
|
| 15 |
-
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
-
other entities that control, are controlled by, or are under common
|
| 17 |
-
control with that entity. For the purposes of this definition,
|
| 18 |
-
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
-
direction or management of such entity, whether by contract or
|
| 20 |
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
-
|
| 23 |
-
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
-
exercising permissions granted by this License.
|
| 25 |
-
|
| 26 |
-
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
-
including but not limited to software source code, documentation
|
| 28 |
-
source, and configuration files.
|
| 29 |
-
|
| 30 |
-
"Object" form shall mean any form resulting from mechanical
|
| 31 |
-
transformation or translation of a Source form, including but
|
| 32 |
-
not limited to compiled object code, generated documentation,
|
| 33 |
-
and conversions to other media types.
|
| 34 |
-
|
| 35 |
-
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
-
Object form, made available under the License, as indicated by a
|
| 37 |
-
copyright notice that is included in or attached to the work
|
| 38 |
-
(an example is provided in the Appendix below).
|
| 39 |
-
|
| 40 |
-
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
-
form, that is based on (or derived from) the Work and for which the
|
| 42 |
-
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
-
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
-
of this License, Derivative Works shall not include works that remain
|
| 45 |
-
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
-
the Work and Derivative Works thereof.
|
| 47 |
-
|
| 48 |
-
"Contribution" shall mean any work of authorship, including
|
| 49 |
-
the original version of the Work and any modifications or additions
|
| 50 |
-
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
-
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
-
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
-
means any form of electronic, verbal, or written communication sent
|
| 55 |
-
to the Licensor or its representatives, including but not limited to
|
| 56 |
-
communication on electronic mailing lists, source code control systems,
|
| 57 |
-
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
-
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
-
excluding communication that is conspicuously marked or otherwise
|
| 60 |
-
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
-
|
| 62 |
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
-
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
-
subsequently incorporated within the Work.
|
| 65 |
-
|
| 66 |
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
-
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
-
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
-
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
-
Work and such Derivative Works in Source or Object form.
|
| 72 |
-
|
| 73 |
-
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
-
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
-
(except as stated in this section) patent license to make, have made,
|
| 77 |
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
-
where such license applies only to those patent claims licensable
|
| 79 |
-
by such Contributor that are necessarily infringed by their
|
| 80 |
-
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
-
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
-
institute patent litigation against any entity (including a
|
| 83 |
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
-
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
-
or contributory patent infringement, then any patent licenses
|
| 86 |
-
granted to You under this License for that Work shall terminate
|
| 87 |
-
as of the date such litigation is filed.
|
| 88 |
-
|
| 89 |
-
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
-
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
-
modifications, and in Source or Object form, provided that You
|
| 92 |
-
meet the following conditions:
|
| 93 |
-
|
| 94 |
-
(a) You must give any other recipients of the Work or
|
| 95 |
-
Derivative Works a copy of this License; and
|
| 96 |
-
|
| 97 |
-
(b) You must cause any modified files to carry prominent notices
|
| 98 |
-
stating that You changed the files; and
|
| 99 |
-
|
| 100 |
-
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
-
that You distribute, all copyright, patent, trademark, and
|
| 102 |
-
attribution notices from the Source form of the Work,
|
| 103 |
-
excluding those notices that do not pertain to any part of
|
| 104 |
-
the Derivative Works; and
|
| 105 |
-
|
| 106 |
-
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
-
distribution, then any Derivative Works that You distribute must
|
| 108 |
-
include a readable copy of the attribution notices contained
|
| 109 |
-
within such NOTICE file, excluding those notices that do not
|
| 110 |
-
pertain to any part of the Derivative Works, in at least one
|
| 111 |
-
of the following places: within a NOTICE text file distributed
|
| 112 |
-
as part of the Derivative Works; within the Source form or
|
| 113 |
-
documentation, if provided along with the Derivative Works; or,
|
| 114 |
-
within a display generated by the Derivative Works, if and
|
| 115 |
-
wherever such third-party notices normally appear. The contents
|
| 116 |
-
of the NOTICE file are for informational purposes only and
|
| 117 |
-
do not modify the License. You may add Your own attribution
|
| 118 |
-
notices within Derivative Works that You distribute, alongside
|
| 119 |
-
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
-
that such additional attribution notices cannot be construed
|
| 121 |
-
as modifying the License.
|
| 122 |
-
|
| 123 |
-
You may add Your own copyright statement to Your modifications and
|
| 124 |
-
may provide additional or different license terms and conditions
|
| 125 |
-
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
-
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
-
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
-
the conditions stated in this License.
|
| 129 |
-
|
| 130 |
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
-
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
-
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
-
this License, without any additional terms or conditions.
|
| 134 |
-
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
-
the terms of any separate license agreement you may have executed
|
| 136 |
-
with Licensor regarding such Contributions.
|
| 137 |
-
|
| 138 |
-
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
-
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
-
except as required for reasonable and customary use in describing the
|
| 141 |
-
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
-
|
| 143 |
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
-
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
-
implied, including, without limitation, any warranties or conditions
|
| 148 |
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
-
appropriateness of using or redistributing the Work and assume any
|
| 151 |
-
risks associated with Your exercise of permissions under this License.
|
| 152 |
-
|
| 153 |
-
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
-
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
-
unless required by applicable law (such as deliberate and grossly
|
| 156 |
-
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
-
liable to You for damages, including any direct, indirect, special,
|
| 158 |
-
incidental, or consequential damages of any character arising as a
|
| 159 |
-
result of this License or out of the use or inability to use the
|
| 160 |
-
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
-
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
-
other commercial damages or losses), even if such Contributor
|
| 163 |
-
has been advised of the possibility of such damages.
|
| 164 |
-
|
| 165 |
-
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
-
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
-
or other liability obligations and/or rights consistent with this
|
| 169 |
-
License. However, in accepting such obligations, You may act only
|
| 170 |
-
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
-
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
-
defend, and hold each Contributor harmless for any liability
|
| 173 |
-
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
-
of your accepting any such warranty or additional liability.
|
| 175 |
-
|
| 176 |
-
END OF TERMS AND CONDITIONS
|
| 177 |
-
|
| 178 |
-
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
-
|
| 180 |
-
To apply the Apache License to your work, attach the following
|
| 181 |
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
-
replaced with your own identifying information. (Don't include
|
| 183 |
-
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
-
comment syntax for the file format. We also recommend that a
|
| 185 |
-
file or class name and description of purpose be included on the
|
| 186 |
-
same "printed page" as the copyright notice for easier
|
| 187 |
-
identification within third-party archives.
|
| 188 |
-
|
| 189 |
-
Copyright [yyyy] [name of copyright owner]
|
| 190 |
-
|
| 191 |
-
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
-
you may not use this file except in compliance with the License.
|
| 193 |
-
You may obtain a copy of the License at
|
| 194 |
-
|
| 195 |
-
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
-
|
| 197 |
-
Unless required by applicable law or agreed to in writing, software
|
| 198 |
-
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
-
See the License for the specific language governing permissions and
|
| 201 |
-
limitations under the License.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dlhammer/README.md
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
# dl-hammer
|
| 2 |
-
tools for deep learning coding.
|
|
|
|
|
|
|
|
|
dlhammer/dlhammer/.ipynb_checkpoints/argparser-checkpoint.py
DELETED
|
@@ -1,110 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
#================================================================
|
| 3 |
-
# Don't go gently into that good night.
|
| 4 |
-
#
|
| 5 |
-
# author: klaus
|
| 6 |
-
# description:
|
| 7 |
-
#
|
| 8 |
-
#================================================================
|
| 9 |
-
|
| 10 |
-
import os
|
| 11 |
-
import argparse
|
| 12 |
-
import datetime
|
| 13 |
-
from functools import partial
|
| 14 |
-
import yaml
|
| 15 |
-
from easydict import EasyDict
|
| 16 |
-
|
| 17 |
-
# from .utils import get_vacant_gpu
|
| 18 |
-
from .logger import bootstrap_logger, logger
|
| 19 |
-
from .utils.system import get_available_gpuids
|
| 20 |
-
from .utils.misc import merge_dict, merge_opts, to_string, eval_dict_leaf
|
| 21 |
-
|
| 22 |
-
CONFIG = EasyDict()
|
| 23 |
-
|
| 24 |
-
BASE_CONFIG = {
|
| 25 |
-
'OUTPUT_DIR': './workspace',
|
| 26 |
-
'SESSION': 'base',
|
| 27 |
-
'NUM_GPUS': 1,
|
| 28 |
-
'LOG_NAME': 'log.txt'
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
def bootstrap_args(default_params=None):
|
| 33 |
-
"""get the params from yaml file and args. The args will override arguemnts in the yaml file.
|
| 34 |
-
Returns: EasyDict instance.
|
| 35 |
-
|
| 36 |
-
"""
|
| 37 |
-
parser = define_default_arg_parser()
|
| 38 |
-
cfg = update_config(parser, default_params)
|
| 39 |
-
create_workspace(cfg) #create workspace
|
| 40 |
-
|
| 41 |
-
CONFIG.update(cfg)
|
| 42 |
-
bootstrap_logger(get_logfile(CONFIG)) # setup logger
|
| 43 |
-
setup_gpu(CONFIG.NUM_GPUS) #setup gpu
|
| 44 |
-
|
| 45 |
-
return cfg
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
def setup_gpu(ngpu):
|
| 49 |
-
gpuids = get_available_gpuids()
|
| 50 |
-
# os.environ['CUDA_VISIBLE_DEVICES'] = ','.join([str(i) for i in gpuids[:ngpu]])
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
def get_logfile(config):
|
| 54 |
-
return os.path.join(config.WORKSPACE, config.LOG_NAME)
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
def define_default_arg_parser():
|
| 58 |
-
"""Define a default arg_parser.
|
| 59 |
-
|
| 60 |
-
Returns:
|
| 61 |
-
A argparse.ArgumentParser. More arguments can be added.
|
| 62 |
-
|
| 63 |
-
"""
|
| 64 |
-
parser = argparse.ArgumentParser()
|
| 65 |
-
parser.add_argument('--cfg', help='load configs from yaml file', default='', type=str)
|
| 66 |
-
parser.add_argument('opts',
|
| 67 |
-
default=None,
|
| 68 |
-
nargs='*',
|
| 69 |
-
help='modify config options using the command-line')
|
| 70 |
-
|
| 71 |
-
return parser
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
def update_config(arg_parser, default_config=None):
|
| 75 |
-
""" update argparser to args.
|
| 76 |
-
|
| 77 |
-
Args:
|
| 78 |
-
arg_parser: argparse.ArgumentParser.
|
| 79 |
-
"""
|
| 80 |
-
|
| 81 |
-
parsed, unknown = arg_parser.parse_known_args()
|
| 82 |
-
if default_config and parsed.cfg == "" and "cfg" in default_config:
|
| 83 |
-
parsed.cfg = default_config["cfg"]
|
| 84 |
-
|
| 85 |
-
config = EasyDict(BASE_CONFIG.copy())
|
| 86 |
-
config['cfg'] = parsed.cfg
|
| 87 |
-
# update default config
|
| 88 |
-
if default_config is not None:
|
| 89 |
-
config.update(default_config)
|
| 90 |
-
|
| 91 |
-
# merge config from yaml
|
| 92 |
-
if os.path.isfile(config.cfg):
|
| 93 |
-
with open(config.cfg, 'r') as f:
|
| 94 |
-
yml_config = yaml.full_load(f)
|
| 95 |
-
config = merge_dict(config, yml_config)
|
| 96 |
-
|
| 97 |
-
# merge opts
|
| 98 |
-
config = merge_opts(config, parsed.opts)
|
| 99 |
-
|
| 100 |
-
# eval values
|
| 101 |
-
config = eval_dict_leaf(config)
|
| 102 |
-
|
| 103 |
-
return config
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
def create_workspace(cfg):
|
| 107 |
-
cfg_name, ext = os.path.splitext(os.path.basename(cfg.cfg))
|
| 108 |
-
workspace = os.path.join(cfg.OUTPUT_DIR, cfg_name, cfg.SESSION)
|
| 109 |
-
os.makedirs(workspace, exist_ok=True)
|
| 110 |
-
cfg.WORKSPACE = workspace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dlhammer/dlhammer/.ipynb_checkpoints/bootstrap-checkpoint.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
#================================================================
|
| 3 |
-
# Don't go gently into that good night.
|
| 4 |
-
#
|
| 5 |
-
# author: klaus
|
| 6 |
-
# description:
|
| 7 |
-
#
|
| 8 |
-
#================================================================
|
| 9 |
-
|
| 10 |
-
import sys
|
| 11 |
-
import logging
|
| 12 |
-
|
| 13 |
-
from .logger import bootstrap_logger, logger
|
| 14 |
-
from .argparser import bootstrap_args, CONFIG
|
| 15 |
-
from .utils.misc import to_string
|
| 16 |
-
|
| 17 |
-
__all__ = ['bootstrap', 'logger', 'CONFIG']
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def bootstrap(default_cfg=None, print_cfg=True):
|
| 21 |
-
"""TODO: Docstring for bootstrap.
|
| 22 |
-
|
| 23 |
-
Kwargs:
|
| 24 |
-
use_argparser (TODO): TODO
|
| 25 |
-
use_logger (TODO): TODO
|
| 26 |
-
|
| 27 |
-
Returns: TODO
|
| 28 |
-
|
| 29 |
-
"""
|
| 30 |
-
config = bootstrap_args(default_cfg)
|
| 31 |
-
if print_cfg:
|
| 32 |
-
logger.info(to_string(config))
|
| 33 |
-
return config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dlhammer/dlhammer/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
from .bootstrap import *
|
|
|
|
|
|
dlhammer/dlhammer/__pycache__/__init__.cpython-37.pyc
DELETED
|
Binary file (185 Bytes)
|
|
|
dlhammer/dlhammer/__pycache__/argparser.cpython-37.pyc
DELETED
|
Binary file (2.59 kB)
|
|
|
dlhammer/dlhammer/__pycache__/bootstrap.cpython-37.pyc
DELETED
|
Binary file (717 Bytes)
|
|
|
dlhammer/dlhammer/__pycache__/logger.cpython-37.pyc
DELETED
|
Binary file (1.47 kB)
|
|
|
dlhammer/dlhammer/argparser.py
DELETED
|
@@ -1,109 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
#================================================================
|
| 3 |
-
# Don't go gently into that good night.
|
| 4 |
-
#
|
| 5 |
-
# author: klaus
|
| 6 |
-
# description:
|
| 7 |
-
#
|
| 8 |
-
#================================================================
|
| 9 |
-
|
| 10 |
-
import os
|
| 11 |
-
import argparse
|
| 12 |
-
import datetime
|
| 13 |
-
from functools import partial
|
| 14 |
-
import yaml
|
| 15 |
-
from easydict import EasyDict
|
| 16 |
-
|
| 17 |
-
# from .utils import get_vacant_gpu
|
| 18 |
-
from .logger import bootstrap_logger, logger
|
| 19 |
-
from .utils.system import get_available_gpuids
|
| 20 |
-
from .utils.misc import merge_dict, merge_opts, to_string, eval_dict_leaf
|
| 21 |
-
|
| 22 |
-
CONFIG = EasyDict()
|
| 23 |
-
|
| 24 |
-
BASE_CONFIG = {
|
| 25 |
-
'OUTPUT_DIR': './workspace',
|
| 26 |
-
'NUM_GPUS': 1,
|
| 27 |
-
'LOG_NAME': 'log.txt'
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
def bootstrap_args(default_params=None):
|
| 32 |
-
"""get the params from yaml file and args. The args will override arguemnts in the yaml file.
|
| 33 |
-
Returns: EasyDict instance.
|
| 34 |
-
|
| 35 |
-
"""
|
| 36 |
-
parser = define_default_arg_parser()
|
| 37 |
-
cfg = update_config(parser, default_params)
|
| 38 |
-
create_workspace(cfg) #create workspace
|
| 39 |
-
|
| 40 |
-
CONFIG.update(cfg)
|
| 41 |
-
bootstrap_logger(get_logfile(CONFIG)) # setup logger
|
| 42 |
-
setup_gpu(CONFIG.NUM_GPUS) #setup gpu
|
| 43 |
-
|
| 44 |
-
return cfg
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def setup_gpu(ngpu):
|
| 48 |
-
gpuids = get_available_gpuids()
|
| 49 |
-
# os.environ['CUDA_VISIBLE_DEVICES'] = ','.join([str(i) for i in gpuids[:ngpu]])
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def get_logfile(config):
|
| 53 |
-
return os.path.join(config.WORKSPACE, config.LOG_NAME)
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
def define_default_arg_parser():
|
| 57 |
-
"""Define a default arg_parser.
|
| 58 |
-
|
| 59 |
-
Returns:
|
| 60 |
-
A argparse.ArgumentParser. More arguments can be added.
|
| 61 |
-
|
| 62 |
-
"""
|
| 63 |
-
parser = argparse.ArgumentParser()
|
| 64 |
-
parser.add_argument('--cfg', help='load configs from yaml file', default='', type=str)
|
| 65 |
-
parser.add_argument('opts',
|
| 66 |
-
default=None,
|
| 67 |
-
nargs='*',
|
| 68 |
-
help='modify config options using the command-line')
|
| 69 |
-
|
| 70 |
-
return parser
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
def update_config(arg_parser, default_config=None):
|
| 74 |
-
""" update argparser to args.
|
| 75 |
-
|
| 76 |
-
Args:
|
| 77 |
-
arg_parser: argparse.ArgumentParser.
|
| 78 |
-
"""
|
| 79 |
-
|
| 80 |
-
parsed, unknown = arg_parser.parse_known_args()
|
| 81 |
-
if default_config and parsed.cfg == "" and "cfg" in default_config:
|
| 82 |
-
parsed.cfg = default_config["cfg"]
|
| 83 |
-
|
| 84 |
-
config = EasyDict(BASE_CONFIG.copy())
|
| 85 |
-
config['cfg'] = parsed.cfg
|
| 86 |
-
# update default config
|
| 87 |
-
if default_config is not None:
|
| 88 |
-
config.update(default_config)
|
| 89 |
-
|
| 90 |
-
# merge config from yaml
|
| 91 |
-
if os.path.isfile(config.cfg):
|
| 92 |
-
with open(config.cfg, 'r') as f:
|
| 93 |
-
yml_config = yaml.full_load(f)
|
| 94 |
-
config = merge_dict(config, yml_config)
|
| 95 |
-
|
| 96 |
-
# merge opts
|
| 97 |
-
config = merge_opts(config, parsed.opts)
|
| 98 |
-
|
| 99 |
-
# eval values
|
| 100 |
-
config = eval_dict_leaf(config)
|
| 101 |
-
|
| 102 |
-
return config
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
def create_workspace(cfg):
|
| 106 |
-
cfg_name, ext = os.path.splitext(os.path.basename(cfg.cfg))
|
| 107 |
-
workspace = os.path.join(cfg.OUTPUT_DIR)
|
| 108 |
-
os.makedirs(workspace, exist_ok=True)
|
| 109 |
-
cfg.WORKSPACE = workspace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dlhammer/dlhammer/bootstrap.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
#================================================================
|
| 3 |
-
# Don't go gently into that good night.
|
| 4 |
-
#
|
| 5 |
-
# author: klaus
|
| 6 |
-
# description:
|
| 7 |
-
#
|
| 8 |
-
#================================================================
|
| 9 |
-
|
| 10 |
-
import sys
|
| 11 |
-
import logging
|
| 12 |
-
|
| 13 |
-
from .logger import bootstrap_logger, logger
|
| 14 |
-
from .argparser import bootstrap_args, CONFIG
|
| 15 |
-
from .utils.misc import to_string
|
| 16 |
-
|
| 17 |
-
__all__ = ['bootstrap', 'logger', 'CONFIG']
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
def bootstrap(default_cfg=None, print_cfg=True):
|
| 21 |
-
"""TODO: Docstring for bootstrap.
|
| 22 |
-
|
| 23 |
-
Kwargs:
|
| 24 |
-
use_argparser (TODO): TODO
|
| 25 |
-
use_logger (TODO): TODO
|
| 26 |
-
|
| 27 |
-
Returns: TODO
|
| 28 |
-
|
| 29 |
-
"""
|
| 30 |
-
config = bootstrap_args(default_cfg)
|
| 31 |
-
if print_cfg:
|
| 32 |
-
logger.info(to_string(config))
|
| 33 |
-
return config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dlhammer/dlhammer/logger.py
DELETED
|
@@ -1,66 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
#================================================================
|
| 3 |
-
# Don't go gently into that good night.
|
| 4 |
-
#
|
| 5 |
-
# author: klaus
|
| 6 |
-
# description:
|
| 7 |
-
#
|
| 8 |
-
#================================================================
|
| 9 |
-
|
| 10 |
-
import os
|
| 11 |
-
import sys
|
| 12 |
-
import logging
|
| 13 |
-
|
| 14 |
-
logger = logging.getLogger('DLHammer')
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def bootstrap_logger(logfile=None, fmt=None):
|
| 18 |
-
"""TODO: Docstring for bootstrap_logger.
|
| 19 |
-
|
| 20 |
-
Args:
|
| 21 |
-
logfile (str): file path logging to.
|
| 22 |
-
|
| 23 |
-
Kwargs:
|
| 24 |
-
fmt (TODO): TODO
|
| 25 |
-
|
| 26 |
-
Returns: TODO
|
| 27 |
-
|
| 28 |
-
"""
|
| 29 |
-
if fmt is None:
|
| 30 |
-
# fmt = '%(asctime)s - %(levelname)-5s - [%(filename)s:%(lineno)d] %(message)s'
|
| 31 |
-
fmt = '%(message)s'
|
| 32 |
-
logging.basicConfig(level=logging.DEBUG, format=fmt)
|
| 33 |
-
|
| 34 |
-
#log to file
|
| 35 |
-
if logfile is not None:
|
| 36 |
-
formatter = logging.Formatter(fmt)
|
| 37 |
-
fh = logging.FileHandler(logfile)
|
| 38 |
-
fh.setLevel(logging.DEBUG)
|
| 39 |
-
fh.setFormatter(formatter)
|
| 40 |
-
logger.addHandler(fh)
|
| 41 |
-
|
| 42 |
-
# sys.stdout = LoggerWriter(sys.stdout, logger.info)
|
| 43 |
-
# sys.stderr = LoggerWriter(sys.stderr, logger.error)
|
| 44 |
-
return
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
class LoggerWriter(object):
|
| 48 |
-
|
| 49 |
-
def __init__(self, stream, logfct):
|
| 50 |
-
self.terminal = stream
|
| 51 |
-
self.logfct = logfct
|
| 52 |
-
self.buf = []
|
| 53 |
-
|
| 54 |
-
def write(self, msg):
|
| 55 |
-
if msg.endswith('\n'):
|
| 56 |
-
self.buf.append(msg.rstrip('\n'))
|
| 57 |
-
|
| 58 |
-
message = ''.join(self.buf)
|
| 59 |
-
self.logfct(message)
|
| 60 |
-
|
| 61 |
-
self.buf = []
|
| 62 |
-
else:
|
| 63 |
-
self.buf.append(msg)
|
| 64 |
-
|
| 65 |
-
def flush(self):
|
| 66 |
-
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dlhammer/dlhammer/test/config.yml
DELETED
|
@@ -1,32 +0,0 @@
|
|
| 1 |
-
a_int: 12
|
| 2 |
-
a_float: 1e-2
|
| 3 |
-
a_list: [0,1,2]
|
| 4 |
-
eval_list: eval(list(range(10)))
|
| 5 |
-
DATA:
|
| 6 |
-
PATH_TO_DATA_DIR: /home/ubuntu/data/kinetics/Mini-Kinetics-200
|
| 7 |
-
PATH_PREFIX: /home/ubuntu/data/kinetics/k400_ver3
|
| 8 |
-
NUM_FRAMES: 16
|
| 9 |
-
SAMPLING_RATE: 8
|
| 10 |
-
TARGET_FPS: 25
|
| 11 |
-
TRAIN_JITTER_SCALES: [256, 320]
|
| 12 |
-
TRAIN_CROP_SIZE: 224
|
| 13 |
-
TEST_CROP_SIZE: 224
|
| 14 |
-
INPUT_CHANNEL_NUM: [3]
|
| 15 |
-
SOLVER:
|
| 16 |
-
BACKBONE:
|
| 17 |
-
OPTIMIZER: sgd
|
| 18 |
-
MOMENTUM: 0.9
|
| 19 |
-
BASE_LR: 1e-3
|
| 20 |
-
SCHEDULER:
|
| 21 |
-
NAME: warmup_multistep
|
| 22 |
-
MILESTONES: [13, 24]
|
| 23 |
-
WARMUP_EPOCHS: 0.5
|
| 24 |
-
GAMMA: 0.1
|
| 25 |
-
TEMPORAL_MODEL:
|
| 26 |
-
OPTIMIZER: sgd
|
| 27 |
-
MOMENTUM: 0.9
|
| 28 |
-
BASE_LR: 1e-3
|
| 29 |
-
SCHEDULER:
|
| 30 |
-
NAME: multistep
|
| 31 |
-
MILESTONES: [13, 24]
|
| 32 |
-
GAMMA: 0.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dlhammer/dlhammer/test/test_args.py
DELETED
|
@@ -1,20 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
#================================================================
|
| 3 |
-
# Don't go gently into that good night.
|
| 4 |
-
#
|
| 5 |
-
# author: klaus
|
| 6 |
-
# description:
|
| 7 |
-
#
|
| 8 |
-
#================================================================
|
| 9 |
-
|
| 10 |
-
import os
|
| 11 |
-
import sys
|
| 12 |
-
|
| 13 |
-
CURRENT_FILE_DIRECTORY = os.path.abspath(os.path.dirname(__file__))
|
| 14 |
-
sys.path.append(os.path.join(CURRENT_FILE_DIRECTORY, '../..'))
|
| 15 |
-
sys.path.append(os.path.join(CURRENT_FILE_DIRECTORY, '.'))
|
| 16 |
-
|
| 17 |
-
from dlhammer import bootstrap, CONFIG
|
| 18 |
-
from dlhammer import logger
|
| 19 |
-
|
| 20 |
-
config = bootstrap(print_cfg=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dlhammer/dlhammer/test/test_logger.py
DELETED
|
@@ -1,22 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
#================================================================
|
| 3 |
-
# Don't go gently into that good night.
|
| 4 |
-
#
|
| 5 |
-
# author: klaus
|
| 6 |
-
# description:
|
| 7 |
-
#
|
| 8 |
-
#================================================================
|
| 9 |
-
|
| 10 |
-
import os
|
| 11 |
-
import sys
|
| 12 |
-
|
| 13 |
-
CURRENT_FILE_DIRECTORY = os.path.abspath(os.path.dirname(__file__))
|
| 14 |
-
sys.path.append(os.path.join(CURRENT_FILE_DIRECTORY, '../..'))
|
| 15 |
-
sys.path.append(os.path.join(CURRENT_FILE_DIRECTORY, '.'))
|
| 16 |
-
|
| 17 |
-
from dlhammer import bootstrap, logger
|
| 18 |
-
bootstrap()
|
| 19 |
-
|
| 20 |
-
logger.info('dummy output')
|
| 21 |
-
|
| 22 |
-
raise Exception('dummy error')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dlhammer/dlhammer/utils/__init__.py
DELETED
|
File without changes
|
dlhammer/dlhammer/utils/__pycache__/__init__.cpython-37.pyc
DELETED
|
Binary file (165 Bytes)
|
|
|
dlhammer/dlhammer/utils/__pycache__/misc.cpython-37.pyc
DELETED
|
Binary file (2.79 kB)
|
|
|
dlhammer/dlhammer/utils/__pycache__/system.cpython-37.pyc
DELETED
|
Binary file (684 Bytes)
|
|
|
dlhammer/dlhammer/utils/misc.py
DELETED
|
@@ -1,125 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
#================================================================
|
| 3 |
-
# Don't go gently into that good night.
|
| 4 |
-
#
|
| 5 |
-
# author: klaus
|
| 6 |
-
# description:
|
| 7 |
-
#
|
| 8 |
-
#================================================================
|
| 9 |
-
|
| 10 |
-
import ast
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def merge_dict(a, b, path=None):
|
| 14 |
-
"""merge b into a. The values in b will override values in a.
|
| 15 |
-
|
| 16 |
-
Args:
|
| 17 |
-
a (dict): dict to merge to.
|
| 18 |
-
b (dict): dict to merge from.
|
| 19 |
-
|
| 20 |
-
Returns: dict1 with values merged from b.
|
| 21 |
-
|
| 22 |
-
"""
|
| 23 |
-
if path is None: path = []
|
| 24 |
-
for key in b:
|
| 25 |
-
if key in a:
|
| 26 |
-
if isinstance(a[key], dict) and isinstance(b[key], dict):
|
| 27 |
-
merge_dict(a[key], b[key], path + [str(key)])
|
| 28 |
-
else:
|
| 29 |
-
a[key] = b[key]
|
| 30 |
-
else:
|
| 31 |
-
a[key] = b[key]
|
| 32 |
-
return a
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
def merge_opts(d, opts):
|
| 36 |
-
"""merge opts
|
| 37 |
-
Args:
|
| 38 |
-
d (dict): The dict.
|
| 39 |
-
opts (list): The opts to merge. format: [key1, name1, key2, name2,...]
|
| 40 |
-
Returns: d. the input dict `d` with merged opts.
|
| 41 |
-
|
| 42 |
-
"""
|
| 43 |
-
assert len(opts) % 2 == 0, f'length of opts must be even. Got: {opts}'
|
| 44 |
-
for i in range(0, len(opts), 2):
|
| 45 |
-
full_k, v = opts[i], opts[i + 1]
|
| 46 |
-
keys = full_k.split('.')
|
| 47 |
-
sub_d = d
|
| 48 |
-
for i, k in enumerate(keys):
|
| 49 |
-
if not hasattr(sub_d, k):
|
| 50 |
-
raise ValueError(f'The key {k} not exist in the dict. Full key:{full_k}')
|
| 51 |
-
if i != len(keys) - 1:
|
| 52 |
-
sub_d = sub_d[k]
|
| 53 |
-
else:
|
| 54 |
-
sub_d[k] = v
|
| 55 |
-
return d
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
def to_string(params, indent=2):
|
| 59 |
-
"""format params to a string
|
| 60 |
-
|
| 61 |
-
Args:
|
| 62 |
-
params (EasyDict): the params.
|
| 63 |
-
|
| 64 |
-
Returns: The string to display.
|
| 65 |
-
|
| 66 |
-
"""
|
| 67 |
-
msg = '{\n'
|
| 68 |
-
for i, (k, v) in enumerate(params.items()):
|
| 69 |
-
if isinstance(v, dict):
|
| 70 |
-
v = to_string(v, indent + 4)
|
| 71 |
-
spaces = ' ' * indent
|
| 72 |
-
msg += spaces + '{}: {}'.format(k, v)
|
| 73 |
-
if i == len(params) - 1:
|
| 74 |
-
msg += ' }'
|
| 75 |
-
else:
|
| 76 |
-
msg += '\n'
|
| 77 |
-
return msg
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
def eval_dict_leaf(d):
|
| 81 |
-
"""eval values of dict leaf.
|
| 82 |
-
|
| 83 |
-
Args:
|
| 84 |
-
d (dict): The dict to eval.
|
| 85 |
-
|
| 86 |
-
Returns: dict.
|
| 87 |
-
|
| 88 |
-
"""
|
| 89 |
-
for k, v in d.items():
|
| 90 |
-
if not isinstance(v, dict):
|
| 91 |
-
d[k] = eval_string(v)
|
| 92 |
-
else:
|
| 93 |
-
eval_dict_leaf(v)
|
| 94 |
-
return d
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
def eval_string(string):
|
| 98 |
-
"""automatically evaluate string to corresponding types.
|
| 99 |
-
|
| 100 |
-
For example:
|
| 101 |
-
not a string -> return the original input
|
| 102 |
-
'0' -> 0
|
| 103 |
-
'0.2' -> 0.2
|
| 104 |
-
'[0, 1, 2]' -> [0,1,2]
|
| 105 |
-
'eval(1+2)' -> 3
|
| 106 |
-
'eval(range(5))' -> [0,1,2,3,4]
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
Args:
|
| 110 |
-
value : string.
|
| 111 |
-
|
| 112 |
-
Returns: the corresponding type
|
| 113 |
-
|
| 114 |
-
"""
|
| 115 |
-
if not isinstance(string, str):
|
| 116 |
-
return string
|
| 117 |
-
if len(string) > 1 and string[0] == '[' and string[-1] == ']':
|
| 118 |
-
return eval(string)
|
| 119 |
-
if string[0:5] == 'eval(':
|
| 120 |
-
return eval(string[5:-1])
|
| 121 |
-
try:
|
| 122 |
-
v = ast.literal_eval(string)
|
| 123 |
-
except:
|
| 124 |
-
v = string
|
| 125 |
-
return v
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dlhammer/dlhammer/utils/system.py
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
#================================================================
|
| 3 |
-
# Don't go gently into that good night.
|
| 4 |
-
#
|
| 5 |
-
# author: klaus
|
| 6 |
-
# description:
|
| 7 |
-
#
|
| 8 |
-
#================================================================
|
| 9 |
-
|
| 10 |
-
import os
|
| 11 |
-
import sys
|
| 12 |
-
import subprocess
|
| 13 |
-
import numpy as np
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
def get_available_gpuids():
|
| 17 |
-
"""
|
| 18 |
-
Returns: the gpu ids sorted in descending order w.r.t occupied memory.
|
| 19 |
-
"""
|
| 20 |
-
com = "nvidia-smi|sed -n '/%/p'|sed 's/|/\\n/g'|sed -n '/MiB/p'|sed 's/ //g'|sed 's/MiB/\\n/'|sed '/\\//d'"
|
| 21 |
-
gpum = subprocess.check_output(com, shell=True)
|
| 22 |
-
gpum = gpum.decode('utf-8').split('\n')
|
| 23 |
-
gpum = gpum[:-1]
|
| 24 |
-
sorted_gpuid = np.argsort(gpum)
|
| 25 |
-
return sorted_gpuid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|