import os
import random
xmlfilepath = 'E:\\LT0517\\label2' #注意这里是image而非mask
txtsavepath = 'E:\\LT0517'
total_xml = os.listdir(xmlfilepath)
num=len(total_xml)
list = range(num)
trainval = random.sample(list, num)
os.chdir('E:\\LT0517')
ftrainval = open('name.txt', 'w') # chuang jian yi ge txt wen jian
for i in list :
name =total_xml[i][:-4] + '\n'
ftrainval.write(name)
ftrainval.close()