Skip to content

Commit

Permalink
Added mobile version support
Browse files Browse the repository at this point in the history
  • Loading branch information
kyakuno committed Nov 1, 2024
1 parent 3bf06e7 commit f5004bc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
18 changes: 15 additions & 3 deletions face_detection/retinaface/retinaface.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,35 @@ cd %~dp0
set MODEL=retinaface
set FILE1=%MODEL%_resnet50.onnx
set FILE2=%MODEL%_resnet50.onnx.prototxt
set FILE3=%MODEL%_mobile0.25.onnx
set FILE4=%MODEL%_mobile0.25.onnx.prototxt

rem download
if not "%1" == "-h" if not "%1" == "--help" (
if not exist %FILE1% (
echo Downloading onnx file... ^(save path: %FILE1%^)
curl https://storage.googleapis.com/ailia-models/%MODEL%/%FILE1% -o %FILE1%
rem bitsadmin /RawReturn /TRANSFER getfile https://storage.googleapis.com/ailia-models/%MODEL%/%FILE1% %CD%/%FILE1%
)
)
if not "%1" == "-h" if not "%1" == "--help" (
if not exist %FILE2% (
echo Downloading onnx file... ^(save path: %FILE2%^)
curl https://storage.googleapis.com/ailia-models/%MODEL%/%FILE2% -o %FILE2%
rem bitsadmin /RawReturn /TRANSFER getfile https://storage.googleapis.com/ailia-models/%MODEL%/%FILE2% %CD%/%FILE2%
)
echo ONNX file and Prototxt file are prepared^^!
)

if not "%1" == "-h" if not "%1" == "--help" (
if not exist %FILE3% (
echo Downloading onnx file... ^(save path: %FILE3%^)
curl https://storage.googleapis.com/ailia-models/%MODEL%/%FILE3% -o %FILE3%
)
)
if not "%1" == "-h" if not "%1" == "--help" (
if not exist %FILE4% (
echo Downloading onnx file... ^(save path: %FILE4%^)
curl https://storage.googleapis.com/ailia-models/%MODEL%/%FILE4% -o %FILE4%
)
echo ONNX file and Prototxt file are prepared^^!
)
rem execute
.\%MODEL%.exe %*
30 changes: 23 additions & 7 deletions face_detection/retinaface/retinaface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ using namespace std;
#define WEIGHT_PATH "retinaface_resnet50.onnx"
#define MODEL_PATH "retinaface_resnet50.onnx.prototxt"

#define WEIGHT_PATH_MOBILE "retinaface_mobile0.25.onnx"
#define MODEL_PATH_MOBILE "retinaface_mobile0.25.onnx.prototxt"

#define IMAGE_PATH "selfie.png"
#define SAVE_IMAGE_PATH "output.png"

Expand All @@ -53,16 +56,12 @@ using namespace std;

#define BENCHMARK_ITERS 5

static std::string weight(WEIGHT_PATH);
static std::string model(MODEL_PATH);

static std::string image_path(IMAGE_PATH);
static std::string video_path("0");
static std::string save_image_path(SAVE_IMAGE_PATH);

static const std::vector<const char*> FACE_CATEGORY = {"face"};

static bool benchmark = false;
static bool mobile = false;
static bool video_mode = false;


Expand Down Expand Up @@ -94,6 +93,7 @@ static void print_help()
PRINT_OUT(" -b, --benchmark Running the inference on the same input 5 times to\n");
PRINT_OUT(" measure execution performance. (Cannot be used in\n");
PRINT_OUT(" video mode)\n");
PRINT_OUT(" -m, --mobile Use mobile version model.\n");
return;
}

Expand Down Expand Up @@ -125,6 +125,9 @@ static int argument_parser(int argc, char **argv)
else if (arg == "-b" || arg == "--benchmark") {
benchmark = true;
}
else if (arg == "-m" || arg == "--mobile") {
mobile = true;
}
else if (arg == "-h" || arg == "--help") {
print_usage();
print_help();
Expand Down Expand Up @@ -180,6 +183,7 @@ int TOP_K = 5000;
int KEEP_TOP_K = 750;
const float CONFIDENCE_THRES = 0.02f;
const float NMS_THRES = 0.4f;
const float VIS_THRES = 0.6f;
float VARIANCE[] = {0.1f, 0.2f};

struct FaceInfo {
Expand Down Expand Up @@ -541,8 +545,13 @@ int plot_result_retinaface(std::vector<FaceInfo> info, cv::Mat& img, bool loggin

for (int i = 0; i < info.size(); i++) {
FaceInfo obj = info[i];
PRINT_OUT("+ idx=%d\n score=%.15f\n x=%.15f\n y=%.15f\n w=%.15f\n h=%.15f\n",
i, obj.score, obj.center.first, obj.center.second, obj.width, obj.height);
if (obj.score < VIS_THRES){
continue;
}
if (logging){
PRINT_OUT("+ idx=%d\n score=%.15f\n x=%.15f\n y=%.15f\n w=%.15f\n h=%.15f\n",
i, obj.score, obj.center.first, obj.center.second, obj.width, obj.height);
}

cv::Point top_left((int)((obj.center.first - obj.width / 2)), (int)((obj.center.second - obj.height / 2)));
cv::Point bottom_right((int)((obj.center.first + obj.width / 2)), (int)((obj.center.second + obj.height / 2)));
Expand Down Expand Up @@ -666,6 +675,13 @@ int main(int argc, char **argv)
return -1;
}

static std::string weight(WEIGHT_PATH);
static std::string model(MODEL_PATH);
if (mobile){
weight = WEIGHT_PATH_MOBILE;
model = MODEL_PATH_MOBILE;
}

// net initialize
AILIANetwork *ailia;
int env_id = AILIA_ENVIRONMENT_ID_AUTO;
Expand Down
18 changes: 15 additions & 3 deletions face_detection/retinaface/retinaface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,35 @@
MODEL="retinaface"
FILE1="${MODEL}_resnet50.onnx"
FILE2="${MODEL}_resnet50.onnx.prototxt"
FILE3="${MODEL}_mobile0.25.onnx"
FILE4="${MODEL}_mobile0.25.onnx.prototxt"

#download
if [ ! "$1" = "-h" ] && [ ! "$1" = "--help" ]; then
if [ ! -e ${FILE1} ]; then
echo "Downloading onnx file... save path: ${FILE1}"
curl https://storage.googleapis.com/ailia-models/${MODEL}/${FILE1} -o ${FILE1}
# wget https://storage.googleapis.com/ailia-models/${MODEL}/${FILE1}
fi
fi
if [ ! "$1" = "-h" ] && [ ! "$1" = "--help" ]; then
if [ ! -e ${FILE2} ]; then
echo "Downloading onnx file... save path: ${FILE2}"
curl https://storage.googleapis.com/ailia-models/${MODEL}/${FILE2} -o ${FILE2}
# wget https://storage.googleapis.com/ailia-models/${MODEL}/${FILE2}
fi
echo "ONNX file and Prototxt file are prepared!"
fi

if [ ! "$1" = "-h" ] && [ ! "$1" = "--help" ]; then
if [ ! -e ${FILE3} ]; then
echo "Downloading onnx file... save path: ${FILE3}"
curl https://storage.googleapis.com/ailia-models/${MODEL}/${FILE3} -o ${FILE3}
fi
fi
if [ ! "$1" = "-h" ] && [ ! "$1" = "--help" ]; then
if [ ! -e ${FILE4} ]; then
echo "Downloading onnx file... save path: ${FILE4}"
curl https://storage.googleapis.com/ailia-models/${MODEL}/${FILE4} -o ${FILE4}
fi
echo "ONNX file and Prototxt file are prepared!"
fi
#execute
./${MODEL} $*

0 comments on commit f5004bc

Please sign in to comment.