mmclassification中test.py指标打印到excel

mmclassification中test.py指标打印到excel

import xlwings as xw
import math
import matplotlib.pyplot as plt
#matplotlib画图中中文显示会有问题,需要这两行设置默认字体
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False

1,图片文件名写入excel
G:\mmlab_code_20221103\mmclassification-master\mmcls\datasets\my_filelist.py

with open(self.ann_file) as f:
    samples = [x.strip().split(' ') for x in f.readlines()]
    p = 0
    for filename, gt_label in samples:
    info = {'img_prefix': self.data_prefix}
    info['img_info'] = {'filename': filename}
    
  	# qcy20221201
	wb = xw.Book('G:\mmlab_code_20221103\mmclassification-master\mmcls\datasets\melon_class_result.xlsx')
	sht = wb.sheets[0]
	sht.range('A1').value = 'filename'  # 向A1单元格写入该行数据lable
	# sht.range('A2').options(transpose=True).value = samples[0][0]  # 从A2单元格开始存入gt_labels第0列
	sht.range(p + 2, 1).options(transpose=True).value = samples[p][0]
	p += 1

2,分类标签,预测为两个类别的概率值写入excel
G:\mmlab_code_20221103\mmclassification-master\mmcls\datasets\base_dataset.py

else:
    eval_results.update(
    {k: v.item()
    for k, v in eval_results_.items()})
    
# qcy20221201
app = xw.App(visible=False, add_book=False)
wb = xw.Book('G:\mmlab_code_20221103\mmclassification-master\mmcls\datasets\melon_class_result.xlsx')
sht = wb.sheets[0]
sht.range('B1').value = 'gt_label'  # 向B1单元格写入该行数据lable
sht.range('B2').options(transpose=True).value = gt_labels  # 从A2单元格开始存入gt_labels第0列
sht.range('D1').value = 'class_1'  # 向D1单元格写入该行数据lable
sht.range('D2').options(transpose=True).value = results[:,0]  # 从D2单元格开始存入results第0列
sht.range('E1').value = 'class_2'  # 向C1单元格写入该行数据lable
sht.range('E2').options(transpose=True).value = results[:,1]  # 从E2单元格开始存入results第1

3,预测标签写入excel
G:\mmlab_code_20221103\mmclassification-master\mmcls\core\evaluation\eval_metrics.py

num_classes = pred.size(1)
pred_score, pred_label = torch.topk(pred, k=1)
pred_score = pred_score.flatten()
pred_label = pred_label.flatten()

# qcy20221201
wb = xw.Book('G:\mmlab_code_20221103\mmclassification-master\mmcls\datasets\melon_class_result.xlsx')
sht = wb.sheets[0]
sht.range('C1').value = 'pred_label1'  # 向C1单元格写入该行数据lable
sht.range('C2').options(transpose=True).value = pred_label1  # 从C2单元格开始存入gt_labels第0

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值