加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
util-statistical_anchor_ratio.py 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
椰子奶糖 提交于 2022-03-31 10:07 . init
import numpy as np
import os
import math
dir_txt = "model/ship_gt/labels_int/"
list_txt = os.listdir(dir_txt)
# labels from float to int
# print(list_txt)
# import pdb
# pdb.set_trace()
ratio_hw = {'1':0,'2':0,'3':0,'4':0,'5':0,'6':0,'7':0,'8':0,'9':0}
ratio_wh = {'1':0,'2':0,'3':0,'4':0,'5':0,'6':0,'7':0,'8':0,'9':0}
ratio_area = [0 for i in range(20)]
# for txt in list_txt:
# # print('{}{}'.format(dir_txt,txt))
# with open('{}{}'.format(dir_txt,txt), 'r') as fr:
# line = fr.readlines()[0]
# # print(line.split(','))
# data = line.split(',')
# w = float(data[4])-float(data[0])
# h = float(data[5])-float(data[1])
# if h/w > 1:
# ratio_hw[str(int(math.floor(h/w)))]+=1
# if w/h > 1:
# ratio_wh[str(int(math.floor(w/h)))]+=1
# # print(int(w*h/1000))
# ratio_area[int(w*h/10000) if int(w*h/10000)<20 else 19 ]+=1
# import pdb
# pdb.set_trace()
print('ratio_hw')
for key in ratio_hw.keys():
print('{}:{}'.format(key,ratio_hw[key]))
print('ratio_wh')
for key in ratio_wh.keys():
print('{}:{}'.format(key,ratio_wh[key]))
print('area')
for index in range(len(ratio_area)):
print('{}:{}'.format(index,ratio_area[index]))
for txt in list_txt:
# print('{}{}'.format(dir_txt,txt))
# import pdb
# pdb.set_trace()
if txt.split('_')[0]=='DDG':
with open('{}{}'.format(dir_txt,txt), 'r') as fr:
line = fr.readlines()[0]
# print(line.split(','))
data = line.split(',')
w = float(data[4])-float(data[0])
h = float(data[5])-float(data[1])
if h/w > 1:
ratio_hw[str(int(math.floor(h/w)))]+=1
if w/h > 1:
ratio_wh[str(int(math.floor(w/h)))]+=1
# print(int(w*h/1000))
ratio_area[int(w*h/1000) if int(w*h/1000)<20 else 19 ]+=1
print('\nddg')
print('ratio_hw')
for key in ratio_hw.keys():
print('{}:{}'.format(key,ratio_hw[key]))
print('ratio_wh')
for key in ratio_wh.keys():
print('{}:{}'.format(key,ratio_wh[key]))
print('area')
for index in range(len(ratio_area)):
print('{}:{}'.format(index,ratio_area[index]))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化