import os
import xml.etree.ElementTree as ETrootdir2 = r"F:\images3\xmls"
file_list = os.listdir( rootdir2)
classes_dict = { } for file_name in file_list:path = os.path.join( rootdir2, file_name) if os.path.isfile( path) :tree = ET.parse( path) root = tree.getroot( ) for obj in root.findall( 'object' ) :name = obj.find( 'name' ) .textif name not in classes_dict:classes_dict[ name] = 1 else:classes_dict[ name] += 1
for k, v in classes_dict.items( ) :print( k, v )
print( classes_dict.keys( )) print( "图片总数:" , len( file_list))
import os
import jsonrootdir2 = r"F:\images3\jsons"
file_list = os.listdir( rootdir2)
label_count = { } for file_name in file_list:path = os.path.join( rootdir2, file_name) if os.path.isfile( path) and path.endswith( '.json' ) :with open( path, 'r' , encoding = 'utf-8' ) as f:data = json.load( f) if 'shapes' in data:for shape in data[ 'shapes' ] :label = shape.get( 'label' ) if label:if label not in label_count:label_count[ label] = 1 else:label_count[ label] += 1
for k, v in label_count.items( ) :print( k, v )
print( label_count.keys( )) print( "文件总数:" , len( file_list))