使用faster rcnn 跑vot2015的数据集

本周老师给的任务:

一是将VOT15数据集(世华已传到服务器上)上每个序列的第1,11,21,31,41帧分别运行Faster R-CNN检测器并保存在图片上显示的检测结果;

二是将这5帧的ground truth bounding box作为proposal得到其对应的检测器分类结果(比如网络要检测20类物体,那包括背景就是得到21类对应的检测分数值),并将每个序列的检测结果分别存成一个文本文档。

 注意,使用代码的时候,可能会有路径错误,还可能是,我贴上的代码,博客园的网站给在某些语句后加了 <br> ,调错的时候细看!!我在后台竟然看不到<br>,但是浏览的时候却有!!

第一个问题已经解决,现在整理一下思路。

先将py faster rcnn 装好之后,测试运行dome.py能成功展示之后,再进行接下来的工作。

我的想法是,

(1)将vot2015数据集上的所有数据的分类统计出来(就是把vot2015下的子文件夹的名称统计出来,方便之后操作),这里直接用了( http://www.cnblogs.com/flyhigh1860/p/3896111.html )的源码进行修改

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
# -*- coding:utf8 -*-
 
import os
allFileNum = 0
 
def printPath(level, path):
    global allFileNum
    '''''
    打印一个目录下的所有文件夹和文件
    '''
    # 所有文件夹,第一个字段是次目录的级别
    dirList = []
    # 所有文件
    fileList = []
    # 返回一个列表,其中包含在目录条目的名称(google翻译)
    files = os.listdir(path)
    # 先添加目录级别
    dirList.append(str(level))
    for f in files:
        if (os.path.isdir(path + '/' + f)):
            # 排除隐藏文件夹。因为隐藏文件夹过多
            if (f[0] == '.'):
                pass
            else:
                # 添加非隐藏文件夹
                dirList.append(f)
        if (os.path.isfile(path + '/' + f)):
            # 添加文件
            fileList.append(f)
            # 当一个标志使用,文件夹列表第一个级别不打印
    i_dl = 0<br>  #得到的文件夹名保存在 save_file.txt 中,使用python的追加操作 ‘a’
    save_file = open('/home/user/Downloads/save_file.txt','a')
    for dl in dirList:
        if (i_dl == 0):
            i_dl = i_dl + 1
        else:
            # 打印至控制台,不是第一个的目录
            print '-' * (int(dirList[0])), dl<br>       #将文件名写入save_file.txt中
            save_file.write(dl)
            save_file.write('\n')
            # 打印目录下的所有文件夹和文件,目录级别+1
            #printPath((int(dirList[0]) + 1), path + '/' + dl)
    for fl in fileList:
        # 打印文件
        print '-' * (int(dirList[0])), fl
        # 随便计算一下有多少个文件
        allFileNum = allFileNum + 1
 
if __name__ == '__main__':
    printPath(1, '/home/user/Downloads/vot2015')
    print '总文件数 =', allFileNum

 这里再给出save_file.txt 文件内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
soldier
butterfly
hand
car2
sheep
birds1
motocross1
marching
book
road
graduate
fish3
fernando
bag
wiper
gymnastics2
leaves
ball1
birds2
crossing
soccer1
godfather
nature
racing
traffic
pedestrian2
handball2
ball2
gymnastics1
singer2
singer1
dinosaur
gymnastics3
bolt1
gymnastics4
pedestrian1
helicopter
singer3
matrix
octopus
iceskater1
fish4
sphere
car1
motocross2
girl
fish1
bolt2
basketball
blanket
bmx
shaking
tiger
handball1
rabbit
fish2
tunnel
glove
iceskater2
soccer2

 

 

 (2)从save_file.txt 中将分来读取出来,保存再一个list中,之后将这段代码加到 demo.py 中使用(参考了  http://www.cnblogs.com/xuxn/archive/2011/07/27/read-a-file-with-python.html     和    http://www.cnblogs.com/mxh1099/p/5680001.html)

1
2
3
4
5
6
7
8
9
10
11
12
13
l = []
 
file = open('/home/user/Downloads/save_file.txt')
 
while 1:
    line = file.readline()
    if line != '\n':
        print line.replace("\n", "")<br>     #在list中 加入去掉换行符的文件名
        l.append(line.replace("\n",""))
    if not line:
        break
 
print l

 

 (3)需要将文件名和要遍历的每个文件夹下的文件名配合,同样,这段代码之后会用在demo.py 中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
lfile = []
 
file = open('/home/user/Downloads/save_file.txt')
 
while 1:
    line = file.readline()
    if line != '\n':
        lfile.append(line.replace("\n", ""))
    if not line:
        break
im_names =['00000023.jpg','00000011.jpg','00000001.jpg']
    # im_names = ['00000001.jpg', '000000011.jpg', '00000021.jpg',
    #             '00000031.jpg', '00000041.jpg']
 
for litme in lfile :
    for im_name in im_names:
        im_path = str(litme) + '/' + str(im_name)
        print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
        #print 'Demo for data/demo/{}'.format(im_name)
        print im_path

 (4)可以对文件遍历之后,需要将生成的图片结果保存下来,参考了《演示如何实现Matplotlib绘图并保存图像但不显示图形的方法》(http://blog.csdn.net/rumswell/article/details/7342479) 和Python创建目录文件夹 (http://www.cnblogs.com/monsteryang/p/6574550.html)

 

最后附上我修改之后的demo.py

 

第二个问题先看着,没想法

 在图片上显示每个IOU大于0.5的proposal对应的最高检测值的类别、分数和回归后的框,在文本文档里则保存每个proposal对应的21个类别的检测分数和回归后的边界框坐标。

对于每个类别,总会生成300个proposals,

所以,在每个proposal,都会有4个坐标

对于每个proposal,都会有一个类别值。

因为要生成每个proposal对应的21个类别的分数,就需要将分数先保存起来,再输出

还要记录回归后的边间框。

 

对于图片,显示每个IOU大于0.5的proposal对应的最高检测值的类别、分数和回归后的框。

也是先要将最高检测分数对应的类别和回归框记录下来。

posted @   unicoe  阅读(1643)  评论(0编辑  收藏  举报
编辑推荐:
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
阅读排行:
· AI Agent爆火后,MCP协议为什么如此重要!
· dotnet 源代码生成器分析器入门
· Draw.io:你可能不知道的「白嫖级」图表绘制神器
· ASP.NET Core 模型验证消息的本地化新姿势
· 从零开始:基于 PyTorch 的图像分类模型
历史上的今天:
2014-11-03 Poj1328-Radar Installation
点击右上角即可分享
微信分享提示