Skip to content

Commit

Permalink
removed data folder; added code for compiling without SSE
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiaolong committed Sep 18, 2016
1 parent 71c4707 commit 49b1c99
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 14 deletions.
14 changes: 11 additions & 3 deletions FaceDetection/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
cmake_minimum_required(VERSION 2.8.4)
cmake_minimum_required(VERSION 3.1.0)

project(seeta_facedet_lib)

# Build options
option(BUILD_EXAMPLES "Set to ON to build examples" ON)
option(USE_OPENMP "Set to ON to build use openmp" ON)
option(USE_SSE "Set to ON to build use SSE" ON)

# Use C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "C++11 support has been enabled by default.")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
# Use SSE
if (USE_SSE)
add_definitions(-DUSE_SSE)
message(STATUS "Use SSE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
endif()

# Use OpenMP
if (USE_OPENMP)
find_package(OpenMP QUIET)
if (OpenMP_FOUND)
if (OPENMP_FOUND)
message(STATUS "Use OpenMP")
add_definitions(-DUSE_OPENMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
Expand All @@ -41,9 +47,11 @@ set(src_files
src/fust.cpp
)

# Build shared library
add_library(seeta_facedet_lib SHARED ${src_files})
set(facedet_required_libs seeta_facedet_lib)

# Build examples
if (BUILD_EXAMPLES)
message(STATUS "Build with examples.")
find_package(OpenCV)
Expand Down
6 changes: 3 additions & 3 deletions FaceDetection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ FacenessNet [2] | 80x80 | n/a | 20 FPS
8. Build.

### How to Build in Linux
- build
- Build
```shell
mkdir build
cd build
cmake ..
make -j${nproc}
```

- run demo
- Run demo
```shell
./build/facedet_test data/2007_007763.jpg model/seeta_fd_frontal_v1.0.bin
./build/facedet_test image_file model/seeta_fd_frontal_v1.0.bin
```

### How to run SeetaFace Detector
Expand Down
Binary file removed FaceDetection/data/2007_007763.jpg
Binary file not shown.
Binary file removed FaceDetection/data/2008_001009.jpg
Binary file not shown.
Binary file removed FaceDetection/data/2008_001322.jpg
Binary file not shown.
Binary file removed FaceDetection/data/2008_002079.jpg
Binary file not shown.
Binary file removed FaceDetection/data/2008_002470.jpg
Binary file not shown.
Binary file removed FaceDetection/data/2008_002506.jpg
Binary file not shown.
Binary file removed FaceDetection/data/2008_004176.jpg
Binary file not shown.
Binary file removed FaceDetection/data/2008_007676.jpg
Binary file not shown.
Binary file removed FaceDetection/data/2009_004587.jpg
Binary file not shown.
40 changes: 33 additions & 7 deletions FaceDetection/include/util/math_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
#ifndef SEETA_FD_UTIL_MATH_FUNC_H_
#define SEETA_FD_UTIL_MATH_FUNC_H_

#ifdef USE_SSE
#include <immintrin.h>
#endif

#include <cstdint>

Expand All @@ -49,31 +51,37 @@ class MathFunction {

static inline void VectorAdd(const int32_t* x, const int32_t* y, int32_t* z,
int32_t len) {
int32_t i;
#ifdef USE_SSE
__m128i x1;
__m128i y1;
const __m128i* x2 = reinterpret_cast<const __m128i*>(x);
const __m128i* y2 = reinterpret_cast<const __m128i*>(y);
__m128i* z2 = reinterpret_cast<__m128i*>(z);

int32_t i;
for (i = 0; i < len - 4; i += 4) {
x1 = _mm_loadu_si128(x2++);
y1 = _mm_loadu_si128(y2++);
_mm_storeu_si128(z2++, _mm_add_epi32(x1, y1));
}
for (; i < len; i++)
*(z + i) = (*(x + i)) + (*(y + i));
#else
for (i = 0; i < len; i++)
*(z + i) = (*(x + i)) + (*(y + i));
#endif
}

static inline void VectorSub(const int32_t* x, const int32_t* y, int32_t* z,
int32_t len) {
int32_t i;
#ifdef USE_SSE
__m128i x1;
__m128i y1;
const __m128i* x2 = reinterpret_cast<const __m128i*>(x);
const __m128i* y2 = reinterpret_cast<const __m128i*>(y);
__m128i* z2 = reinterpret_cast<__m128i*>(z);

int32_t i;
for (i = 0; i < len - 4; i += 4) {
x1 = _mm_loadu_si128(x2++);
y1 = _mm_loadu_si128(y2++);
Expand All @@ -82,47 +90,62 @@ class MathFunction {
}
for (; i < len; i++)
*(z + i) = (*(x + i)) - (*(y + i));
#else
for (i = 0; i < len; i++)
*(z + i) = (*(x + i)) - (*(y + i));
#endif
}

static inline void VectorAbs(const int32_t* src, int32_t* dest, int32_t len) {
int32_t i;
#ifdef USE_SSE
__m128i val;
__m128i val_abs;
const __m128i* x = reinterpret_cast<const __m128i*>(src);
__m128i* y = reinterpret_cast<__m128i*>(dest);

int32_t i;
for (i = 0; i < len - 4; i += 4) {
val = _mm_loadu_si128(x++);
val_abs = _mm_abs_epi32(val);
_mm_storeu_si128(y++, val_abs);
}
for (; i < len; i++)
dest[i] = (src[i] >= 0 ? src[i] : -src[i]);
#else
for (i = 0; i < len; i++)
dest[i] = (src[i] >= 0 ? src[i] : -src[i]);
#endif
}

static inline void Square(const int32_t* src, uint32_t* dest, int32_t len) {
int32_t i;
#ifdef USE_SSE
__m128i x1;
const __m128i* x2 = reinterpret_cast<const __m128i*>(src);
__m128i* y2 = reinterpret_cast<__m128i*>(dest);

int32_t i;
for (i = 0; i < len - 4; i += 4) {
x1 = _mm_loadu_si128(x2++);
_mm_storeu_si128(y2++, _mm_mullo_epi32(x1, x1));
}
for (; i < len; i++)
*(dest + i) = (*(src + i)) * (*(src + i));
#else
for (i = 0; i < len; i++)
*(dest + i) = (*(src + i)) * (*(src + i));
#endif
}

static inline float VectorInnerProduct(const float* x, const float* y,
int32_t len) {
float prod = 0;
int32_t i;
#ifdef USE_SSE
__m128 x1;
__m128 y1;
__m128 z1 = _mm_setzero_ps();
float prod;
float buf[4];

int32_t i;
for (i = 0; i < len - 4; i += 4) {
x1 = _mm_loadu_ps(x + i);
y1 = _mm_loadu_ps(y + i);
Expand All @@ -132,7 +155,10 @@ class MathFunction {
prod = buf[0] + buf[1] + buf[2] + buf[3];
for (; i < len; i++)
prod += x[i] * y[i];

#else
for (i = 0; i < len; i++)
prod += x[i] * y[i];
#endif
return prod;
}
};
Expand Down
38 changes: 37 additions & 1 deletion FaceDetection/src/feat/surf_feature_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ void SURFFeatureMap::ComputeIntegralImages() {
void SURFFeatureMap::MaskIntegralChannel() {
const int32_t* grad_x = grad_x_.data();
const int32_t* grad_y = grad_y_.data();
int32_t len = width_ * height_;
#ifdef USE_SSE
__m128i dx;
__m128i dy;
__m128i dx_mask;
Expand All @@ -232,7 +234,6 @@ void SURFFeatureMap::MaskIntegralChannel() {
__m128i data;
__m128i result;
__m128i* src = reinterpret_cast<__m128i*>(int_img_.data());
int32_t len = width_ * height_;

for (int32_t i = 0; i < len; i++) {
dx = _mm_set1_epi32(*(grad_x++));
Expand All @@ -247,6 +248,32 @@ void SURFFeatureMap::MaskIntegralChannel() {
result = _mm_and_si128(data, dx_mask);
_mm_storeu_si128(src++, result);
}
#else
int32_t dx, dy, dx_mask, dy_mask, cmp;
int32_t xor_bits[] = {-1, -1, 0, 0};

int32_t* src = int_img_.data();
for (int32_t i = 0; i < len; i++) {
dy = *(grad_y++);
dx = *(grad_x++);

cmp = dy < 0 ? 0xffffffff : 0x0;
for (int32_t j = 0; j < 4; j++) {
// cmp xor xor_bits
dy_mask = cmp ^ xor_bits[j];
*(src) = (*src) & dy_mask;
src++;
}

cmp = dx < 0 ? 0xffffffff : 0x0;
for (int32_t j = 0; j < 4; j++) {
// cmp xor xor_bits
dx_mask = cmp ^ xor_bits[j];
*(src) = (*src) & dx_mask;
src++;
}
}
#endif
}

void SURFFeatureMap::Integral() {
Expand All @@ -266,6 +293,7 @@ void SURFFeatureMap::Integral() {

void SURFFeatureMap::VectorCumAdd(int32_t* x, int32_t len,
int32_t num_channel) {
#ifdef USE_SSE
__m128i x1;
__m128i y1;
__m128i z1;
Expand All @@ -289,6 +317,14 @@ void SURFFeatureMap::VectorCumAdd(int32_t* x, int32_t len,
_mm_storeu_si128(z2, z1);
z2 = y2;
}
#else
int32_t cols = len / num_channel - 1;
for (int32_t i = 0; i < cols; i++) {
int32_t* col1 = x + i * num_channel;
int32_t* col2 = col1 + num_channel;
seeta::fd::MathFunction::VectorAdd(col1, col2, col2, num_channel);
}
#endif
}

void SURFFeatureMap::ComputeFeatureVector(const SURFFeature & feat,
Expand Down
7 changes: 7 additions & 0 deletions FaceDetection/src/test/facedetection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ int main(int argc, char** argv) {
#else
cout << "OpenMP is not used. " << endl;
#endif

#ifdef USE_SSE
cout << "SSE is used." << endl;
#else
cout << "SSE is not used." << endl;
#endif

cout << "Image size (wxh): " << img_data.width << "x"
<< img_data.height << endl;

Expand Down

0 comments on commit 49b1c99

Please sign in to comment.