移动文件
import os
import shutil
s1path='..'
#获取该目录下所有文件,存入列表中
fileList_mat=os.listdir(s1path)
for i,file in enumerate(fileList_mat):
old_path=s1path
#注意这里的new_path要根据具体情况重新定义
new_path=os.path.join(s1path,fileList_mat[i][:-9])
if not os.path.exists(new_path):
os.makedirs(new_path)
src = os.path.join(old_path, file)
dst = os.path.join(new_path, file)
shutil.move(src, dst)
修改文件名’
for i,file in enumerate(fileList_mat):
oldname=os.listdir(os.path.join(s1path,file))[0]
oldname_path=s1path+ os.sep+file+ os.sep+oldname
newname_path=os.path.join(s1path,file) + os.sep +'统一名字.mat'
os.rename(oldname_path,newname_path)
计算模型参数量
import numpy as np
import torch
model_path='..\xx.pkl'
model = torch.load(model_path)
model.eval()
model_para=sum([param.nelement() for param in model.parameters()])
print(model_para)
num='{:0>3}'.format(num) #补齐s