From 39e93f6eb115ecf6d4e7a3cc18717f62f0166ac4 Mon Sep 17 00:00:00 2001 From: PhoenixZ810 Date: Mon, 18 Sep 2023 18:09:40 +0800 Subject: [PATCH 01/11] final I --- .../RF100-Benchmark/scripts/log_extract.py | 198 ++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 projects/RF100-Benchmark/scripts/log_extract.py diff --git a/projects/RF100-Benchmark/scripts/log_extract.py b/projects/RF100-Benchmark/scripts/log_extract.py new file mode 100644 index 00000000000..55e01b93b84 --- /dev/null +++ b/projects/RF100-Benchmark/scripts/log_extract.py @@ -0,0 +1,198 @@ +import re +import argparse +import os +import csv +import json +import pandas as pd +import openpyxl +from openpyxl import load_workbook +from openpyxl.styles import Alignment +import numpy as np + +parser = argparse.ArgumentParser(description="log_name") +parser.add_argument("method", type=str, help='method name, used in csv/xlsx header') +parser.add_argument("epoch", type=int, help = 'train_epoch, uesd for checking whether training completed') +parser.add_argument('--work_dirs', type=str, default='work_dirs/', required=False, help='directory for saving results') +args = parser.parse_args() + +def write_csv(datas): + num = 0 + fail_num = 0 + none_exist_num = 0 + fail=[] + none_exist=[] + for dataset in sorted(os.listdir("rf100/")): + print(f'\ndataset={dataset}, index={num}') + num+=1 + with open('rf100/'+dataset+'/train/_annotations.coco.json','r') as f: + image=json.load(f) + num_train = len(image['images']) # get number of train images + with open('rf100/'+dataset+'/valid/_annotations.coco.json','r') as f: + image=json.load(f) + num_valid = len(image['images']) # get number of valid images + with open('scripts/labels_names.json') as f: + label=json.load(f) + for index in label: + if index['name'] == dataset: + category = index['category'] # get category of dataset + + # determine whether the dataset directory exists + try: + dirs = [os.path.join(args.work_dirs, dataset, d) for d in os.listdir(os.path.join(args.work_dirs, dataset)) + if os.path.isdir(os.path.join(args.work_dirs, dataset, d))] + dirs.sort(key=os.path.getmtime) + + latest_dir = dirs[-1] + latest_log_name = latest_dir.split('/')[-1] + print('time='+latest_log_name) + latest_log = latest_dir+f'/{latest_log_name}.log' # get latest log name + with open(latest_log, 'r') as f: + log = f.read() + print(latest_log) + + complete_flag=re.findall(r'Epoch\(val\) \[{}\]\[\d+/\d+\]'.format(args.epoch), log) # find log of args.epoch's validing process + + # Check whether the training is complete + if not complete_flag: + fail_num+=1 + fail.append(dataset) + print("------------------------------------------------------------------------------------") + print(f'{dataset} train failed!') + print(f'{fail_num} dataset failed!') + print("------------------------------------------------------------------------------------") + key_value=[dataset, category, num_train, num_valid, '', '', '', '', ''] + else: + '''match result''' + match_all = re.findall(r'The best checkpoint with ([\d.]+) coco/bbox_mAP at ([\d.]+) epoch', log) + if match_all: + match = match_all[-1] + best_epoch = match[-1] + print(f'best_epoch={best_epoch}') + # find best result + match_AP = re.findall(r'\[{}\]\[\d+/\d+\] coco/bbox_mAP: (-?\d+\.?\d*) coco/bbox_mAP_50: (-?\d+\.?\d*) coco/bbox_mAP_75: -?\d+\.?\d* coco/bbox_mAP_s: (-?\d+\.?\d*) coco/bbox_mAP_m: (-?\d+\.?\d*) coco/bbox_mAP_l: (-?\d+\.?\d*)'.format(best_epoch), log) + print(f'match_AP={match_AP}') + + key_value = [dataset, category, num_train, num_valid] + key_value.extend(match_AP[0]) + else: + print("------------------------------------------------------------------------------------") + print('log has no result!') + print("------------------------------------------------------------------------------------") + key_value=[dataset, category, num_train, num_valid, '', '', '', '', ''] + except: + print(f"{dataset} directory doesn't exist!") + none_exist_num+=1 + none_exist.append(dataset) + key_value=[dataset, category, num_train, num_valid, '', '', '', '', ''] + + if num==1: # generate headers + result_csv = os.path.join(args.work_dirs,f'{latest_log_name}_eval.csv') + print(result_csv) + with open(result_csv, mode='w') as f: + writer = csv.writer(f) + header1 = ['Dataset', 'Category', 'Images', 'Images', args.method, args.method, args.method, args.method, args.method] + writer.writerow(header1) + with open(result_csv, mode='a') as f: + writer = csv.writer(f) + header2 = ['Dataset', 'Category', 'train', 'valid', 'mAP', 'mAP50', 'mAP_s', 'mAP_m', 'mAP_l'] + writer.writerow(header2) + writer.writerow(key_value) + + else: + with open(result_csv, mode='a') as f: + writer = csv.writer(f) + writer.writerow(key_value) + + return result_csv, fail, fail_num, none_exist, none_exist_num + +def wb_align(file, pair_ls): + # adjust format of .xlsx file + wb = load_workbook(file) + ws = wb.active + for pair in pair_ls: + ws.merge_cells(f'{pair[0]}:{pair[1]}') + ws[f'{pair[0]}'].alignment = Alignment(horizontal='center', vertical='center') + wb.save(file) + +def sort_excel(in_csv, out_xlsx): + # read csv with two headers then convert it to xlsx, sort it by category name & dataset name + df = pd.read_csv(in_csv) + df_sorted = df.iloc[1:].sort_values(by=['Category','Dataset']) + df_sort = pd.concat([df.iloc[:1], df_sorted]) + df_sort.to_excel(out_xlsx, index=False) + +def sum_excel(in_csv, out_xlsx): + # read csv with two headers then convert it to xlsx, get total number of train&valid images and mean of results + df = pd.read_csv(in_csv) + df = df.iloc[:, 1:] + average = df.iloc[1:].groupby('Category') # group by category name + df_new = df.iloc[0:1,:] + num = 0 + for key, value in average: + num += 1 + df_cate=[key] + for i in range(1,8): + if i==1 or i==2: + df_cate.append(value.iloc[:, i].astype(float).sum()) + else: + df_cate.append(format(value.iloc[:, i].astype(float).replace('', np.nan).mean(), '.4f')) + df_new.loc[len(df_new)]=df_cate + + df_cate=['total'] # final row = 'total' + for i in range(1,8): + if i==1 or i==2: + df_cate.append(df_new.iloc[1:, i].astype(float).sum()) + else: + df_cate.append(format(df_new.iloc[1:, i].astype(float).replace('', np.nan).mean(), '.4f')) + df_new.loc[len(df_new)+1] = df_cate + df_new.to_excel(out_xlsx, float_format='%.4f', index=False) + +def main(): + + result_csv, fail, fail_num, none_exist, none_exist_num = write_csv("rf_100/") + + # write detail + df = pd.read_csv(result_csv) + result_xlsx_detail = '{}_detail.xlsx'.format(result_csv.split('.')[0]) + if os.path.exists(result_xlsx_detail): + os.remove(result_xlsx_detail) + print(f'\n{result_xlsx_detail} created!\n') + df.to_excel(result_xlsx_detail) + + wb_align(result_xlsx_detail, [['D1','E1'], ['F1','J1']]) + + result_xlsx_sort = '{}_detail_sort.xlsx'.format(result_csv.split('.')[0]) + result_xlsx_sum = '{}_sum.xlsx'.format(result_csv.split('.')[0]) + if os.path.exists(result_xlsx_sum): + os.remove(result_xlsx_sum) + + # sortec by category name + sort_excel(result_csv, result_xlsx_sort) + wb_align(result_xlsx_sort, [['C1','D1'], ['E1','I1']]) + + # sum of each category + sum_excel(result_csv, result_xlsx_sum) + wb_align(result_xlsx_sum, [['A1','A2'], ['B1','C1'], ['D1','H1']]) + + # wb.save(result_xlsx_sum) + print(f'sum_file = {result_xlsx_sum}') + + ''' generate .txt file ''' + print(f'{none_exist_num} datasets were not trained:\n{none_exist}\n') + print(f'{fail_num} training failed:\n{fail}\n') + fail_txt = '{}.txt'.format(result_csv.split('.')[0]) + + with open(fail_txt, 'w') as f: + pass + with open(fail_txt, 'a') as f: + for item in none_exist: + f.write(f'{item}\n') + for item in fail: + f.write(f'{item}\n') + + print(f'all {fail_num+none_exist_num} untrained datasets have been logged in {fail_txt}!') + + +if __name__ == "__main__": + main() + \ No newline at end of file From fb5156eb8bdc6005256fa681000dc4052a47f8ea Mon Sep 17 00:00:00 2001 From: PhoenixZ810 Date: Mon, 18 Sep 2023 18:29:46 +0800 Subject: [PATCH 02/11] stop tracking ignore --- .gitignore | 123 ----------------------------------------------------- 1 file changed, 123 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 55ad113be46..00000000000 --- a/.gitignore +++ /dev/null @@ -1,123 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/en/_build/ -docs/zh_cn/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -data/ -data -.vscode -.idea -.DS_Store - -# custom -*.pkl -*.pkl.json -*.log.json -docs/modelzoo_statistics.md -mmdet/.mim -work_dirs/ - -# Pytorch -*.pth -*.py~ -*.sh~ From 7013380c946be67c002bc03921759e638213fdbe Mon Sep 17 00:00:00 2001 From: PhoenixZ810 Date: Mon, 18 Sep 2023 18:37:36 +0800 Subject: [PATCH 03/11] final II --- .../RF100-Benchmark/scripts/log_extract.py | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/projects/RF100-Benchmark/scripts/log_extract.py b/projects/RF100-Benchmark/scripts/log_extract.py index 55e01b93b84..c5b705f64ba 100644 --- a/projects/RF100-Benchmark/scripts/log_extract.py +++ b/projects/RF100-Benchmark/scripts/log_extract.py @@ -9,25 +9,38 @@ from openpyxl.styles import Alignment import numpy as np -parser = argparse.ArgumentParser(description="log_name") -parser.add_argument("method", type=str, help='method name, used in csv/xlsx header') -parser.add_argument("epoch", type=int, help = 'train_epoch, uesd for checking whether training completed') -parser.add_argument('--work_dirs', type=str, default='work_dirs/', required=False, help='directory for saving results') -args = parser.parse_args() - -def write_csv(datas): +def parse_args(): + parser = argparse.ArgumentParser(description="log_name") + parser.add_argument("method", + type=str, + help='method name, used in csv/xlsx header') + parser.add_argument("--epoch", + type=int, + default=25, + required=False, + help='train_epoch, uesd for checking whether training completed') + parser.add_argument('--work-dirs', + type=str, + default='work_dirs/', + required=False, + help='directory for saving results') + args = parser.parse_args() + + return args + +def write_csv(datas, args): num = 0 fail_num = 0 none_exist_num = 0 fail=[] none_exist=[] - for dataset in sorted(os.listdir("rf100/")): + for dataset in sorted(os.listdir(datas)): print(f'\ndataset={dataset}, index={num}') num+=1 - with open('rf100/'+dataset+'/train/_annotations.coco.json','r') as f: + with open(os.path.join(datas, dataset, 'train/_annotations.coco.json'),'r') as f: image=json.load(f) num_train = len(image['images']) # get number of train images - with open('rf100/'+dataset+'/valid/_annotations.coco.json','r') as f: + with open(os.path.join(datas, dataset,'valid/_annotations.coco.json'),'r') as f: image=json.load(f) num_valid = len(image['images']) # get number of valid images with open('scripts/labels_names.json') as f: @@ -148,8 +161,9 @@ def sum_excel(in_csv, out_xlsx): df_new.to_excel(out_xlsx, float_format='%.4f', index=False) def main(): + args = parse_args() - result_csv, fail, fail_num, none_exist, none_exist_num = write_csv("rf_100/") + result_csv, fail, fail_num, none_exist, none_exist_num = write_csv("rf100/", args) # write detail df = pd.read_csv(result_csv) @@ -195,4 +209,3 @@ def main(): if __name__ == "__main__": main() - \ No newline at end of file From 1d101600dff88b551b9f25ed9a5a28bcb00ebef2 Mon Sep 17 00:00:00 2001 From: PhoenixZ810 Date: Mon, 18 Sep 2023 20:30:34 +0800 Subject: [PATCH 04/11] final III --- .../RF100-Benchmark/scripts/log_extract.py | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/projects/RF100-Benchmark/scripts/log_extract.py b/projects/RF100-Benchmark/scripts/log_extract.py index c5b705f64ba..702d6ff9644 100644 --- a/projects/RF100-Benchmark/scripts/log_extract.py +++ b/projects/RF100-Benchmark/scripts/log_extract.py @@ -18,12 +18,17 @@ def parse_args(): type=int, default=25, required=False, - help='train_epoch, uesd for checking whether training completed') + help='train_epoch, used for checking whether training completed') parser.add_argument('--work-dirs', type=str, default='work_dirs/', required=False, help='directory for saving results') + parser.add_argument('--origin', + type=str, + default=False, + required=False, + help='excel with datasets in the order of execution ') args = parser.parse_args() return args @@ -32,8 +37,11 @@ def write_csv(datas, args): num = 0 fail_num = 0 none_exist_num = 0 - fail=[] - none_exist=[] + fail = [] + none_exist = [] + latest_time = 0 + with open('scripts/labels_names.json') as f: + label=json.load(f) for dataset in sorted(os.listdir(datas)): print(f'\ndataset={dataset}, index={num}') num+=1 @@ -43,11 +51,9 @@ def write_csv(datas, args): with open(os.path.join(datas, dataset,'valid/_annotations.coco.json'),'r') as f: image=json.load(f) num_valid = len(image['images']) # get number of valid images - with open('scripts/labels_names.json') as f: - label=json.load(f) - for index in label: - if index['name'] == dataset: - category = index['category'] # get category of dataset + for index in label: + if index['name'] == dataset: + category = index['category'] # get category of dataset # determine whether the dataset directory exists try: @@ -57,6 +63,8 @@ def write_csv(datas, args): latest_dir = dirs[-1] latest_log_name = latest_dir.split('/')[-1] + if int(latest_log_name)>int(latest_time): + latest_time = latest_log_name print('time='+latest_log_name) latest_log = latest_dir+f'/{latest_log_name}.log' # get latest log name with open(latest_log, 'r') as f: @@ -116,7 +124,7 @@ def write_csv(datas, args): writer = csv.writer(f) writer.writerow(key_value) - return result_csv, fail, fail_num, none_exist, none_exist_num + return result_csv, fail, fail_num, none_exist, none_exist_num, os.path.join(args.work_dirs, latest_time[4:]) def wb_align(file, pair_ls): # adjust format of .xlsx file @@ -163,20 +171,24 @@ def sum_excel(in_csv, out_xlsx): def main(): args = parse_args() - result_csv, fail, fail_num, none_exist, none_exist_num = write_csv("rf100/", args) + result_csv, fail, fail_num, none_exist, none_exist_num, latest_time = write_csv("rf100/", args) + + os.rename(result_csv, latest_time+'_eval.csv') + result_csv = latest_time+'_eval.csv' + # write excel with datasets in the order of execution + if(args.origin): + df = pd.read_csv(result_csv) + result_xlsx_detail = '{}_detail.xlsx'.format(latest_time) + if os.path.exists(result_xlsx_detail): + os.remove(result_xlsx_detail) + print(f'\n{result_xlsx_detail} created!\n') + df.to_excel(result_xlsx_detail) + wb_align(result_xlsx_detail, [['D1','E1'], ['F1','J1']]) - # write detail - df = pd.read_csv(result_csv) - result_xlsx_detail = '{}_detail.xlsx'.format(result_csv.split('.')[0]) - if os.path.exists(result_xlsx_detail): - os.remove(result_xlsx_detail) - print(f'\n{result_xlsx_detail} created!\n') - df.to_excel(result_xlsx_detail) - wb_align(result_xlsx_detail, [['D1','E1'], ['F1','J1']]) - result_xlsx_sort = '{}_detail_sort.xlsx'.format(result_csv.split('.')[0]) - result_xlsx_sum = '{}_sum.xlsx'.format(result_csv.split('.')[0]) + result_xlsx_sort = '{}_sort.xlsx'.format(latest_time) + result_xlsx_sum = '{}_sum.xlsx'.format(latest_time) if os.path.exists(result_xlsx_sum): os.remove(result_xlsx_sum) @@ -194,7 +206,7 @@ def main(): ''' generate .txt file ''' print(f'{none_exist_num} datasets were not trained:\n{none_exist}\n') print(f'{fail_num} training failed:\n{fail}\n') - fail_txt = '{}.txt'.format(result_csv.split('.')[0]) + fail_txt = 'failed_dataset_list.txt' with open(fail_txt, 'w') as f: pass From 4746cf183715ad5a76633de6b3a4351d70a9ecde Mon Sep 17 00:00:00 2001 From: PhoenixZ810 Date: Tue, 19 Sep 2023 10:42:51 +0800 Subject: [PATCH 05/11] final III rename --- projects/RF100-Benchmark/scripts/log_extract.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/projects/RF100-Benchmark/scripts/log_extract.py b/projects/RF100-Benchmark/scripts/log_extract.py index 702d6ff9644..aef3cefbf6a 100644 --- a/projects/RF100-Benchmark/scripts/log_extract.py +++ b/projects/RF100-Benchmark/scripts/log_extract.py @@ -175,10 +175,11 @@ def main(): os.rename(result_csv, latest_time+'_eval.csv') result_csv = latest_time+'_eval.csv' - # write excel with datasets in the order of execution + + # write excel in the order of execution if(args.origin): df = pd.read_csv(result_csv) - result_xlsx_detail = '{}_detail.xlsx'.format(latest_time) + result_xlsx_detail = '{}_origin.xlsx'.format(latest_time) if os.path.exists(result_xlsx_detail): os.remove(result_xlsx_detail) print(f'\n{result_xlsx_detail} created!\n') @@ -186,8 +187,8 @@ def main(): wb_align(result_xlsx_detail, [['D1','E1'], ['F1','J1']]) - - result_xlsx_sort = '{}_sort.xlsx'.format(latest_time) + # write excel in the order of category&dataset name + result_xlsx_sort = '{}_detail.xlsx'.format(latest_time) result_xlsx_sum = '{}_sum.xlsx'.format(latest_time) if os.path.exists(result_xlsx_sum): os.remove(result_xlsx_sum) From 166a02a18d479aa859708259dec8d0e5b8fec409 Mon Sep 17 00:00:00 2001 From: PhoenixZ810 Date: Tue, 19 Sep 2023 11:29:44 +0800 Subject: [PATCH 06/11] ignore --- .gitignore | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..aa79341d30f --- /dev/null +++ b/.gitignore @@ -0,0 +1,127 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/en/_build/ +docs/zh_cn/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +data/ +data +.vscode +.idea +.DS_Store + +# custom +*.pkl +*.pkl.json +*.log.json +docs/modelzoo_statistics.md +mmdet/.mim +**work_dirs/ +projects/ROBOFLOW-100-BENCHMARK +.gitignore +projects/RF100-Benchmark/rf100 +projects/RF100-Benchmark/temp_configs/ + +# Pytorch +*.pth +*.py~ +*.sh~ From 8ab40096fd62d12cbfd24c963c407b2f639fd9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haian=20Huang=28=E6=B7=B1=E5=BA=A6=E7=9C=B8=29?= <1286304229@qq.com> Date: Tue, 19 Sep 2023 12:04:24 +0800 Subject: [PATCH 07/11] Delete .gitignore --- .gitignore | 127 ----------------------------------------------------- 1 file changed, 127 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index aa79341d30f..00000000000 --- a/.gitignore +++ /dev/null @@ -1,127 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/en/_build/ -docs/zh_cn/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -data/ -data -.vscode -.idea -.DS_Store - -# custom -*.pkl -*.pkl.json -*.log.json -docs/modelzoo_statistics.md -mmdet/.mim -**work_dirs/ -projects/ROBOFLOW-100-BENCHMARK -.gitignore -projects/RF100-Benchmark/rf100 -projects/RF100-Benchmark/temp_configs/ - -# Pytorch -*.pth -*.py~ -*.sh~ From 6a91249dc455e0eca9de42d7a6775b4f28185881 Mon Sep 17 00:00:00 2001 From: PhoenixZ810 Date: Tue, 19 Sep 2023 12:49:43 +0800 Subject: [PATCH 08/11] ignore --- .gitignore | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..55ad113be46 --- /dev/null +++ b/.gitignore @@ -0,0 +1,123 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/en/_build/ +docs/zh_cn/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +data/ +data +.vscode +.idea +.DS_Store + +# custom +*.pkl +*.pkl.json +*.log.json +docs/modelzoo_statistics.md +mmdet/.mim +work_dirs/ + +# Pytorch +*.pth +*.py~ +*.sh~ From d5d8ef144821e5c2918d3aabbfbea2b05b0b8570 Mon Sep 17 00:00:00 2001 From: PhoenixZ810 Date: Tue, 19 Sep 2023 13:22:42 +0800 Subject: [PATCH 09/11] final V, format --- .../RF100-Benchmark/scripts/log_extract.py | 208 +++++++++++------- 1 file changed, 131 insertions(+), 77 deletions(-) diff --git a/projects/RF100-Benchmark/scripts/log_extract.py b/projects/RF100-Benchmark/scripts/log_extract.py index aef3cefbf6a..1e716e183a8 100644 --- a/projects/RF100-Benchmark/scripts/log_extract.py +++ b/projects/RF100-Benchmark/scripts/log_extract.py @@ -1,38 +1,42 @@ -import re import argparse -import os import csv import json +import os +import re + +import numpy as np import pandas as pd -import openpyxl from openpyxl import load_workbook from openpyxl.styles import Alignment -import numpy as np + def parse_args(): - parser = argparse.ArgumentParser(description="log_name") - parser.add_argument("method", - type=str, - help='method name, used in csv/xlsx header') - parser.add_argument("--epoch", - type=int, - default=25, - required=False, - help='train_epoch, used for checking whether training completed') - parser.add_argument('--work-dirs', - type=str, - default='work_dirs/', - required=False, - help='directory for saving results') - parser.add_argument('--origin', - type=str, - default=False, - required=False, - help='excel with datasets in the order of execution ') + parser = argparse.ArgumentParser(description='log_name') + parser.add_argument( + 'method', type=str, help='method name, used in csv/xlsx header') + parser.add_argument( + '--epoch', + type=int, + default=25, + required=False, + help='train_epoch, used for checking whether training completed') + parser.add_argument( + '--work-dirs', + type=str, + default='work_dirs/', + required=False, + help='directory for saving results') + parser.add_argument( + '--origin', + type=str, + default=False, + required=False, + help='excel with datasets in the order of execution ') args = parser.parse_args() return args + def write_csv(datas, args): num = 0 fail_num = 0 @@ -41,15 +45,19 @@ def write_csv(datas, args): none_exist = [] latest_time = 0 with open('scripts/labels_names.json') as f: - label=json.load(f) + label = json.load(f) for dataset in sorted(os.listdir(datas)): print(f'\ndataset={dataset}, index={num}') - num+=1 - with open(os.path.join(datas, dataset, 'train/_annotations.coco.json'),'r') as f: - image=json.load(f) + num += 1 + with open( + os.path.join(datas, dataset, 'train/_annotations.coco.json'), + 'r') as f: + image = json.load(f) num_train = len(image['images']) # get number of train images - with open(os.path.join(datas, dataset,'valid/_annotations.coco.json'),'r') as f: - image=json.load(f) + with open( + os.path.join(datas, dataset, 'valid/_annotations.coco.json'), + 'r') as f: + image = json.load(f) num_valid = len(image['images']) # get number of valid images for index in label: if index['name'] == dataset: @@ -57,65 +65,96 @@ def write_csv(datas, args): # determine whether the dataset directory exists try: - dirs = [os.path.join(args.work_dirs, dataset, d) for d in os.listdir(os.path.join(args.work_dirs, dataset)) - if os.path.isdir(os.path.join(args.work_dirs, dataset, d))] + dirs = [ + os.path.join(args.work_dirs, dataset, d) + for d in os.listdir(os.path.join(args.work_dirs, dataset)) + if os.path.isdir(os.path.join(args.work_dirs, dataset, d)) + ] dirs.sort(key=os.path.getmtime) latest_dir = dirs[-1] latest_log_name = latest_dir.split('/')[-1] - if int(latest_log_name)>int(latest_time): + if int(latest_log_name) > int(latest_time): latest_time = latest_log_name - print('time='+latest_log_name) - latest_log = latest_dir+f'/{latest_log_name}.log' # get latest log name + print('time=' + latest_log_name) + latest_log = latest_dir + f'/{latest_log_name}.log' # get latest log name with open(latest_log, 'r') as f: log = f.read() print(latest_log) - complete_flag=re.findall(r'Epoch\(val\) \[{}\]\[\d+/\d+\]'.format(args.epoch), log) # find log of args.epoch's validing process + complete_flag = re.findall( + r'Epoch\(val\) \[{}\]\[\d+/\d+\]'.format(args.epoch), + log) # find log of args.epoch's validating process # Check whether the training is complete if not complete_flag: - fail_num+=1 + fail_num += 1 fail.append(dataset) - print("------------------------------------------------------------------------------------") + print( + '------------------------------------------------------------------------------------' + ) print(f'{dataset} train failed!') print(f'{fail_num} dataset failed!') - print("------------------------------------------------------------------------------------") - key_value=[dataset, category, num_train, num_valid, '', '', '', '', ''] + print( + '------------------------------------------------------------------------------------' + ) + key_value = [ + dataset, category, num_train, num_valid, '', '', '', '', '' + ] else: - '''match result''' - match_all = re.findall(r'The best checkpoint with ([\d.]+) coco/bbox_mAP at ([\d.]+) epoch', log) + """match result.""" + match_all = re.findall( + r'The best checkpoint with ([\d.]+) coco/bbox_mAP at ([\d.]+) epoch', + log) if match_all: match = match_all[-1] best_epoch = match[-1] print(f'best_epoch={best_epoch}') # find best result - match_AP = re.findall(r'\[{}\]\[\d+/\d+\] coco/bbox_mAP: (-?\d+\.?\d*) coco/bbox_mAP_50: (-?\d+\.?\d*) coco/bbox_mAP_75: -?\d+\.?\d* coco/bbox_mAP_s: (-?\d+\.?\d*) coco/bbox_mAP_m: (-?\d+\.?\d*) coco/bbox_mAP_l: (-?\d+\.?\d*)'.format(best_epoch), log) + match_AP = re.findall( + r'\[{}\]\[\d+/\d+\] coco/bbox_mAP: (-?\d+\.?\d*) coco/bbox_mAP_50: (-?\d+\.?\d*) coco/bbox_mAP_75: -?\d+\.?\d* coco/bbox_mAP_s: (-?\d+\.?\d*) coco/bbox_mAP_m: (-?\d+\.?\d*) coco/bbox_mAP_l: (-?\d+\.?\d*)' + .format(best_epoch), log) print(f'match_AP={match_AP}') key_value = [dataset, category, num_train, num_valid] key_value.extend(match_AP[0]) else: - print("------------------------------------------------------------------------------------") + print( + '------------------------------------------------------------------------------------' + ) print('log has no result!') - print("------------------------------------------------------------------------------------") - key_value=[dataset, category, num_train, num_valid, '', '', '', '', ''] + print( + '------------------------------------------------------------------------------------' + ) + key_value = [ + dataset, category, num_train, num_valid, '', '', '', + '', '' + ] except: print(f"{dataset} directory doesn't exist!") - none_exist_num+=1 + none_exist_num += 1 none_exist.append(dataset) - key_value=[dataset, category, num_train, num_valid, '', '', '', '', ''] + key_value = [ + dataset, category, num_train, num_valid, '', '', '', '', '' + ] - if num==1: # generate headers - result_csv = os.path.join(args.work_dirs,f'{latest_log_name}_eval.csv') + if num == 1: # generate headers + result_csv = os.path.join(args.work_dirs, + f'{latest_log_name}_eval.csv') print(result_csv) with open(result_csv, mode='w') as f: writer = csv.writer(f) - header1 = ['Dataset', 'Category', 'Images', 'Images', args.method, args.method, args.method, args.method, args.method] + header1 = [ + 'Dataset', 'Category', 'Images', 'Images', args.method, + args.method, args.method, args.method, args.method + ] writer.writerow(header1) with open(result_csv, mode='a') as f: writer = csv.writer(f) - header2 = ['Dataset', 'Category', 'train', 'valid', 'mAP', 'mAP50', 'mAP_s', 'mAP_m', 'mAP_l'] + header2 = [ + 'Dataset', 'Category', 'train', 'valid', 'mAP', 'mAP50', + 'mAP_s', 'mAP_m', 'mAP_l' + ] writer.writerow(header2) writer.writerow(key_value) @@ -124,7 +163,9 @@ def write_csv(datas, args): writer = csv.writer(f) writer.writerow(key_value) - return result_csv, fail, fail_num, none_exist, none_exist_num, os.path.join(args.work_dirs, latest_time[4:]) + return result_csv, fail, fail_num, none_exist, none_exist_num, os.path.join( + args.work_dirs, latest_time[4:]) + def wb_align(file, pair_ls): # adjust format of .xlsx file @@ -132,60 +173,72 @@ def wb_align(file, pair_ls): ws = wb.active for pair in pair_ls: ws.merge_cells(f'{pair[0]}:{pair[1]}') - ws[f'{pair[0]}'].alignment = Alignment(horizontal='center', vertical='center') + ws[f'{pair[0]}'].alignment = Alignment( + horizontal='center', vertical='center') wb.save(file) + def sort_excel(in_csv, out_xlsx): # read csv with two headers then convert it to xlsx, sort it by category name & dataset name df = pd.read_csv(in_csv) - df_sorted = df.iloc[1:].sort_values(by=['Category','Dataset']) + df_sorted = df.iloc[1:].sort_values(by=['Category', 'Dataset']) df_sort = pd.concat([df.iloc[:1], df_sorted]) df_sort.to_excel(out_xlsx, index=False) + def sum_excel(in_csv, out_xlsx): # read csv with two headers then convert it to xlsx, get total number of train&valid images and mean of results df = pd.read_csv(in_csv) df = df.iloc[:, 1:] average = df.iloc[1:].groupby('Category') # group by category name - df_new = df.iloc[0:1,:] + df_new = df.iloc[0:1, :] num = 0 for key, value in average: num += 1 - df_cate=[key] - for i in range(1,8): - if i==1 or i==2: + df_cate = [key] + for i in range(1, 8): + if i == 1 or i == 2: df_cate.append(value.iloc[:, i].astype(float).sum()) else: - df_cate.append(format(value.iloc[:, i].astype(float).replace('', np.nan).mean(), '.4f')) - df_new.loc[len(df_new)]=df_cate + df_cate.append( + format( + value.iloc[:, i].astype(float).replace('', + np.nan).mean(), + '.4f')) + df_new.loc[len(df_new)] = df_cate - df_cate=['total'] # final row = 'total' - for i in range(1,8): - if i==1 or i==2: + df_cate = ['total'] # final row = 'total' + for i in range(1, 8): + if i == 1 or i == 2: df_cate.append(df_new.iloc[1:, i].astype(float).sum()) else: - df_cate.append(format(df_new.iloc[1:, i].astype(float).replace('', np.nan).mean(), '.4f')) - df_new.loc[len(df_new)+1] = df_cate + df_cate.append( + format( + df_new.iloc[1:, i].astype(float).replace('', + np.nan).mean(), + '.4f')) + df_new.loc[len(df_new) + 1] = df_cate df_new.to_excel(out_xlsx, float_format='%.4f', index=False) + def main(): args = parse_args() - result_csv, fail, fail_num, none_exist, none_exist_num, latest_time = write_csv("rf100/", args) + result_csv, fail, fail_num, none_exist, none_exist_num, latest_time = write_csv( + 'rf100/', args) - os.rename(result_csv, latest_time+'_eval.csv') - result_csv = latest_time+'_eval.csv' + os.rename(result_csv, latest_time + '_eval.csv') + result_csv = latest_time + '_eval.csv' # write excel in the order of execution - if(args.origin): + if (args.origin): df = pd.read_csv(result_csv) result_xlsx_detail = '{}_origin.xlsx'.format(latest_time) if os.path.exists(result_xlsx_detail): os.remove(result_xlsx_detail) print(f'\n{result_xlsx_detail} created!\n') df.to_excel(result_xlsx_detail) - wb_align(result_xlsx_detail, [['D1','E1'], ['F1','J1']]) - + wb_align(result_xlsx_detail, [['D1', 'E1'], ['F1', 'J1']]) # write excel in the order of category&dataset name result_xlsx_sort = '{}_detail.xlsx'.format(latest_time) @@ -195,20 +248,19 @@ def main(): # sortec by category name sort_excel(result_csv, result_xlsx_sort) - wb_align(result_xlsx_sort, [['C1','D1'], ['E1','I1']]) + wb_align(result_xlsx_sort, [['C1', 'D1'], ['E1', 'I1']]) # sum of each category sum_excel(result_csv, result_xlsx_sum) - wb_align(result_xlsx_sum, [['A1','A2'], ['B1','C1'], ['D1','H1']]) + wb_align(result_xlsx_sum, [['A1', 'A2'], ['B1', 'C1'], ['D1', 'H1']]) # wb.save(result_xlsx_sum) print(f'sum_file = {result_xlsx_sum}') - ''' generate .txt file ''' print(f'{none_exist_num} datasets were not trained:\n{none_exist}\n') print(f'{fail_num} training failed:\n{fail}\n') - fail_txt = 'failed_dataset_list.txt' + fail_txt = os.path.join(args.work_dirs, 'failed_dataset_list.txt') with open(fail_txt, 'w') as f: pass with open(fail_txt, 'a') as f: @@ -217,8 +269,10 @@ def main(): for item in fail: f.write(f'{item}\n') - print(f'all {fail_num+none_exist_num} untrained datasets have been logged in {fail_txt}!') + print( + f'all {fail_num+none_exist_num} untrained datasets have been logged in {fail_txt}!' + ) -if __name__ == "__main__": +if __name__ == '__main__': main() From 830ccc748ef1c0b2eae648965ec3cc932f2b655e Mon Sep 17 00:00:00 2001 From: PhoenixZ810 Date: Tue, 19 Sep 2023 18:01:15 +0800 Subject: [PATCH 10/11] add classes column --- .../RF100-Benchmark/scripts/log_extract.py | 70 +++++++++++-------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/projects/RF100-Benchmark/scripts/log_extract.py b/projects/RF100-Benchmark/scripts/log_extract.py index 1e716e183a8..4675ddc5580 100644 --- a/projects/RF100-Benchmark/scripts/log_extract.py +++ b/projects/RF100-Benchmark/scripts/log_extract.py @@ -62,6 +62,7 @@ def write_csv(datas, args): for index in label: if index['name'] == dataset: category = index['category'] # get category of dataset + class_num = len(index['classes'].keys()) # determine whether the dataset directory exists try: @@ -99,7 +100,7 @@ def write_csv(datas, args): '------------------------------------------------------------------------------------' ) key_value = [ - dataset, category, num_train, num_valid, '', '', '', '', '' + dataset, category, class_num, num_train, num_valid, '', '', '', '', '' ] else: """match result.""" @@ -116,7 +117,7 @@ def write_csv(datas, args): .format(best_epoch), log) print(f'match_AP={match_AP}') - key_value = [dataset, category, num_train, num_valid] + key_value = [dataset, category, class_num, num_train, num_valid] key_value.extend(match_AP[0]) else: print( @@ -127,7 +128,7 @@ def write_csv(datas, args): '------------------------------------------------------------------------------------' ) key_value = [ - dataset, category, num_train, num_valid, '', '', '', + dataset, category, class_num, num_train, num_valid, '', '', '', '', '' ] except: @@ -145,14 +146,14 @@ def write_csv(datas, args): with open(result_csv, mode='w') as f: writer = csv.writer(f) header1 = [ - 'Dataset', 'Category', 'Images', 'Images', args.method, + 'Dataset', 'Category', 'Classes', 'Images', 'Images', args.method, args.method, args.method, args.method, args.method ] writer.writerow(header1) with open(result_csv, mode='a') as f: writer = csv.writer(f) header2 = [ - 'Dataset', 'Category', 'train', 'valid', 'mAP', 'mAP50', + 'Dataset', 'Category', 'Classes', 'train', 'valid', 'mAP', 'mAP50', 'mAP_s', 'mAP_m', 'mAP_l' ] writer.writerow(header2) @@ -189,6 +190,7 @@ def sort_excel(in_csv, out_xlsx): def sum_excel(in_csv, out_xlsx): # read csv with two headers then convert it to xlsx, get total number of train&valid images and mean of results df = pd.read_csv(in_csv) + df.insert(2, 'dataset', pd.Series([])) df = df.iloc[:, 1:] average = df.iloc[1:].groupby('Category') # group by category name df_new = df.iloc[0:1, :] @@ -196,8 +198,10 @@ def sum_excel(in_csv, out_xlsx): for key, value in average: num += 1 df_cate = [key] - for i in range(1, 8): - if i == 1 or i == 2: + for i in range(1, 10): + if i==1: + df_cate.append(len(value)) + elif i!=1 and i<5: df_cate.append(value.iloc[:, i].astype(float).sum()) else: df_cate.append( @@ -205,11 +209,12 @@ def sum_excel(in_csv, out_xlsx): value.iloc[:, i].astype(float).replace('', np.nan).mean(), '.4f')) + # import pdb;pdb.set_trace() df_new.loc[len(df_new)] = df_cate df_cate = ['total'] # final row = 'total' - for i in range(1, 8): - if i == 1 or i == 2: + for i in range(1, 10): + if i<5: df_cate.append(df_new.iloc[1:, i].astype(float).sum()) else: df_cate.append( @@ -230,6 +235,9 @@ def main(): os.rename(result_csv, latest_time + '_eval.csv') result_csv = latest_time + '_eval.csv' + # result_csv = 'work_dirs/0919_161800_eval.csv' + # latest_time = '0919_161800' + # write excel in the order of execution if (args.origin): df = pd.read_csv(result_csv) @@ -238,7 +246,7 @@ def main(): os.remove(result_xlsx_detail) print(f'\n{result_xlsx_detail} created!\n') df.to_excel(result_xlsx_detail) - wb_align(result_xlsx_detail, [['D1', 'E1'], ['F1', 'J1']]) + wb_align(result_xlsx_detail, [['E1', 'F1'], ['G1', 'K1']]) # write excel in the order of category&dataset name result_xlsx_sort = '{}_detail.xlsx'.format(latest_time) @@ -248,30 +256,30 @@ def main(): # sortec by category name sort_excel(result_csv, result_xlsx_sort) - wb_align(result_xlsx_sort, [['C1', 'D1'], ['E1', 'I1']]) + wb_align(result_xlsx_sort, [['D1', 'E1'], ['F1', 'J1']]) # sum of each category sum_excel(result_csv, result_xlsx_sum) - wb_align(result_xlsx_sum, [['A1', 'A2'], ['B1', 'C1'], ['D1', 'H1']]) - - # wb.save(result_xlsx_sum) - print(f'sum_file = {result_xlsx_sum}') - ''' generate .txt file ''' - print(f'{none_exist_num} datasets were not trained:\n{none_exist}\n') - print(f'{fail_num} training failed:\n{fail}\n') - - fail_txt = os.path.join(args.work_dirs, 'failed_dataset_list.txt') - with open(fail_txt, 'w') as f: - pass - with open(fail_txt, 'a') as f: - for item in none_exist: - f.write(f'{item}\n') - for item in fail: - f.write(f'{item}\n') - - print( - f'all {fail_num+none_exist_num} untrained datasets have been logged in {fail_txt}!' - ) + wb_align(result_xlsx_sum, [['A1', 'A2'], ['B1', 'B2'], ['C1', 'C2'], ['D1', 'E1'], ['F1', 'J1']]) + + # # save fail + # print(f'sum_file = {result_xlsx_sum}') + # ''' generate .txt file ''' + # print(f'{none_exist_num} datasets were not trained:\n{none_exist}\n') + # print(f'{fail_num} training failed:\n{fail}\n') + + # fail_txt = os.path.join(args.work_dirs, 'failed_dataset_list.txt') + # with open(fail_txt, 'w') as f: + # pass + # with open(fail_txt, 'a') as f: + # for item in none_exist: + # f.write(f'{item}\n') + # for item in fail: + # f.write(f'{item}\n') + + # print( + # f'all {fail_num+none_exist_num} untrained datasets have been logged in {fail_txt}!' + # ) if __name__ == '__main__': From c91ce17aa602add31e567e6be0e722e70d25272d Mon Sep 17 00:00:00 2001 From: PhoenixZ810 Date: Tue, 19 Sep 2023 19:14:06 +0800 Subject: [PATCH 11/11] add column --- .../RF100-Benchmark/scripts/log_extract.py | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/projects/RF100-Benchmark/scripts/log_extract.py b/projects/RF100-Benchmark/scripts/log_extract.py index 4675ddc5580..a3c0f629f9d 100644 --- a/projects/RF100-Benchmark/scripts/log_extract.py +++ b/projects/RF100-Benchmark/scripts/log_extract.py @@ -100,7 +100,8 @@ def write_csv(datas, args): '------------------------------------------------------------------------------------' ) key_value = [ - dataset, category, class_num, num_train, num_valid, '', '', '', '', '' + dataset, category, class_num, num_train, num_valid, '', '', + '', '', '' ] else: """match result.""" @@ -117,7 +118,9 @@ def write_csv(datas, args): .format(best_epoch), log) print(f'match_AP={match_AP}') - key_value = [dataset, category, class_num, num_train, num_valid] + key_value = [ + dataset, category, class_num, num_train, num_valid + ] key_value.extend(match_AP[0]) else: print( @@ -128,8 +131,8 @@ def write_csv(datas, args): '------------------------------------------------------------------------------------' ) key_value = [ - dataset, category, class_num, num_train, num_valid, '', '', '', - '', '' + dataset, category, class_num, num_train, num_valid, '', + '', '', '', '' ] except: print(f"{dataset} directory doesn't exist!") @@ -146,15 +149,16 @@ def write_csv(datas, args): with open(result_csv, mode='w') as f: writer = csv.writer(f) header1 = [ - 'Dataset', 'Category', 'Classes', 'Images', 'Images', args.method, - args.method, args.method, args.method, args.method + 'Dataset', 'Category', 'Classes', 'Images', 'Images', + args.method, args.method, args.method, args.method, + args.method ] writer.writerow(header1) with open(result_csv, mode='a') as f: writer = csv.writer(f) header2 = [ - 'Dataset', 'Category', 'Classes', 'train', 'valid', 'mAP', 'mAP50', - 'mAP_s', 'mAP_m', 'mAP_l' + 'Dataset', 'Category', 'Classes', 'train', 'valid', 'mAP', + 'mAP50', 'mAP_s', 'mAP_m', 'mAP_l' ] writer.writerow(header2) writer.writerow(key_value) @@ -199,9 +203,9 @@ def sum_excel(in_csv, out_xlsx): num += 1 df_cate = [key] for i in range(1, 10): - if i==1: + if i == 1: df_cate.append(len(value)) - elif i!=1 and i<5: + elif i != 1 and i < 5: df_cate.append(value.iloc[:, i].astype(float).sum()) else: df_cate.append( @@ -214,7 +218,7 @@ def sum_excel(in_csv, out_xlsx): df_cate = ['total'] # final row = 'total' for i in range(1, 10): - if i<5: + if i < 5: df_cate.append(df_new.iloc[1:, i].astype(float).sum()) else: df_cate.append( @@ -235,9 +239,6 @@ def main(): os.rename(result_csv, latest_time + '_eval.csv') result_csv = latest_time + '_eval.csv' - # result_csv = 'work_dirs/0919_161800_eval.csv' - # latest_time = '0919_161800' - # write excel in the order of execution if (args.origin): df = pd.read_csv(result_csv) @@ -260,26 +261,28 @@ def main(): # sum of each category sum_excel(result_csv, result_xlsx_sum) - wb_align(result_xlsx_sum, [['A1', 'A2'], ['B1', 'B2'], ['C1', 'C2'], ['D1', 'E1'], ['F1', 'J1']]) - - # # save fail - # print(f'sum_file = {result_xlsx_sum}') - # ''' generate .txt file ''' - # print(f'{none_exist_num} datasets were not trained:\n{none_exist}\n') - # print(f'{fail_num} training failed:\n{fail}\n') - - # fail_txt = os.path.join(args.work_dirs, 'failed_dataset_list.txt') - # with open(fail_txt, 'w') as f: - # pass - # with open(fail_txt, 'a') as f: - # for item in none_exist: - # f.write(f'{item}\n') - # for item in fail: - # f.write(f'{item}\n') - - # print( - # f'all {fail_num+none_exist_num} untrained datasets have been logged in {fail_txt}!' - # ) + wb_align( + result_xlsx_sum, + [['A1', 'A2'], ['B1', 'B2'], ['C1', 'C2'], ['D1', 'E1'], ['F1', 'J1']]) + + # save fail + print(f'sum_file = {result_xlsx_sum}') + ''' generate .txt file ''' + print(f'{none_exist_num} datasets were not trained:\n{none_exist}\n') + print(f'{fail_num} training failed:\n{fail}\n') + + fail_txt = os.path.join(args.work_dirs, 'failed_dataset_list.txt') + with open(fail_txt, 'w') as f: + pass + with open(fail_txt, 'a') as f: + for item in none_exist: + f.write(f'{item}\n') + for item in fail: + f.write(f'{item}\n') + + print( + f'all {fail_num+none_exist_num} untrained datasets have been logged in {fail_txt}!' + ) if __name__ == '__main__':