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

Method initializationOnThread

src/openpose/net/netCaffe.cpp:154–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152 }
153
154 void NetCaffe::initializationOnThread()
155 {
156 try
157 {
158 #ifdef USE_CAFFE
159 // Initialize net
160 #ifdef USE_OPENCL
161 caffe::Caffe::set_mode(caffe::Caffe::GPU);
162 caffe::Caffe::SelectDevice(upImpl->mGpuId, true);
163 upImpl->upCaffeNet.reset(new caffe::Net<float>{upImpl->mCaffeProto, caffe::TEST,
164 caffe::Caffe::GetDefaultDevice()});
165 upImpl->upCaffeNet->CopyTrainedLayersFrom(upImpl->mCaffeTrainedModel);
166 OpenCL::getInstance(upImpl->mGpuId, CL_DEVICE_TYPE_GPU, true);
167 #else
168 #ifdef USE_CUDA
169 caffe::Caffe::set_mode(caffe::Caffe::GPU);
170 caffe::Caffe::SetDevice(upImpl->mGpuId);
171 #ifdef NV_CAFFE
172 upImpl->upCaffeNet.reset(new caffe::Net{upImpl->mCaffeProto, caffe::TEST});
173 #else
174 upImpl->upCaffeNet.reset(new caffe::Net<float>{upImpl->mCaffeProto, caffe::TEST});
175 #endif
176 #else
177 caffe::Caffe::set_mode(caffe::Caffe::CPU);
178 #ifdef _WIN32
179 upImpl->upCaffeNet.reset(new caffe::Net<float>{upImpl->mCaffeProto, caffe::TEST,
180 caffe::Caffe::GetCPUDevice()});
181 #else
182 upImpl->upCaffeNet.reset(new caffe::Net<float>{upImpl->mCaffeProto, caffe::TEST});
183 #endif
184 #endif
185 upImpl->upCaffeNet->CopyTrainedLayersFrom(upImpl->mCaffeTrainedModel);
186 #ifdef USE_CUDA
187 cudaCheck(__LINE__, __FUNCTION__, __FILE__);
188 #endif
189 #endif
190 // Set spOutputBlob
191 #ifdef NV_CAFFE
192 upImpl->spOutputBlob = boost::static_pointer_cast<caffe::TBlob<float>>(
193 upImpl->upCaffeNet->blob_by_name(upImpl->mLastBlobName));
194 #else
195 upImpl->spOutputBlob = upImpl->upCaffeNet->blob_by_name(upImpl->mLastBlobName);
196 #endif
197 // Sanity check
198 if (upImpl->spOutputBlob == nullptr)
199 error("The output blob is a nullptr. Did you use the same name than the prototxt? (Used: "
200 + upImpl->mLastBlobName + ").", __LINE__, __FUNCTION__, __FILE__);
201 #ifdef USE_CUDA
202 cudaCheck(__LINE__, __FUNCTION__, __FILE__);
203 #endif
204 #endif
205 }
206 catch (const std::exception& e)
207 {
208 error(e.what(), __LINE__, __FUNCTION__, __FILE__);
209 }
210 }
211

Callers

nothing calls this directly

Calls 4

cudaCheckFunction · 0.85
whatMethod · 0.80
errorFunction · 0.50
resetMethod · 0.45

Tested by

no test coverage detected