lib\model\test.py里主要是test_net.py,用于faster测试的时候调用模型进行测试,并对结果进行保存。在tools/test_net.py里被调用。函数相对简单,但确实是测试时的整个流程了。基本每一句都写得很清楚了。
# --------------------------------------------------------
# Tensorflow Faster R-CNN
# Licensed under The MIT License [see LICENSE for details]
# Written by Xinlei Chen
#解析:nansbas
# --------------------------------------------------------
#-*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import cv2
import numpy as np
try:
import cPickle as pickle
except ImportError:
import pickle
import os
import math
from utils.timer import Timer
from utils.blob import im_list_to_blob
from model.config import cfg, get_output_dir
from model.bbox_transform import clip_boxes, bbox_transform_inv
from model.nms_wrapper import nms
def _get_image_blob(im):
"""Converts an image into a network input.
Arguments:
im (ndarray): a color image in BGR order
Returns:
blob (ndarray): a data blob holding an image pyramid
im_scale_factors (list): list of image scales (relative to im) used
in the image pyramid
"""
#图像转换为float32。注意是bgr顺序,不是rgb顺序
im_orig = im.astype(np.float32, copy=True)
#原始图像减去均值。均值影响的是收敛速度,其实差不多在一个范围内就行。
im_orig -= cfg.PIXEL_MEANS
#提取最大、最小边
im_shape = im_orig.shape
im_size_min = np.min(im_shape[0:2])
im_size_max = np.max(im_shape[0:2])
#张开保存处理结果的张亮
processed_ims = []
#初始化尺度因子
im_scale_factors = []
#cfg.TEST.SCALES=600
for target_size in cfg.TEST.SCALES:
im_scale = float(target_size) / float(im_size_min)
#