1
1
2
2
/*
3
- * Company: Systhesis
3
+ * Company: Synthesis
4
4
* Author: Chen
5
5
* Date: 2018/06/04
6
6
*/
22
22
using namespace caffe ;
23
23
using namespace cv ;
24
24
25
- // YOLOV3
26
- const string& model_file = " /home/nvidia/projects/caffe-yolov3/data/networks/yolov3/yolov3.prototxt" ;
27
- const string& weights_file = " /home/nvidia/projects/caffe-yolov3/data/networks/yolov3/yolov3.caffemodel" ;
25
+ const int timeIters = 10 ;
28
26
29
- const char * imgFilename = " /home/nvidia/projects/caffe-yolov3/data/images/dog.jpg" ;
27
+ // YOLOV3
28
+ const string& model_file = " /home/chen/projects/caffe-yolov3/data/yolov3/yolov3.prototxt" ;// modify your model file path
29
+ const string& weights_file = " /home/chen/projects/caffe-yolov3/data/yolov3/yolov3.caffemodel" ;// modify your weights file path
30
+ const char * imgFilename = " /home/chen/projects/caffe-yolov3/data/images/dog.jpg" ; // modify your images file path
30
31
31
32
uint64_t current_timestamp () {
32
33
struct timeval te;
@@ -47,7 +48,7 @@ void sig_handler(int signo)
47
48
48
49
int main ( int argc, char ** argv )
49
50
{
50
- printf (" detectnet-camera \n args (%i): " , argc);
51
+ printf (" detectnet\n args (%i): " , argc);
51
52
52
53
for ( int i=0 ; i < argc; i++ )
53
54
printf (" %i [%s] " , i, argv[i]);
@@ -77,39 +78,48 @@ int main( int argc, char** argv )
77
78
78
79
int size = input_data_blobs->channels ()*input_data_blobs->width ()*input_data_blobs->height ();
79
80
80
- uint64_t beginDataTime = current_timestamp ();
81
- // load image
82
- image im = load_image_color ((char *)imgFilename,0 ,0 );
83
- image sized = letterbox_image (im,input_data_blobs->width (),input_data_blobs->height ());
84
- cuda_push_array (input_data_blobs->mutable_gpu_data (),sized.data ,size);
85
-
86
- uint64_t endDataTime = current_timestamp ();
87
-
88
- // YOLOV3 objection detection implementation with Caffe
89
- uint64_t beginDetectTime = current_timestamp ();
90
-
91
- net->Forward ();
92
-
93
- vector<Blob<float >*> blobs;
94
- blobs.clear ();
95
- Blob<float >* out_blob1 = net->output_blobs ()[1 ];
96
- blobs.push_back (out_blob1);
97
- Blob<float >* out_blob2 = net->output_blobs ()[2 ];
98
- blobs.push_back (out_blob2);
99
- Blob<float >* out_blob3 = net->output_blobs ()[0 ];
100
- blobs.push_back (out_blob3);
101
-
102
- printf (" output blob1 shape c= %d, h = %d, w = %d\n " ,out_blob1->channels (),out_blob1->height (),out_blob1->width ());
103
- printf (" output blob2 shape c= %d, h = %d, w = %d\n " ,out_blob2->channels (),out_blob2->height (),out_blob2->width ());
104
- printf (" output blob3 shape c= %d, h = %d, w = %d\n " ,out_blob3->channels (),out_blob3->height (),out_blob3->width ());
105
-
81
+ uint64_t dataTime = 0 ;
82
+ uint64_t networkTime = 0 ;
83
+ image im,sized;
106
84
int nboxes = 0 ;
107
- detection *dets = get_detections (blobs,im.w ,im.h ,&nboxes);
108
-
109
- uint64_t endDetectTime = current_timestamp ();
110
- printf (" object-detection: finished processing data operation (%zu)ms\n " , endDataTime - beginDataTime);
111
- printf (" object-detection: finished processing yolov3 network (%zu)ms\n " , endDetectTime - beginDetectTime);
112
-
85
+ detection *dets = NULL ;
86
+ for (int i=0 ;i<timeIters;++i){
87
+ uint64_t beginDataTime = current_timestamp ();
88
+ // load image
89
+ im = load_image_color ((char *)imgFilename,0 ,0 );
90
+ sized = letterbox_image (im,input_data_blobs->width (),input_data_blobs->height ());
91
+ cuda_push_array (input_data_blobs->mutable_gpu_data (),sized.data ,size);
92
+
93
+ uint64_t endDataTime = current_timestamp ();
94
+ dataTime += (endDataTime - beginDataTime);
95
+
96
+ // YOLOV3 objection detection implementation with Caffe
97
+
98
+ net->Forward ();
99
+
100
+ vector<Blob<float >*> blobs;
101
+ blobs.clear ();
102
+ Blob<float >* out_blob1 = net->output_blobs ()[1 ];
103
+ blobs.push_back (out_blob1);
104
+ Blob<float >* out_blob2 = net->output_blobs ()[2 ];
105
+ blobs.push_back (out_blob2);
106
+ Blob<float >* out_blob3 = net->output_blobs ()[0 ];
107
+ blobs.push_back (out_blob3);
108
+
109
+ // printf("output blob1 shape c= %d, h = %d, w = %d\n",out_blob1->channels(),out_blob1->height(),out_blob1->width());
110
+ // printf("output blob2 shape c= %d, h = %d, w = %d\n",out_blob2->channels(),out_blob2->height(),out_blob2->width());
111
+ // printf("output blob3 shape c= %d, h = %d, w = %d\n",out_blob3->channels(),out_blob3->height(),out_blob3->width());
112
+
113
+ // int nboxes = 0;
114
+ // printf("img width =%d, height = %d\n",im.w,im.h);
115
+ dets = get_detections (blobs,im.w ,im.h ,&nboxes);
116
+
117
+ uint64_t endDetectTime = current_timestamp ();
118
+ networkTime += (endDetectTime - endDataTime);
119
+ }
120
+
121
+ printf (" object-detection: total iters = %d done, processing data operation avergae time is (%zu)ms\n " , timeIters,dataTime/timeIters);
122
+ printf (" object-detection: total iters = %d done, processing network yolov3 avergae time is (%zu)ms\n " , timeIters,networkTime/timeIters);
113
123
114
124
// show detection results
115
125
Mat img = imread (imgFilename);
0 commit comments