[dlib] 19.7설치

spring·2020년 11월 9일
0

##[dlib] 설치

http://dlib.net/

에 들어가서 좌측 하단에 있는 다운로드 버튼을 클릭한다.

아니면 아래에 미리 빌드된 버전을 받아도 된다.

dlib19.7 prebuild zip

다운받은 파일을 압축을 풀어준다.

필요한 라이브러리는 아래와 같다.

opencv-3.3.0-vc14.exe

libjpeg-x64.zip

libpng-x64.zip

zlib-x64.zip

CUDNN

MKL


설치 방법은 홈페이지에 너무나 자세하게 나와 있지는 않고,

써드파티가 문제인데, 우선 example/build 폴더까지는 만들어주고
cmake-gui 를 켠 다음 Advanced를 체크한다.

DLIB_JPEG_SUPPORT                    ON
DLIB_PNG_SUPPORT                     ON
DLIB_USE_BLAS                        OFF
DLIB_USE_CUDA                        ON
DLIB_USE_LAPACK                      OFF
JPEG_INCLUDE_DIR                     <path> 
JPEG_LIBRARY                         <path>
OpenCV_DIR                           <path>
PNG_LIBRARY_RELEASE                  <path>
PNG_PNG_INCLUDE_DIR                  <path>
USE_AVX_INSTRUCTIONS                 ON
USE_SSE2_INSTRUCTIONS                ON
USE_SSE4_INSTRUCTUINS                ON
ZLIB_INCLUDE_DIR                     <path>
ZLIB_LIBRARY_RELEASE                 <path>
cudnn                                <path>
cudnn_include                        <path>

<path> 에는 위에서 받은 써드파티 라이브러리의 경로를 넣어주면 된다. cudnn은 5.1을 사용했다.

cmake build 가 끝났으면, examples/build/dlib-build 에 들어가서 dlib.sln 을 열어 ALL_BUILD 를 빌드해준다.
그럼 examples/build/dlib_build/Release/ 폴더에 lib 파일들이 생겼을 것이다.

19.7을 돌리는 이유는 새로나온 cnn을 쓰기 위해서 인데, 이 코드를 컴파일 하려면 몇가지 설정이 필요하다.

전처리기에 아래 내용 추가

DLIB_USE_CUDA
DLIB_JPEG_SUPPORT

추가 종속성에 아래 내용 추가

dlib.lib
libiomp5md.lib
mkl_core.lib
mkl_intel_lp64.lib
mkl_intel_thread.lib
libjpeg.lib
cudart.lib
cuda.lib
cudnn.lib
curand.lib
cublas.lib
cusolver.lib

이제 아래의 예제 소스를 컴파일 해보자.

#include <iostream> 
#include <dlib/dnn.h> 
#include <dlib/image_io.h> 
#include <dlib/gui_widgets.h> 
#include <dlib/image_processing.h> 
using namespace std; 
using namespace dlib;

template <long num_filters, typename SUBNET> using con5d = con<num_filters, 5, 5, 2, 2, SUBNET>;
template <long num_filters, typename SUBNET> using con5 = con<num_filters, 5, 5, 1, 1, SUBNET>;
template <typename SUBNET> using downsampler = relu<affine<con5d<32, relu<affine<con5d<32, relu<affine<con5d<16, SUBNET>>>>>>>>>;
template <typename SUBNET> using rcon5 = relu<affine<con5<55, SUBNET>>>;
using net_type = loss_mmod<con<1, 9, 9, 1, 1, rcon5<rcon5<rcon5<downsampler<input_rgb_image_pyramid<pyramid_down<6>>>>>>>>;

int main()try {
	net_type net; 
	shape_predictor sp; 
	// You can get this file from http://dlib.net/files/mmod_front_and_rear_end_vehicle_detector.dat.bz2
	// This network was produced by the dnn_mmod_train_find_cars_ex.cpp example program.
	// As you can see, the file also includes a separately trained shape_predictor.  To see
	// a generic example of how to train those refer to train_shape_predictor_ex.cpp.
	deserialize("../../mmod_front_and_rear_end_vehicle_detector.dat") >> net >> sp; 
	matrix<rgb_pixel> img;
	load_image(img, "../../mmod_cars_test_image2.jpg"); 
	image_window win;
	win.set_image(img); // Run the detector on the image and show us the output.
	auto network = net(img);
	std::cout << "load?" << std::endl;
	for (auto&& d : network) {
		// We use a shape_predictor to refine the exact shape and location of the detection
		// box.  This shape_predictor is trained to simply output the 4 corner points of
		// the box.  So all we do is make a rectangle that tightly contains those 4 points
		// and that rectangle is our refined detection position.
		auto fd = sp(img, d); 
		rectangle rect; 
		for (unsigned long j = 0; j < fd.num_parts(); ++j)
			rect += fd.part(j); 
		if (d.label == "rear") 
			win.add_overlay(rect, rgb_pixel(255, 0, 0), d.label);
		else 
			win.add_overlay(rect, rgb_pixel(255, 255, 0), d.label);
	}
	system("pause");
} catch (image_load_error& e) {
	cout << e.what() << endl; cout << "The test image is located in the examples folder.  So you should run this program from a sub folder so that the relative path is correct." << endl;
} catch (serialization_error& e) {
	cout << e.what() << endl; cout << "The correct model file can be obtained from: http://dlib.net/files/mmod_front_and_rear_end_vehicle_detector.dat.bz2" << endl;
} catch (std::exception& e) {
	cout << e.what() << endl;
}

####결과

http://dlib.net/release_notes.html

http://dlib.net/dnn_mmod_train_find_cars_ex.cpp.html

http://dlib.net/dnn_mmod_find_cars2_ex.cpp.html

http://dlib.net/files/

profile
Researcher & Developer @ NAVER Corp | Designer @ HONGIK Univ.

0개의 댓글