1.将positive所有数据送入训练 import xml.etree.ElementTree as ET import pickle import os from os import listdir, getcwd from os.path import join from PIL import Image import re import random def convert(size, box): dw = 1./(size[0]) dh = 1./(size[1]) x = (box[0] + box[1])/2.0 - 1 y = (box[2] + box[3])/2.0 - 1 w = box[1] - box[0] h = box[3] - box[2] x = x*dw w = w*dw y = y*dh h = h*dh return (x,y,w,h) def convert_annotation(image_id): in_file = open('/home/vip/Documents/xigongdashujuji/NWPUVHR-10dataset/ground_truth/%s.txt' % (image_id)) out_file = open('/home/vip/Documents/xigongdashujuji/NWPUVHR-10dataset/labels/%s.txt' % (image_id), 'w') img = Image.open('/home/vip/Documents/xigongdashujuji/NWPUVHR-10dataset/positiveimageset/%s.jpg' % (image_id)) size = img.size w = int(size[0]) h = int(size[1]) for obj in in_file: newmo = (((obj.replace('(', '')).replace(')', '')).replace('(', '')).replace(')', '') list2 = newmo.strip().split(',') if len(list2)<5: continue cls_id = int(list2[4]) - 1 b = (float(list2[0]), float(list2[2]), float(list2[1]), float(list2[3])) bb = convert((w, h), b) out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n') data = [random.randint(0,649) for i in range(649)] image_ids=[] for image_temp in data: if image_temp<100: image_id_temp=(str(image_temp+1)).zfill(3) else : image_id_temp=str(image_temp+1) image_ids.append(image_id_temp) list_file = open('/home/vip/Documents/xigongdashujuji/NWPUVHR-10dataset/train.txt','w') for image_id in image_ids: list_file.write('/home/vip/Documents/xigongdashujuji/NWPUVHR-10dataset/positiveimageset/%s.jpg\n'%(image_id)) convert_annotation(image_id) list_file.close()
使用YOLOV2训练NWPUVHR-10dataset数据集
最新推荐文章于 2025-04-20 16:54:03 发布