Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build libraries to run on Windows #144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ how_to_make_video_demos.txt
test_pr*.py
demo_for_*.py
examples/**/zou*
examples/inputs/videos
examples/inputs/videos

.vs/
x64/

FaceBoxes/utils/nms/*.pyd
Sim3DR/*.pyd
2 changes: 1 addition & 1 deletion FaceBoxes/utils/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def build_extensions(self):
"nms.cpu_nms",
["nms/cpu_nms.pyx"],
# extra_compile_args={'gcc': ["-Wno-cpp", "-Wno-unused-function"]},
extra_compile_args=["-Wno-cpp", "-Wno-unused-function"],
# extra_compile_args=["-Wno-cpp", "-Wno-unused-function"],
include_dirs=[numpy_include]
)
]
Expand Down
7 changes: 4 additions & 3 deletions FaceBoxes/utils/nms/cpu_nms.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ cdef inline np.float32_t min(np.float32_t a, np.float32_t b):
return a if a <= b else b

def cpu_nms(np.ndarray[np.float32_t, ndim=2] dets, np.float thresh):
# Author: zubair-ahmed-ai https://github.com/cleardusk/3DDFA_V2/issues/12#issuecomment-697479173
cdef np.ndarray[np.float32_t, ndim=1] x1 = dets[:, 0]
cdef np.ndarray[np.float32_t, ndim=1] y1 = dets[:, 1]
cdef np.ndarray[np.float32_t, ndim=1] x2 = dets[:, 2]
cdef np.ndarray[np.float32_t, ndim=1] y2 = dets[:, 3]
cdef np.ndarray[np.float32_t, ndim=1] scores = dets[:, 4]

cdef np.ndarray[np.float32_t, ndim=1] areas = (x2 - x1 + 1) * (y2 - y1 + 1)
cdef np.ndarray[np.int_t, ndim=1] order = scores.argsort()[::-1]
cdef np.ndarray[np.int64_t, ndim=1] order = scores.argsort()[::-1]

cdef int ndets = dets.shape[0]
cdef np.ndarray[np.int_t, ndim=1] suppressed = \
np.zeros((ndets), dtype=np.int)
cdef np.ndarray[np.int64_t, ndim=1] suppressed = \
np.zeros((ndets), dtype=np.int64)

# nominal indices
cdef int _i, _j
Expand Down
27 changes: 27 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
torch = "*"
torchvision = "*"
matplotlib = "*"
numpy = "*"
opencv-python = "*"
imageio = "*"
imageio-ffmpeg = "*"
pyyaml = "*"
tqdm = "*"
argparse = "*"
cython = "*"
scikit-image = "*"
scipy = "*"
onnxruntime = "*"
gradio = "*"

[dev-packages]
ipykernel = "*"

[requires]
python_version = "3.10"
2,061 changes: 2,061 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bfm/bfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, bfm_fp, shape_dim=40, exp_dim=10):
self.tri = bfm.get('tri')

self.tri = _to_ctype(self.tri.T).astype(np.int32)
self.keypoints = bfm.get('keypoints').astype(np.long) # fix bug
self.keypoints = bfm.get('keypoints').astype(np.longlong) # fix bug
w = np.concatenate((self.w_shp, self.w_exp), axis=1)
self.w_norm = np.linalg.norm(w, axis=0)

Expand Down
11 changes: 11 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cd FaceBoxes/utils
./venv/Scripts/python build.py build_ext --inplace
cd ../..

cd Sim3DR
./venv/Scripts/python setup.py build_ext --inplace
cd ..

cd utils/asset
# gcc -shared -Wall -O3 render.c -o render.so -fPIC
cd ../..
20 changes: 20 additions & 0 deletions buildOnWindows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Prerequisite

Python, VS 2022

# Virtual environment

python -m pip install pipenv

mkdir .venv

python -m pipenv install

# Build libraries

Run build.ps1

Use precompiled render.dll
or
Build the solution in utils/asset/render

Binary file added utils/asset/render.dll
Binary file not shown.
31 changes: 31 additions & 0 deletions utils/asset/render/render.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32922.545
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "render", "render\render.vcxproj", "{4917C136-23D5-4643-8664-E70963754ABA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4917C136-23D5-4643-8664-E70963754ABA}.Debug|x64.ActiveCfg = Debug|x64
{4917C136-23D5-4643-8664-E70963754ABA}.Debug|x64.Build.0 = Debug|x64
{4917C136-23D5-4643-8664-E70963754ABA}.Debug|x86.ActiveCfg = Debug|Win32
{4917C136-23D5-4643-8664-E70963754ABA}.Debug|x86.Build.0 = Debug|Win32
{4917C136-23D5-4643-8664-E70963754ABA}.Release|x64.ActiveCfg = Release|x64
{4917C136-23D5-4643-8664-E70963754ABA}.Release|x64.Build.0 = Release|x64
{4917C136-23D5-4643-8664-E70963754ABA}.Release|x86.ActiveCfg = Release|Win32
{4917C136-23D5-4643-8664-E70963754ABA}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E15B8BE0-3719-4B95-8953-0723FF650352}
EndGlobalSection
EndGlobal
19 changes: 19 additions & 0 deletions utils/asset/render/render/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// dllmain.cpp : 定義 DLL 應用程式的進入點。
#include "pch.h"

BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}

5 changes: 5 additions & 0 deletions utils/asset/render/render/framework.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#define WIN32_LEAN_AND_MEAN // 從 Windows 標頭排除不常使用的項目
// Windows 標頭檔
#include <windows.h>
5 changes: 5 additions & 0 deletions utils/asset/render/render/pch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// pch.cpp: 對應到先行編譯標頭的來源檔案

#include "pch.h"

// 使用先行編譯的標頭時,需要來源檔案才能使編譯成功。
13 changes: 13 additions & 0 deletions utils/asset/render/render/pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// pch.h: 此為先行編譯的標頭檔。
// 以下所列檔案只會編譯一次,可改善之後組建的組建效能。
// 這也會影響 IntelliSense 效能,包括程式碼完成以及許多程式碼瀏覽功能。
// 但此處所列的檔案,如果其中任一在組建之間進行了更新,即會重新編譯所有檔案。
// 請勿於此處新增會經常更新的檔案,如此將會對於效能優勢產生負面的影響。

#ifndef PCH_H
#define PCH_H

// 請於此新增您要先行編譯的標頭
#include "framework.h"

#endif //PCH_H
Loading