Tensorflow yolov3 Intel Realsense D435 单摄像头下各模块识别时间测试
生活随笔
收集整理的這篇文章主要介紹了
Tensorflow yolov3 Intel Realsense D435 单摄像头下各模块识别时间测试
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
文章目錄
- 1、一次循環(huán)總耗時
- 2、從循環(huán)開始到self.predict()之前
- 3、第一次循環(huán)主要耗時函數(shù):wait_for_frames()(其實self.predict()函數(shù)在第一次循環(huán)更耗時)
- 4、self.predict()函數(shù)
- 5、utils.draw_bbox()函數(shù)
- 測試代碼
1、一次循環(huán)總耗時
2、從循環(huán)開始到self.predict()之前
3、第一次循環(huán)主要耗時函數(shù):wait_for_frames()(其實self.predict()函數(shù)在第一次循環(huán)更耗時)
經(jīng)過排查,發(fā)現(xiàn)運行第一次循環(huán)時的主要耗時為wait_for_frames()函數(shù)
4、self.predict()函數(shù)
耗時:2.5726187229156494秒 耗時:0.07996416091918945秒 耗時:0.07428789138793945秒 耗時:0.0805974006652832秒 耗時:0.07904219627380371秒 耗時:0.06201648712158203秒 耗時:0.06962394714355469秒 耗時:0.08076310157775879秒 耗時:0.06206536293029785秒 耗時:0.06133413314819336秒 耗時:0.07121872901916504秒 耗時:0.05918383598327637秒 耗時:0.059471845626831055秒 耗時:0.059415578842163086秒 耗時:0.06809067726135254秒 耗時:0.06953263282775879秒 耗時:0.0625460147857666秒 耗時:0.0598294734954834秒 耗時:0.07292938232421875秒 耗時:0.06318020820617676秒 耗時:0.0830841064453125秒 耗時:0.07958698272705078秒5、utils.draw_bbox()函數(shù)
耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0009729862213134766秒 耗時:0.0005013942718505859秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0秒 耗時:0.0005011558532714844秒測試代碼
# -*- coding: utf-8 -*- """ @File : test-191204-單攝像頭耗時測試.py @Time : 2019/12/4 11:54 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """import cv2 import numpy as np import tensorflow as tf import core.utils as utils from core.config import cfg from core.yolov3 import YOLOV3 import pyrealsense2 as rs import time import dontla_package.dontla_ThreadClass as dtclass YoloTest(object):def __init__(self):# D·C 191111:__C.TEST.INPUT_SIZE = 544self.input_size = cfg.TEST.INPUT_SIZEself.anchor_per_scale = cfg.YOLO.ANCHOR_PER_SCALE# Dontla 191106注釋:初始化class.names文件的字典信息屬性self.classes = utils.read_class_names(cfg.YOLO.CLASSES)# D·C 191115:類數(shù)量屬性self.num_classes = len(self.classes)self.anchors = np.array(utils.get_anchors(cfg.YOLO.ANCHORS))# D·C 191111:__C.TEST.SCORE_THRESHOLD = 0.3self.score_threshold = cfg.TEST.SCORE_THRESHOLD# D·C 191120:__C.TEST.IOU_THRESHOLD = 0.45self.iou_threshold = cfg.TEST.IOU_THRESHOLDself.moving_ave_decay = cfg.YOLO.MOVING_AVE_DECAY# D·C 191120:__C.TEST.ANNOT_PATH = "./data/dataset/Dontla/20191023_Artificial_Flower/test.txt"self.annotation_path = cfg.TEST.ANNOT_PATH# D·C 191120:__C.TEST.WEIGHT_FILE = "./checkpoint/f_g_c_weights_files/yolov3_test_loss=15.8845.ckpt-47"self.weight_file = cfg.TEST.WEIGHT_FILE# D·C 191115:可寫標(biāo)記(bool類型值)self.write_image = cfg.TEST.WRITE_IMAGE# D·C 191115:__C.TEST.WRITE_IMAGE_PATH = "./data/detection/"(識別圖片畫框并標(biāo)注文本后寫入的圖片路徑)self.write_image_path = cfg.TEST.WRITE_IMAGE_PATH# D·C 191116:TEST.SHOW_LABEL設(shè)置為Trueself.show_label = cfg.TEST.SHOW_LABEL# D·C 191120:創(chuàng)建命名空間“input”with tf.name_scope('input'):# D·C 191120:建立變量(創(chuàng)建占位符開辟內(nèi)存空間)self.input_data = tf.placeholder(dtype=tf.float32, name='input_data')self.trainable = tf.placeholder(dtype=tf.bool, name='trainable')model = YOLOV3(self.input_data, self.trainable)self.pred_sbbox, self.pred_mbbox, self.pred_lbbox = model.pred_sbbox, model.pred_mbbox, model.pred_lbbox# D·C 191120:創(chuàng)建命名空間“指數(shù)滑動平均”with tf.name_scope('ema'):ema_obj = tf.train.ExponentialMovingAverage(self.moving_ave_decay)# D·C 191120:在允許軟設(shè)備放置的會話中啟動圖形并記錄放置決策。(不懂啥意思。。。)allow_soft_placement=True表示允許tf自動選擇可用的GPU和CPUself.sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True))# D·C 191120:variables_to_restore()用于加載模型計算滑動平均值時將影子變量直接映射到變量本身self.saver = tf.train.Saver(ema_obj.variables_to_restore())# D·C 191120:用于下次訓(xùn)練時恢復(fù)模型self.saver.restore(self.sess, self.weight_file)def predict(self, image):# D·C 191107:復(fù)制一份圖片的鏡像,避免對圖片直接操作改變圖片的內(nèi)在屬性org_image = np.copy(image)# D·C 191107:獲取圖片尺寸org_h, org_w, _ = org_image.shape# D·C 191108:該函數(shù)將源圖結(jié)合input_size,將其轉(zhuǎn)換成預(yù)投喂的方形圖像(作者默認(rèn)544×544,中間為縮小尺寸的源圖,上下空區(qū)域為灰圖):image_data = utils.image_preprocess(image, [self.input_size, self.input_size])# D·C 191108:打印維度看看:# print(image_data.shape)# (544, 544, 3)# D·C 191108:創(chuàng)建新軸,不懂要創(chuàng)建新軸干嘛?image_data = image_data[np.newaxis, ...]# D·C 191108:打印維度看看:# print(image_data.shape)# (1, 544, 544, 3)# D·C 191110:三個box可能存放了預(yù)測框圖(可能是N多的框,有用的沒用的重疊的都在里面)的信息(但是打印出來的值完全看不懂啊喂?)pred_sbbox, pred_mbbox, pred_lbbox = self.sess.run([self.pred_sbbox, self.pred_mbbox, self.pred_lbbox],feed_dict={self.input_data: image_data,self.trainable: False})# D·C 191110:打印三個box的類型、形狀和值看看:# print(type(pred_sbbox))# print(type(pred_mbbox))# print(type(pred_lbbox))# 都是<class 'numpy.ndarray'># print(pred_sbbox.shape)# print(pred_mbbox.shape)# print(pred_lbbox.shape)# (1, 68, 68, 3, 6)# (1, 34, 34, 3, 6)# (1, 17, 17, 3, 6)# print(pred_sbbox)# print(pred_mbbox)# print(pred_lbbox)# D·C 191110:(-1,6)表示不知道有多少行,反正你給我整成6列,然后concatenate又把它們仨給疊起來,最終得到無數(shù)個6列數(shù)組(后面self.num_classes)個數(shù)存放的貌似是這個框?qū)儆陬惖母怕?#xff09;pred_bbox = np.concatenate([np.reshape(pred_sbbox, (-1, 5 + self.num_classes)),np.reshape(pred_mbbox, (-1, 5 + self.num_classes)),np.reshape(pred_lbbox, (-1, 5 + self.num_classes))], axis=0)# D·C 191111:打印pred_bbox和它的維度看看:# print(pred_bbox)# print(pred_bbox.shape)# (18207, 6)# D·C 191111:猜測是第一道過濾,過濾掉score_threshold以下的圖片,過濾完之后少了好多:# D·C 191115:bboxes維度為[n,6],前四列是坐標(biāo),第五列是得分,第六列是對應(yīng)類下標(biāo)bboxes = utils.postprocess_boxes(pred_bbox, (org_h, org_w), self.input_size, self.score_threshold)# D·C 191111:猜測是第二道過濾,過濾掉iou_threshold以下的圖片:bboxes = utils.nms(bboxes, self.iou_threshold)return bboxesdef dontla_evaluate_detect(self):ctx = rs.context()pipeline1 = rs.pipeline(ctx)config1 = rs.config()# 通過程序去獲取已連接攝像頭序列號serial1 = ctx.devices[0].get_info(rs.camera_info.serial_number)config1.enable_device(serial1)config1.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)config1.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)pipeline1.start(config1)# 創(chuàng)建對齊對象(深度對齊顏色)align1 = rs.align(rs.stream.color)try:while True:begin_time = time.time()frames1 = pipeline1.wait_for_frames()end_time = time.time()t = end_time - begin_timeprint('耗時:{}秒'.format(t))# 獲取對齊幀集aligned_frames1 = align1.process(frames1)# 獲取對齊后的深度幀和彩色幀aligned_depth_frame1 = aligned_frames1.get_depth_frame()color_frame1 = aligned_frames1.get_color_frame()# 獲取顏色幀內(nèi)參color_profile1 = color_frame1.get_profile()cvsprofile1 = rs.video_stream_profile(color_profile1)color_intrin1 = cvsprofile1.get_intrinsics()color_intrin_part1 = [color_intrin1.ppx, color_intrin1.ppy, color_intrin1.fx, color_intrin1.fy]# if not aligned_depth_frame1 or not color_frame1:# continue# if not aligned_depth_frame2 or not color_frame2:# continuecolor_image1 = np.asanyarray(color_frame1.get_data())# D·C 191121:顯示幀看看# cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)# cv2.imshow('RealSense', color_frame)# cv2.waitKey(1)bboxes_pr1 = self.predict(color_image1)image1 = utils.draw_bbox(color_image1, bboxes_pr1, aligned_depth_frame1, color_intrin_part1,show_label=self.show_label)# cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)cv2.imshow('window1', image1)cv2.waitKey(1)finally:pipeline1.stop()if __name__ == '__main__':YoloTest().dontla_evaluate_detect()總結(jié)
以上是生活随笔為你收集整理的Tensorflow yolov3 Intel Realsense D435 单摄像头下各模块识别时间测试的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python pkl是什么类型的文件?怎
- 下一篇: python多线程为啥是假的?(GIL