import os
import random
val_percent = 0.5
xmlfilepath = 'Annotations'
txtsavepath = 'ImageSets'
total_xml = os.listdir(xmlfilepath)
num = len(total_xml)
list = range(num)
tv = int(num * val_percent)
val = random.sample(list, tv)
ftrain = open('ImageSets/train.txt', 'w')
fval = open('ImageSets/val.txt', 'w')
for i in list:
    name = total_xml[i][:-4] + '\n'
    if i in val:
        fval.write(name)
    else:
        ftrain.write(name)
ftrain.close()
fval.close()

3e2efbe280bd3361c600dba3ded0c7ab2cff8d3a
<mask token>

<mask token>
for i in list:
    name = total_xml[i][:-4] + '\n'
    if i in val:
        fval.write(name)
    else:
        ftrain.write(name)
ftrain.close()
fval.close()

<mask token>
val_percent = 0.5
xmlfilepath = 'Annotations'
txtsavepath = 'ImageSets'
total_xml = os.listdir(xmlfilepath)
num = len(total_xml)
list = range(num)
tv = int(num * val_percent)
val = random.sample(list, tv)
ftrain = open('ImageSets/train.txt', 'w')
fval = open('ImageSets/val.txt', 'w')
for i in list:
    name = total_xml[i][:-4] + '\n'
    if i in val:
        fval.write(name)
    else:
        ftrain.write(name)
ftrain.close()
fval.close()

import os
import random
val_percent = 0.5
xmlfilepath = 'Annotations'
txtsavepath = 'ImageSets'
total_xml = os.listdir(xmlfilepath)
num = len(total_xml)
list = range(num)
tv = int(num * val_percent)
val = random.sample(list, tv)
ftrain = open('ImageSets/train.txt', 'w')
fval = open('ImageSets/val.txt', 'w')
for i in list:
    name = total_xml[i][:-4] + '\n'
    if i in val:
        fval.write(name)
    else:
        ftrain.write(name)
ftrain.close()
fval.close()
