标签结果输出(自用)

这是写

import os
with open(os.path.join(self.args.cwd,'data/txt/result.txt'), 'w', encoding="utf-8") as wf:
    wf.write(sk_result)
    print('Successful write!!')

my_dict = dict(zip(imgids, pred_labels))

#打印结果
with open(os.path.join(self.args.cwd,"实验结果_HVP.txt" ),"w", encoding="utf-8" )as file:
    # 遍历实验结果字典
    for name, result in my_dict.items():
        # 将名称和数字写入文件,每个结果占一行
        file.write(f"{name}: {result}\n")
    print('2222Successful write!!')

my_dict = dict(zip(imgids, true_labels))
#打印结果
with open(os.path.join(self.args.cwd,"实验结果zhen.txt" ),"w", encoding="utf-8" )as file:
    # 遍历实验结果字典
    for name, result in my_dict.items():
        # 将名称和数字写入文件,每个结果占一行
        file.write(f"{name}: {result}\n")
    print('2222Successful write!!')

这是读

with open("实验结果.txt", "r") as file:
    # 定义一个空列表来存储数值
    values = []
    names=[]
    # 逐行读取文件内容
    for line in file:
        # 使用split()函数分割每一行内容,得到名称和数字
        name, result = line.strip().split(":")
        # 将数字转换为整数类型
        result = int(result)
        name=str(name)
        # 将数值添加到列表中
        values.append(result)
        names.append(name)
# 打印存储的数值列表
with open("实验结果zhen.txt", "r") as file:
    # 定义一个空列表来存储数值
    values2 = []
    names2=[]
    # 逐行读取文件内容
    for line in file:
        # 使用split()函数分割每一行内容,得到名称和数字
        name, result = line.strip().split(":")
        # 将数字转换为整数类型
        result = int(result)
        name=str(name)
        # 将数值添加到列表中
        values2.append(result)
        names2.append(name)

#
# 遍历两个列表,比较文本和数值
for i in range(len(names)):
    for j in range(len(names2)):
        if names[i] == names2[j]:  # 这里只以'实验1'为例,您可以根据需要修改或删除此条件
                if values[i] != values2[j]:
                    print(names[i])
                    with open("不一致1.txt", "a") as file:# 这里只以比较数值大小为例,您可以根据需要修改操作
                        file.write(f"{names[i]}:{values[i]}\n")
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值