加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
voc_annotation_medical.py 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
Bubbliiiing 提交于 2021-11-12 21:52 . Add files via upload
import os
import random
#----------------------------------------------------------------------#
# 医药数据集的例子没有验证集
#----------------------------------------------------------------------#
trainval_percent = 1
train_percent = 1
#-------------------------------------------------------#
# 指向医药数据集所在的文件夹
# 默认指向根目录下的Medical_Datasets
#-------------------------------------------------------#
VOCdevkit_path = 'Medical_Datasets'
if __name__ == "__main__":
random.seed(0)
print("Generate txt in ImageSets.")
segfilepath = os.path.join(VOCdevkit_path, 'Labels')
saveBasePath = os.path.join(VOCdevkit_path, 'ImageSets/Segmentation')
temp_seg = os.listdir(segfilepath)
total_seg = []
for seg in temp_seg:
if seg.endswith(".png"):
total_seg.append(seg)
num = len(total_seg)
list = range(num)
tv = int(num*trainval_percent)
tr = int(tv*train_percent)
trainval= random.sample(list,tv)
train = random.sample(trainval,tr)
print("train and val size",tv)
print("traub suze",tr)
ftrainval = open(os.path.join(saveBasePath,'trainval.txt'), 'w')
ftest = open(os.path.join(saveBasePath,'test.txt'), 'w')
ftrain = open(os.path.join(saveBasePath,'train.txt'), 'w')
fval = open(os.path.join(saveBasePath,'val.txt'), 'w')
for i in list:
name=total_seg[i][:-4]+'\n'
if i in trainval:
ftrainval.write(name)
if i in train:
ftrain.write(name)
else:
fval.write(name)
else:
ftest.write(name)
ftrainval.close()
ftrain.close()
fval.close()
ftest.close()
print("Generate txt in ImageSets done.")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化