Python 把标注文件Annotations.txt按7:2:1数量比例分配给train集,val集,test集,其中单个样本随机分配

博客演示了如何使用Python将Annotations.txt文件中的样本以7:2:1的比例随机分配到训练集、验证集和测试集中,以备进行yolov3的训练、验证和测试。
摘要由CSDN通过智能技术生成

 先测试把100个数字0-99个,按7:2:1数量比例分配给a集,b集,c集,其中单个样本随机分配

import random

totalnum = 100
t1 = totalnum*0.1
t2 = totalnum*0.2
t3 = totalnum*0.7
a = set()
b = set()
c = set()

while(len(a)<t1):
    x = random.randint(0,totalnum)
    if x not in a:
       a.add(x)

while(len(b)<t2):
    x = random.randint(0,totalnum)
    if x in a:
       continue
    if x not in b:
       b.add(x)

for x in range(totalnum):
    if x in a or x in b:
       continue
    else:
       c.add(x)

print "a = ",a,len(a)
print "b = ",b,len(b)
print "c = ",c,len(c)

wu@wu-X555LF:~$ python random_test.py
a =  set([44, 42, 12, 46, 15, 49, 19, 20, 14, 59]) 10
b =  set([35, 36, 86, 39, 8, 9, 75, 76, 13, 77, 29, 24, 78, 3, 53, 22, 88, 68, 93, 7]) 20

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值