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

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

作者: dc_3 | 来源:发表于2020-02-11 16:47 被阅读0次

    -- 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)

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/fkbxfhtx.html