is a collection of SOTA computer vision models, layers, utilities, optimizers, schedulers, data-loaders, augmentations and also training/validating scripts with ability to reproduce ImageNet training results.
#采用os.walk()方法,读取文件夹中后缀为.csv的文件名 deflistdir2(path):#path为文件夹的存储路径 type = ('.csv') #可在此处更改文件类型 list_name = [] #保存所有文件名至列表 for root, dirs, files in os.walk(path): for f in files: fname = os.path.join(root, f) if fname.endswith(type): list_name.append(fname) return list_name
2、读取多个excel内容存到list中
1 2 3 4 5 6 7 8 9
#函数的输入为列表,存储着多张excel的文件位置 #函数的输出为二维列表,保存着多张excel的内容 deftextList(list_name):#list_name为多张表的位置信息列表 text_excel = [] #text_excel为存储多张表的二维列表 for num in list_name: excel = pd.read_excel(num, header=None, skiprows=0) excel = excel.values.tolist() text_excel.extend(excel) return text_excel
3、将二维列表的值写入excel中
1 2 3 4 5 6 7 8 9 10 11 12
#利用openpyxl模块实现,还有一种常用的是利用pandas模块,后续进行介绍 defwriteToExcel(file_path, new_list):#file_path为excel存储路径,new_list为二维列表 wb = openpyxl.Workbook() ws = wb.active ws.title = 'feature' for r inrange(len(new_list)): for c inrange(len(new_list[0])): ws.cell(r + 1, c + 1).value = new_list[r][c] # excel中的行和列是从1开始计数的,所以需要+1 wb.save(file_path) # 注意,写入后一定要保存 print("成功写入文件: " + file_path + " !") return1
4、批量更改excel文件名
1 2 3 4 5 6 7 8
#批量修改文件中excel文件名,使用到1中listdir()函数 defrename_excel(path, text):#path为存储文件夹,text为替换的新内容 list_name = listdir(path) for excel_name in list_name: new_name = excel_name[:-10] + text + excel_name[-8:] os.rename(excel_name, new_name) return list_name rename_excel(r'D:\test', '27')
# 方法2 for idx, i in enumerate(tqdm(可迭代对象)): pass for idx, i in tqdm(enumerate(可迭代对象)): pass
# 方法3 而如果想要在迭代过程中变更说明文字,还可以预先实例化进度条对象,在需要刷新说明文字的时候执行相应的程序 p = tqdm(可迭代对象) for idx, i in enumerate(p): pass # 方法4 手动控制更新 with tqdm.tqdm(total=10) as bar: # total为进度条总的迭代次数 # 操作1 time.sleep(1) # 更新进度条 bar.update(1) # bar.update()里面的数表示更新的次数,和optimizer.step方法类似 # 操作2 time.sleep(2) # 更新进度条 bar.update(3) # 操作3 time.sleep(1) # 更新进度条 bar.update(6) # 建议不要超过total with tqdm(total=100) as pbar: for i in range(10): pbar.update(10) # 也可以这样 pbar = tqdm(total=100) for i in range(10): pbar.update(10) pbar.close()
for idx, element in enumerate(pbar): time.sleep(0.01) pbar.set_description(f"Epoch {idx}/{epochs}") pbar.set_postfix({"class": element}, loss=random.random(), cost_time = random.randrange(0, 100))
bar_format : str, optional
Specify a custom bar string formatting. May impact performance.
[default: '{l_bar}{bar}{r_bar}'], where
l_bar='{desc}: {percentage:3.0f}%|' and
r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}{postfix}]'
Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
percentage, elapsed, elapsed_s, ncols, desc, unit,
rate, rate_fmt, rate_noinv, rate_noinv_fmt,
rate_inv, rate_inv_fmt, postfix, unit_divisor,
remaining, remaining_s.
Note that a trailing ": " is automatically removed after {desc}
if the latter is empty.