-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update model index and metafile (#1593)
* - * fix dev_scripts * update field name in readme * refactor format in readme
- Loading branch information
1 parent
671ddb1
commit 8b30739
Showing
109 changed files
with
2,551 additions
and
3,076 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from .job_util import (filter_jobs, get_info_from_id, parse_job_list, | ||
parse_job_list_from_file) | ||
from .modelindex import (collate_metrics, dump_yaml_and_check_difference, | ||
found_table, modelindex_to_dict) | ||
|
||
__all__ = [ | ||
'modelindex_to_dict', 'found_table', 'dump_yaml_and_check_difference', | ||
'collate_metrics', 'parse_job_list', 'parse_job_list_from_file', | ||
'get_info_from_id', 'filter_jobs' | ||
] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import os.path as osp | ||
|
||
import mmengine | ||
from modelindex.models.Collection import Collection | ||
from modelindex.models.Model import Model | ||
|
||
|
||
def dump_yaml_and_check_difference(obj, file): | ||
"""Dump object to a yaml file, and check if the file content is different | ||
from the original. | ||
Args: | ||
obj (any): The python object to be dumped. | ||
file (str): YAML filename to dump the object to. | ||
Returns: | ||
Bool: If the target YAML file is different from the original. | ||
""" | ||
|
||
str_dump = mmengine.dump( | ||
obj, None, file_format='yaml', sort_keys=True, | ||
line_break='\n') # force use LF | ||
|
||
if osp.isfile(file): | ||
file_exists = True | ||
# print(f' exist {file}') | ||
with open(file, 'r', encoding='utf-8') as f: | ||
str_orig = f.read() | ||
else: | ||
file_exists = False | ||
str_orig = None | ||
|
||
if file_exists and str_orig == str_dump: | ||
is_different = False | ||
else: | ||
is_different = True | ||
print(f' update {file}') | ||
with open(file, 'w', encoding='utf-8') as f: | ||
f.write(str_dump) | ||
|
||
return is_different | ||
|
||
|
||
def collate_metrics(keys): | ||
"""Collect metrics from the first row of the table. | ||
Args: | ||
keys (List): Elements in the first row of the table. | ||
Returns: | ||
dict: A dict of metrics. | ||
""" | ||
used_metrics = dict() | ||
for idx, key in enumerate(keys): | ||
if key in ['Model', 'Dataset', 'Training Resources', 'Download']: | ||
continue | ||
used_metrics[key] = idx | ||
return used_metrics | ||
|
||
|
||
def found_table(lines, i): | ||
if i + 1 >= len(lines): | ||
return False | ||
if i - 2 < 0 or 'SKIP THIS TABLE' in lines[i - 2]: | ||
return False | ||
if lines[i][0] != '|': | ||
return False | ||
|
||
for c in ['| :', '|:', '|-']: | ||
if c in lines[i + 1]: | ||
return True | ||
return False | ||
|
||
|
||
def modelindex_to_dict(model): | ||
if isinstance(model, Collection): | ||
result = model.data | ||
if model.metadata is not None: | ||
result['Metadata'] = model.metadata.data | ||
elif isinstance(model, Model): | ||
result = model.data | ||
if model.metadata is not None: | ||
result['Metadata'] = model.metadata.data | ||
if model.results is not None: | ||
results_list = [] | ||
for r in model.results: | ||
results_list.append(r.data) | ||
result['Results'] = results_list | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.