随机打乱txt标签图片,并按照9:1比例分train和test标

2020-02-11  本文已影响0人  dc_3

-- coding: utf-8 --

"""
Created on Tue Feb 11 16:00:54 2020

@author: mn_j
"""
import numpy as np

txt文件路径,可变

with open("./data/dataset/trainship.txt", 'r') as f:
txt = f.readlines()
annotations = [line.strip()+'\n' for line in txt if len(line.strip().split()[1:]) != 0]
np.random.shuffle(annotations)
total=len(annotations)
train_num=int(total*0.9)
train_ship_an=annotations[:train_num]
test_ship_an=annotations[train_num:]
with open("./data/dataset/train_ship_random.txt", 'w') as f:
f.writelines(train_ship_an)
with open("./data/dataset/test_ship_random.txt", 'w') as f:
f.writelines(test_ship_an)

上一篇下一篇

猜你喜欢

热点阅读