Home > other >  Kitti convert voc format, is always an error AttributeError: 'NoneType' object has no attr
Kitti convert voc format, is always an error AttributeError: 'NoneType' object has no attr

Time:10-05

Kitti convert voc format, is always an error AttributeError: 'NoneType' object has no attribute 'shape, to be crazy, trouble to help have a look, thank you! :



-- -- -- -- -- - utils. P y -- -- -- -- -- --
The import OS, cv2, sys, shutil

The from XML, dom minidom import Document

Def writexml (filename, saveimg bboxes, xmlpath, typename) :
Doc=Document ()

The annotation=doc. The createElement method (' annotation)

Doc. The appendChild (annotations)

Folder=doc. The createElement method (' folder ')

Kitti folder_name=doc. CreateTextNode (' ')
Folder. The appendChild (folder_name)
The annotation. The appendChild (folder)
Filenamenode=doc. The createElement method (' filename ')
Filename_name=doc. CreateTextNode (filename)
Filenamenode. The appendChild (filename_name)
The annotation. The appendChild (filenamenode)
Source=doc. The createElement method (' source ')
The annotation. The appendChild (source)
The database=doc. The createElement method (' database ')
The database. The appendChild (doc. CreateTextNode (' kitti database '))
Source. The appendChild (database)
Annotation_s=doc. The createElement method (' annotation)
Annotation_s. The appendChild (doc. CreateTextNode (' kitti))
Source. The appendChild (annotation_s)
Image=doc. The createElement method (' image ')
Image. The appendChild (doc. CreateTextNode (' flickr))
Source. The appendChild (image)
Flickrid=doc. The createElement method (' flickrid)
Flickrid. The appendChild (doc. CreateTextNode (' 1 '))
Source. The appendChild (flickrid)
The owner=doc. The createElement method (" owner ")
The annotation. The appendChild (the owner)
Flickrid_o=doc. The createElement method (' flickrid)
Flickrid_o. The appendChild (doc. CreateTextNode (' muke))
Owner. The appendChild (flickrid_o)
Name_o=doc. The createElement method (' name ')
Name_o. The appendChild (doc. CreateTextNode (' muke))
Owner. The appendChild (name_o)

Size=doc. The createElement method (' size ')
The annotation. The appendChild (size)

Width=doc. The createElement method (' width ')
Width. The appendChild (doc. CreateTextNode (STR (saveimg. Shape [1])))
Height=doc. The createElement method (' height ')
Height. The appendChild (doc. CreateTextNode (STR (saveimg. Shape [0])))
The depth=doc. The createElement method (' the depth)
The depth. The appendChild (doc. CreateTextNode (STR (saveimg. Shape [2])))

Size. The appendChild (width)

Size. The appendChild (height)
Size. The appendChild (the depth)
Segmented=doc. The createElement method (' segmented)
Segmented. The appendChild (doc. CreateTextNode (' 0 '))
The annotation. The appendChild (segmented)
For I in range (len (bboxes) :
Bbox=bboxes [I]
Objects=doc. The createElement method (' object ')
The annotation. The appendChild (objects)
Object_name=doc. The createElement method (' name ')
Object_name. The appendChild (doc. CreateTextNode (typename [I]))
Objects. The appendChild (object_name)
Pose=doc. The createElement method (' pose ')
Pose. The appendChild (doc. CreateTextNode (' Unspecified '))
Objects. The appendChild (pose)
Truncated=doc. The createElement method (' truncated)
Truncated. The appendChild (doc. CreateTextNode (' 1 '))
Objects. The appendChild (truncated)
About=doc. The createElement method (' about ')
About the appendChild (doc. CreateTextNode (' 0 '))
Objects. The appendChild (about)
Bndbox=doc. The createElement method (' bndbox)
Objects. The appendChild (bndbox)
Xmin=doc. The createElement method (' xmin)
Xmin. The appendChild (doc. CreateTextNode (STR (bbox [0])))
Bndbox. The appendChild (xmin)
Ymin=doc. The createElement method (' ymin)
Ymin. The appendChild (doc. CreateTextNode (STR (bbox [1])))
Bndbox. The appendChild (ymin)
Xmax=doc. The createElement method (' xmax)
Xmax. The appendChild (doc. CreateTextNode (STR (bbox [2])))
Bndbox. The appendChild (xmax)
Ymax=doc. The createElement method (' ymax)
Ymax. The appendChild (doc. CreateTextNode (STR (bbox [3])))
Bndbox. The appendChild (ymax)
F=open (xmlpath, "w")
F.w rite (doc. Toprettyxml (indent="))
F. lose ()

-- -- -- -- -- -- -- the demo. P y -- -- -- -- -- -- --
The import cv2
The import glob
The from fasterrcnn_kitti. Utils import writexml

Trainval=open (" F:/Database/kitti/ImageSets/Main/trainval. TXT ", "w")
"Train"=open (" F:/Database/kitti/ImageSets/Main/" train ". TXT ", "w")
Val=open (" F:/Database/kitti/ImageSets/Main/val. TXT ", "w")
Test=open (" F:/Database/kitti/ImageSets/Main/test. TXT ", "w")

List_anno_files=glob. Glob (" F: Database/kitti/training/label_2/* ")

Independence idx=0
For file_path list_anno_files in:
With the open (file_path) as file:
Anno_infos=file. Readlines ()

Print (anno_infos)

Bboxes=[]
Typename=[]
For anno_item anno_infos in:

Anno_infos=anno_item. Split (" ")

If anno_infos [0]=="Misc" or anno_infos [1]=="DontCare" :
The continue
The else:
Bbox=(int (float (anno_infos [4])), int, float (anno_infos [5])),
Int (float (anno_infos [6]), int, float (anno_infos [7])))

Bboxes. Append (bbox) # bboxes is the coordinates of boundary box
Typename. Append (anno_infos [0]) # typename is category name

Filename=file_path. Split ("/") [1]. The replace (" TXT ", "PNG") # filename is the name of the picture
Xmlpath="F:/Database/kitti/Annotations/" + filename. Replace (" PNG" and "XML")

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related