# --------------------------------------------------------
# Fast R-CNN
# Copyright (c) 2015 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Ross Girshick and Xinlei Chen
# --------------------------------------------------------
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
from datasets.imdb import imdb
import datasets.ds_utils as ds_utils
import xml.etree.ElementTree as ET
import numpy as np
import scipy.sparse
import scipy.io as sio
import utils.cython_bbox
import pickle
import subprocess
import uuid
from .voc_eval import voc_eval
from model.config import cfg
# pascal_voc继承imdb
class pascal_voc(imdb):
# image_set代表数据集名称(train,val,test...),year代表版本如2007
def __init__(self, image_set, year, use_diff=False):
name = 'voc_' + year + '_' + image_set # 例如voc_2007_train
if use_diff:
name += '_diff'
# 调用imdb的构造函数
imdb.__init__(self, name)
self._year = year
self._image_set = image_set
# /home/liubo/tf-faster-rcnn1/data/VOCdevkit2007/
self._devkit_path = self._get_default_path()
# /home/liubo/tf-faster-rcnn1/data/VOCdevkit/VOC2007/
self._data_path = os.path.join(self._devkit_path, 'VOC' + self._year)
self._classes = ('__background__', # always index 0
'tilt', 'miss', 'normal')
# _class_to_ind保存的是{'__background__' : 0 , 'tilt' : 1 , 'miss' : 2 , 'normal' : 3}
self._class_to_ind = dict(list(zip(self.classes, list(range(self.num_classes)))))
# 图片的格式
self._image_ext = '.JPG'
# 里面包含所有数据集图像的名称,如[000001,000002,000003...]
self._image_index = self._load_image_set_index()
# Default to roidb handler
# 得到roi图片信息,重载imdb中
self._roidb_handler = self.gt_roidb
# 定义一个随机的标识符
self._salt = str(uuid.uuid4()) # 4a5ae4d0-03ff-490c-871b-33b615a19bb4
self._comp_id = 'comp4'
# PASCAL specific config options
self.config = {'cleanup': True,
'use_salt': True,
'use_diff': use_diff,
'matlab_eval': False,
'rpn_file': None}
assert os.path.exists(self._devkit_path), \
'VOCdevkit path does not exist: {}'.format(self._devkit_path)
assert os.path.exists(self._data_path), \
'Path does not exist: {}'.format(self._data_path)
# 返回图片所在的路径
def image_path_at(self, i):
"""
Return the absolute path to image i in the image sequence.
"""
# /home/liubo/tf-faster-rcnn1/data/VOCdevkit/VOC2007/JPEGImages/000001.JPG
return self.image_path_from_index(self._image_index[i])
def image_path_from_index(self, index):
"""
Construct an image path from the image's "index" identifier.
"""
# _data_path = /home/liubo/tf-faster-rcnn1/data/VOCdevkit/VOC2007/
image_path = os.path.join(self._data_path, 'JPEGImages',
index + self._image_ext) # _image_ext = .JPG 后缀名
assert os.path.exists(image_path), \
'Path does not exist: {}'.format(image_path)
return image_path
# 获取图片索引
def _load_image_set_
Faster Rcnn 代码解读之 pascal_voc.py
最新推荐文章于 2022-06-07 17:57:26 发布