import os
from os import getcwd
wd =getcwd()
mulu=['/'+'annotations_train_xml','/'+'annotations_val_xml']
count=0
for i in mulu:
count+=1
dir =wd+i
print(dir)
filenames=os.listdir(dir)
if count==1:
f=open('train_all.txt','w')
count_1=0
for filename in filenames:
count_1+=1
out_path=dir+'/'+filename.replace('xml','jpg')
out_path=out_path.replace('annotations_train_xml','JPEGImages/train2017')
f.write(out_path+'\n')
f.close()
print('done!,total:%s'%count_1)
elif count==2:
f=open('val_all.txt','w')
count_1=0
for filename in filenames:
count_1+=1
out_path=dir+'/'+filename.replace('xml','jpg')
out_path=out_path.replace('annotations_val_xml','JPEGImages/val2017')
f.write(out_path+'\n')
f.close()
print('done!,total:%s'%count_1)
3.2 第二部分
然后将得到的文件一起整理好,生成每个xml对应的txt标签
这里也是先执行train 然后修改train为val继续执行,就是打###的三个部分的路径
import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
#20190227@new-only 2007 data
#sets=[('2007', 'train'), ('2007', 'val'), ('2007_test', 'test')]
sets =['train']
#classes = ['1', '2', '3','4','5','6','7','8','9','10','11', '12', '13','14','15','16','17','18','19','20']
classes = ['person','bicycle', 'car','motorcycle','airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog','horse', 'sheep','cow','elephant','bear', 'zebra', 'giraffe','backpack','umbrella', 'handbag','tie', 'suitcase', 'frisbee', 'skis', 'snowboard','sports ball', 'kite', 'baseball bat', 'baseball glove','skateboard', 'surfboard', 'tennis racket','bottle', 'wine glass', 'cup', 'fork','knife', 'spoon', 'bowl', 'banana','apple', 'sandwich', 'orange','broccoli', 'carrot', 'hot dog', 'pizza','donut', 'cake', 'chair', 'couch', 'potted plant', 'bed','dining table', 'toilet','tv','laptop', 'mouse','remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush']
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):
#print("2-open annotations")
#print('image_id:%s'%image_id)
#image_id_1 = image_id.split('/')[-1]
#print('image_id:%s'%image_id)
#imade_id = image_id_1.replace("jpg","xml")
#print('image_id:%s'%image_id)
#in_file = open('/home/test/darknet/VOC2020/annotations_val_xml/%s.xml'%(image_id))
#print('infile:','/home/test/darknet/VOC2020/annotations_val_xml/%s'%(image_id))
in_file = open('/home/test/darknet/VOC2020/annotations_train_xml/%s.xml'%(image_id)) ##########
#print("3-convert to txt")
out_file = open('/home/test/darknet/VOC2020/annotations_train_txt/%s.txt'%(image_id), 'w') #######
tree=ET.parse(in_file)
root = tree.getroot()
size = root.find('size')
w = int(size.find('width').text)
h = int(size.find('height').text)
for obj in root.iter('object'):
difficult = obj.find('difficult').text
cls = obj.find('name').text
if cls not in classes or int(difficult)==1:
continue
cls_id = classes.index(cls)
xmlbox = obj.find('bndbox')
b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
bb = convert((w,h), b)
out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
#print("write ok")
#wd = getcwd()
wd = " "
for image_set in sets:
image_ids = open('train_all.txt').read().strip().split() ######
# image_ids = open('%s.txt'%(image_set)).read().strip().split()
print("start ")
#list_file = open('%s.txt'%(image_set), 'w')
for image_id in image_ids:
#print("again write")
#print('image_id:%s'%image_id)
#list_file.write('%s/%s.jpg\n'%(wd, image_id))
id = image_id.split('/')[-1].replace('jpg','xml')
id =id.split('.')[0]
print('id:%s'%id)
convert_annotation(id)
#list_file.close()
<script language="javascript">
$(function (){
var i = 4;$(window).bind("scroll", function (event){
//滚动条到网页头部的 高度,兼容ie,ff,chrome
var top = document.documentElement.s
包冲突是开发过程中很常见的问题:
其表现有:
1.明明在eclipse中能够索引到某个类,运行时却报出找不到类。
2.明明在eclipse中能够索引到某个类的方法,运行时却报出找不到方法。
3.类及方法都有,以正确编译成了.class文件,在本机跑的好好的,发到测试或者正式环境就
抛如下异常:
java.lang.NoClassDefFoundError: Could not in
NAME: gpasswd - administer the /etc/group file
SYNOPSIS:
gpasswd group
gpasswd -a user group
gpasswd -d user group
gpasswd -R group
gpasswd -r group
gpasswd [-A user,...] [-M user,...] g
enquiry mysql version in centos linux
yum list installed | grep mysql
yum -y remove mysql-libs.x86_64
enquiry mysql version in yum repositoryyum list | grep mysql oryum -y list mysql*
install mysq
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.
Below is one possible representation of s1 = "great":
select p.spid,c.object_name,b.session_id,b.oracle_username,b.os_user_name from v$process p,v$session a, v$locked_object b,all_objects c where p.addr=a.paddr and a.process=b.process and c.object_id=b.