MCPcopy Create free account
hub / github.com/CMU-Perceptual-Computing-Lab/openpose / clTest

Function clTest

examples/tests/clTest.cpp:93–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91 );
92
93int clTest()
94{
95 try
96 {
97 // logging_level
98 cv::Mat img = cv::imread(FLAGS_image_path);
99 if(img.empty())
100 op::error("Could not open or find the image: " + FLAGS_image_path, __LINE__, __FUNCTION__, __FILE__);
101 cv::Mat imgResize; cv::resize(img, imgResize, cv::Size(368,368));
102 cv::Mat imgFloat; imgResize.convertTo(imgFloat, CV_32FC3);
103 imgFloat /= 255.;
104 int imageVolume = imgFloat.size().width * imgFloat.size().height * imgFloat.channels();
105 std::cout << imgFloat.channels() << std::endl;
106
107 // Setup caffe
108 caffe::Caffe::set_mode(caffe::Caffe::GPU);
109 std::vector<int> devices;
110 const int maxNumberGpu = op::OpenCL::getTotalGPU();
111 for (auto i = 0; i < maxNumberGpu; i++){
112 devices.emplace_back(i);
113 std::cout << i << std::endl;
114 }
115 caffe::Caffe::SetDevices(devices);
116
117 // Load model
118 std::unique_ptr<caffe::Net<float>> upCaffeNet;
119 caffe::Caffe::set_mode(caffe::Caffe::GPU);
120 caffe::Caffe::SelectDevice(0, true);
121 upCaffeNet.reset(new caffe::Net<float>{
122 "models/pose/coco/pose_deploy_linevec.prototxt", caffe::TEST, caffe::Caffe::GetDefaultDevice()});
123 upCaffeNet->CopyTrainedLayersFrom("models/pose/coco/pose_iter_440000.caffemodel");
124 op::OpenCL::getInstance(0, CL_DEVICE_TYPE_GPU, true);
125
126 // Reshape net to image size
127 upCaffeNet->blobs()[0]->Reshape({1,imgFloat.channels(),imgResize.size().width,imgResize.size().height});
128 upCaffeNet->Reshape();
129
130 // Convert to caffe image
131 caffe::BlobProto blob_proto;
132 blob_proto.set_channels(3);
133 blob_proto.set_height(imgResize.size().width);
134 blob_proto.set_width(imgResize.size().height);
135 blob_proto.clear_data();
136 for (int c = 0; c < 3; ++c)
137 for (int h = 0; h < imgResize.size().height; ++h)
138 for (int w = 0; w < imgResize.size().width; ++w)
139 blob_proto.add_data(imgResize.at<cv::Vec3f>(h, w)[c]);
140 blob_proto.set_num(1);
141 caffe::Blob<float>* input_layer = upCaffeNet->input_blobs()[0];
142 input_layer->FromProto(blob_proto);
143 upCaffeNet->Forward(0);
144
145 boost::shared_ptr<caffe::Blob<float>> output_blob = upCaffeNet->blob_by_name("net_output");
146
147 // Test
148 cl::Device& device = op::OpenCL::getInstance(0)->getDevice();
149 cl_uint mem_align;
150 clGetDeviceInfo(device.get(), CL_DEVICE_MEM_BASE_ADDR_ALIGN, sizeof(mem_align), &mem_align, nullptr);

Callers

nothing calls this directly

Calls 14

mutable_gpu_dataMethod · 0.80
shapeMethod · 0.80
enqueueReadBufferMethod · 0.80
createSubBufferMethod · 0.80
whatMethod · 0.80
errMethod · 0.80
errorFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
channelsMethod · 0.45
resetMethod · 0.45
ReshapeMethod · 0.45

Tested by

no test coverage detected