数据量不够时val为空debug

This commit is contained in:
JIAKUNHAO 2022-11-23 19:51:38 +08:00
parent 9818a1d488
commit 2b522c32cf

View File

@ -107,6 +107,8 @@ def mv_file(train_files: List[str], test_files: List[str], r_v_rate: Optional[fl
train_len = ceil(train_len_all * r_v_rate)
# t_files: 训练集, val_files:验证集
t_files = train_img_files[0:train_len]
if train_len==train_len_all:
train_len = 0
val_files = train_img_files[train_len:train_len_all]
# 判断目标文件夹是否存在, 存在则删除目录下文件
@ -179,18 +181,15 @@ def get_file(ori_path: str, type_list: Union[object,str]):
test_files = []
# 训练、测试比例强制91
for img in imgs[0:1]:
path = ori_path + '/images/' +img #'/images/'
# print(os.path.exists(path))
path = ori_path + '/images/' +img #'./ori/images/xxx.jpg'
print('图像路径',path)
if os.path.exists(path):
test_files.append(path)
print('1111')
#label = ori_path + 'labels/' + os.path.split(path)[1]
(filename1, extension) = os.path.splitext(img) # 文件名与后缀名分开
label = ori_path + '/labels/' + filename1 + '.json' #'/labels/'
print('标签',label)
if label is not None:
#train_files.append(label)
test_files.append(label)
print('2222')
for img in imgs[1:]:
@ -209,10 +208,6 @@ def get_file(ori_path: str, type_list: Union[object,str]):
# proj = plc.get_proj_by_proj_no(proj_no=proj_no, db=db)
target_path = mv_file(train_files=train_files, test_files=test_files)
# 生成标签
# img_types = ilc.get_label_by_proj_no(proj_no=proj_no, db=db)
# type_list = []
# for img_type in img_types:
# type_list.append(img_type.lebel_type)
type_dict = {'classes': type_list}
str_json = json.dumps(type_dict)
path = os.path.dirname(ori_path) + '/img_label_type'