测试tensforflow的pb格式模型

主要是用来测试Vitis-AI量化前后的pb模型的mAP的,以此来预估量化损失
核心代码在https://github.com/Xilinx/Vitis-AI-Tutorials/tree/1.2/Design_Tutorials/07-ml-edge-YOLOv3/files/core可以找到
但我不知道如何准备测试所需的文件和格式,所以我会写下我自己的准备过程。

[En]

But I don’t know how to prepare the files and formats needed for testing, so I’ll write down my own preparation process.

1 准备一些测试图片放到一个文件夹里,使用下面的代码提取出图片名

import os
path_imgs = './test_dir/'
for files in os.listdir(path_imgs):
    print(files)
    img_path = path_imgs+ files
    with open("test_dir.txt", "a") as f:
        f.write(str(img_path) + '\n')

将图片名写在test_dir.txt里面

2 运行tf_prediction.py得到检测结果

这里需要用到pb文件权重(我的博客写了如何获取pb模型)和上一步得到的test_dir.txt,将检测结果写在detec_result.txt文件中。得到的结果是这样的

测试tensforflow的pb格式模型
; 3 获取map

这里麻烦的是需要按照代码来准备需要的格式文件,上一步可以看出detec_result.txt内容格式为

image_name class_label score xmin ymin xmax ymax

我们要自己准备一个如下格式的groundtruth.txt的文本

image_name class_label xmin ymin xmax ymax

voc数据集的groundtruth内容是这样的

测试tensforflow的pb格式模型
所以说只需要将image_name 与这些内容对应就好了,我写了一个脚本(写的很烂,好在功能可以实现)
import os
def hebing():
    path_imgs = './img/'
    groundtruth = r'input/ground-truth'
    list2 = []
    for i in os.listdir(path_imgs):
        list2.append(i.split('.')[0])
    num = 0
    for i in list2:
        for filename in os.listdir(groundtruth ):

            path = os.path.join(groundtruth , filename)
            f = open(path, 'r')
            lines = f.readlines()
            for k in lines:
                img_path = list2[num] + ' ' + k
                print(img_path)
                with open("test_dir.txt", "a") as f:
                    f.write(str(img_path))
            num = num + 1
            continue
        continue

hebing()

运行之后,我们得到了这样的结果。

[En]

After running it, we get such a result.

测试tensforflow的pb格式模型
4 最后只需要运行evaluation.py就好了

结果是这样的

测试tensforflow的pb格式模型
这个权重是我随便训练了十几轮的结果,图片我也只取了前200张,所以mAP比较低。

Original: https://blog.csdn.net/weixin_43850171/article/details/123223547
Author: 折磨王
Title: 测试tensforflow的pb格式模型

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/509065/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球