Tensorflow-Faster代码解析: test.py

test.py 文件位于 libmodel 目录下,主要包含 test_net.py 函数,该函数在测试 Faster 模型时被 tools/test_net.py 调用。此文件负责调用模型并保存测试结果,其内部逻辑清晰,每一步操作都有详细注释。
摘要由CSDN通过智能技术生成

 

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)
    # 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
没有GPU,优化程序class point_cloud_generator(): def init(self, rgb_file, depth_file, save_ply, camera_intrinsics=[312.486, 243.928, 382.363, 382.363]): self.rgb_file = rgb_file self.depth_file = depth_file self.save_ply = save_ply self.rgb = cv2.imread(rgb_file) self.depth = cv2.imread(self.depth_file, -1) print("your depth image shape is:", self.depth.shape) self.width = self.rgb.shape[1] self.height = self.rgb.shape[0] self.camera_intrinsics = camera_intrinsics self.depth_scale = 1000 def compute(self): t1 = time.time() depth = np.asarray(self.depth, dtype=np.uint16).T self.Z = depth / self.depth_scale fx, fy, cx, cy = self.camera_intrinsics X = np.zeros((self.width, self.height)) Y = np.zeros((self.width, self.height)) for i in range(self.width): X[i, :] = np.full(X.shape[1], i) self.X = ((X - cx / 2) * self.Z) / fx for i in range(self.height): Y[:, i] = np.full(Y.shape[0], i) self.Y = ((Y - cy / 2) * self.Z) / fy data_ply = np.zeros((6, self.width * self.height)) data_ply[0] = self.X.T.reshape(-1)[:self.width * self.height] data_ply[1] = -self.Y.T.reshape(-1)[:self.width * self.height] data_ply[2] = -self.Z.T.reshape(-1)[:self.width * self.height] img = np.array(self.rgb, dtype=np.uint8) data_ply[3] = img[:, :, 0:1].reshape(-1)[:self.width * self.height] data_ply[4] = img[:, :, 1:2].reshape(-1)[:self.width * self.height] data_ply[5] = img[:, :, 2:3].reshape(-1)[:self.width * self.height] self.data_ply = data_ply t2 = time.time() print('calcualte 3d point cloud Done.', t2 - t1) def write_ply(self): start = time.time() float_formatter = lambda x: "%.4f" % x points = [] for i in self.data_ply
05-24
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值