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

Cherry-pick PR 1366, 1370, 1460, 1577, 1598, 1601, 1612, 1626 to dev-1.x #1635

Merged
merged 9 commits into from
Jan 17, 2023
Merged
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
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ endif ()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# options
option(MMDEPLOY_SHARED_LIBS "build shared libs" ON)
option(MMDEPLOY_SHARED_LIBS "build shared libs" OFF)
option(MMDEPLOY_BUILD_SDK "build MMDeploy SDK" OFF)
option(MMDEPLOY_BUILD_SDK_MONOLITHIC "build single lib for SDK API" OFF)
option(MMDEPLOY_BUILD_SDK_MONOLITHIC "build single lib for SDK API" ON)
option(MMDEPLOY_BUILD_TEST "build unittests" OFF)
option(MMDEPLOY_BUILD_SDK_PYTHON_API "build SDK Python API" OFF)
option(MMDEPLOY_BUILD_SDK_CXX_API "build SDK C++ API" OFF)
Expand Down Expand Up @@ -73,8 +73,6 @@ endif ()

if (MSVC)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/diagnostics:classic>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/Zc:preprocessor>) # /experimental:preprocessor on VS2017
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/wd4251>)
endif ()

Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/csharp/MMDeploy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMDeploy", "MMDeploy\MMDeploy.csproj", "{3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MMDeploy", "MMDeploy\MMDeployCSharp.csproj", "{3DC914EB-A8FB-4A89-A7CF-7DF9CC5284A6}"
EndProject

Global
Expand Down
1 change: 1 addition & 0 deletions csrc/mmdeploy/apis/csharp/MMDeploy/APIs/common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public unsafe struct Mat
public int Channel;
public PixelFormat Format;
public DataType Type;
public void* Device;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netcoreapp3.1;net48;</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<AssemblyName>MMDeploy</AssemblyName>
<AssemblyName>MMDeployCSharp</AssemblyName>
<RootNamespace>MMDeploy</RootNamespace>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Deterministic>true</Deterministic>
Expand All @@ -17,7 +17,16 @@
<MMDeployNativeDlls>$(MSBuildThisFileDirectory)\..\..\..\..\..</MMDeployNativeDlls>
</PropertyGroup>
<ItemGroup>
<Content CopyToOutputDirectory="PreserveNewest" Include="$(MMDeployNativeDlls)\build\bin\Release\mmdeploy.dll" Pack="true" PackagePath="runtimes\win-x64\native\mmdeploy.dll" />
<Content Include="$(MMDeployNativeDlls)\build\bin\Release\mmdeploy.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>true</Pack>
<PackagePath>runtimes\win-x64\native\mmdeploy.dll</PackagePath>
</Content>
<Content Include="MMDeployCSharp.props">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>true</Pack>
<PackagePath>build\net48\MMDeployCSharp.props</PackagePath>
</Content>
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
11 changes: 11 additions & 0 deletions csrc/mmdeploy/apis/csharp/MMDeploy/MMDeployCSharp.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MMDeployNativeDlls>$(MSBuildThisFileDirectory)..\..\runtimes</MMDeployNativeDlls>
</PropertyGroup>
<ItemGroup Condition="$(TargetFrameworkVersion.StartsWith('v4')) Or $(TargetFramework.StartsWith('net4'))">
<Content Include="$(MMDeployNativeDlls)\win-x64\native\mmdeploy.dll">
<Link>mmdeploy.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions csrc/mmdeploy/apis/csharp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ There are two methods to build the nuget package.

(*option 1*) Use the command.

If your environment is well prepared, you can just go to the `csrc\apis\csharp` folder, open a terminal and type the following command, the nupkg will be built in `csrc\apis\csharp\MMDeploy\bin\Release\MMDeploy.1.0.0.nupkg`.
If your environment is well prepared, you can just go to the `csrc\apis\csharp` folder, open a terminal and type the following command, the nupkg will be built in `csrc\apis\csharp\MMDeploy\bin\Release\MMDeployCSharp.1.0.0-rc1.nupkg`.

```shell
dotnet build --configuration Release -p:Version=1.0.0
dotnet build --configuration Release -p:Version=1.0.0-rc1
```

(*option 2*) Open MMDeploy.sln && Build.
Expand Down
12 changes: 2 additions & 10 deletions csrc/mmdeploy/codebase/mmdet/yolo_head.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@ Result<Detections> YOLOHead::GetBBoxes(const Value& prep_res,
return objs;
}

Result<Value> YOLOV3Head::operator()(const Value& prep_res, const Value& infer_res) {
return YOLOHead::operator()(prep_res, infer_res);
}

std::array<float, 4> YOLOV3Head::yolo_decode(float box_x, float box_y, float box_w, float box_h,
float stride,
const std::vector<std::vector<float>>& anchor, int j,
Expand All @@ -212,11 +208,7 @@ std::array<float, 4> YOLOV3Head::yolo_decode(float box_x, float box_y, float box
return std::array<float, 4>{box_x, box_y, box_w, box_h};
}

Result<Value> YOLOv5Head::operator()(const Value& prep_res, const Value& infer_res) {
return YOLOHead::operator()(prep_res, infer_res);
}

std::array<float, 4> YOLOv5Head::yolo_decode(float box_x, float box_y, float box_w, float box_h,
std::array<float, 4> YOLOV5Head::yolo_decode(float box_x, float box_y, float box_w, float box_h,
float stride,
const std::vector<std::vector<float>>& anchor, int j,
int i, int a) const {
Expand All @@ -232,6 +224,6 @@ std::array<float, 4> YOLOv5Head::yolo_decode(float box_x, float box_y, float box
}

MMDEPLOY_REGISTER_CODEBASE_COMPONENT(MMDetection, YOLOV3Head);
MMDEPLOY_REGISTER_CODEBASE_COMPONENT(MMDetection, YOLOv5Head);
MMDEPLOY_REGISTER_CODEBASE_COMPONENT(MMDetection, YOLOV5Head);

} // namespace mmdeploy::mmdet
4 changes: 1 addition & 3 deletions csrc/mmdeploy/codebase/mmdet/yolo_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ class YOLOHead : public MMDetection {
class YOLOV3Head : public YOLOHead {
public:
using YOLOHead::YOLOHead;
Result<Value> operator()(const Value& prep_res, const Value& infer_res);
std::array<float, 4> yolo_decode(float box_x, float box_y, float box_w, float box_h, float stride,
const std::vector<std::vector<float>>& anchor, int j, int i,
int a) const override;
};

class YOLOv5Head : public YOLOHead {
class YOLOV5Head : public YOLOHead {
public:
using YOLOHead::YOLOHead;
Result<Value> operator()(const Value& prep_res, const Value& infer_res);
std::array<float, 4> yolo_decode(float box_x, float box_y, float box_w, float box_h, float stride,
const std::vector<std::vector<float>>& anchor, int j, int i,
int a) const override;
Expand Down
5 changes: 5 additions & 0 deletions csrc/mmdeploy/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ target_include_directories(${PROJECT_NAME}
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/third_party/json>
)

if (MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:/Zc:preprocessor;/Zc:__cplusplus>)
endif ()

if (MMDEPLOY_STATUS_USE_STACKTRACE)
include(${CMAKE_SOURCE_DIR}/cmake/stacktrace.cmake)
else ()
Expand Down
5 changes: 4 additions & 1 deletion csrc/mmdeploy/device/cpu/cpu_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ class CpuHostMemory : public NonCopyable {
public:
CpuHostMemory() : size_(), data_(), owned_data_{false} {}
Result<void> Init(size_t size, size_t alignment) {
size_t space = (size + alignment - 1) / alignment * alignment;
alignment = std::max(alignment, sizeof(void*));
auto space = (size + alignment - 1) / alignment * alignment;
#ifdef _MSC_VER
data_ = _aligned_malloc(space, alignment);
#elif defined(ANDROID)
posix_memalign(&data_, alignment, space);
#else
data_ = std::aligned_alloc(alignment, space);
#endif
Expand Down
8 changes: 4 additions & 4 deletions csrc/mmdeploy/experimental/module_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ Result<Value> Invoke(Ret (*f)(Args...), const Value& args) {
}

// member function pointer
template <typename Ret, typename C, typename... Args>
Result<Value> Invoke(Ret (C::*f)(Args...) const, C* inst, const Value& args) {
template <typename Ret, typename C0, typename C1, typename... Args>
Result<Value> Invoke(Ret (C0::*f)(Args...) const, C1* inst, const Value& args) {
return InvokeImpl<Ret, Args...>::apply(f, args, inst);
}
template <typename Ret, typename C, typename... Args>
Result<Value> Invoke(Ret (C::*f)(Args...), C* inst, const Value& args) {
template <typename Ret, typename C0, typename C1, typename... Args>
Result<Value> Invoke(Ret (C0::*f)(Args...), C1* inst, const Value& args) {
return InvokeImpl<Ret, Args...>::apply(f, args, inst);
}

Expand Down
1 change: 1 addition & 0 deletions csrc/mmdeploy/operation/cuda/warp_affine.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) OpenMMLab. All rights reserved.
#include <array>

#include "mmdeploy/core/utils/formatter.h"
#include "mmdeploy/operation/vision.h"
Expand Down
1 change: 1 addition & 0 deletions demo/csharp/image_classification/FormDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static void CvMatToMat(CvMat[] cvMats, out Mat[] mats)
mats[i].Channel = cvMats[i].Dims;
mats[i].Format = PixelFormat.BGR;
mats[i].Type = DataType.Int8;
mats[i].Device = null;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MMDeploy" Version="1.0.0" />
<PackageReference Include="MMDeployCSharp" Version="1.0.0-rc1" />
<PackageReference Include="OpenCvSharp4" Version="4.5.5.20211231" />
<PackageReference Include="OpenCvSharp4.Extensions" Version="4.5.5.20211231" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.5.20211231" />
Expand Down
1 change: 1 addition & 0 deletions demo/csharp/image_restorer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static void CvMatToMat(CvMat[] cvMats, out Mat[] mats)
mats[i].Channel = cvMats[i].Dims;
mats[i].Format = PixelFormat.BGR;
mats[i].Type = DataType.Int8;
mats[i].Device = null;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion demo/csharp/image_restorer/image_restorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MMDeploy" Version="1.0.0" />
<PackageReference Include="MMDeployCSharp" Version="1.0.0-rc1" />
<PackageReference Include="OpenCvSharp4" Version="4.5.5.20211231" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.5.20211231" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions demo/csharp/image_segmentation/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static void CvMatToMat(OpenCvSharp.Mat[] cvMats, out MMDeploy.Mat[] mats)
mats[i].Channel = cvMats[i].Dims;
mats[i].Format = PixelFormat.BGR;
mats[i].Type = DataType.Int8;
mats[i].Device = null;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion demo/csharp/image_segmentation/image_segmentation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MMDeploy" Version="1.0.0" />
<PackageReference Include="MMDeployCSharp" Version="1.0.0-rc1" />
<PackageReference Include="OpenCvSharp4" Version="4.5.5.20211231" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.5.20211231" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions demo/csharp/object_detection/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static void CvMatToMat(OpenCvSharp.Mat[] cvMats, out MMDeploy.Mat[] mats)
mats[i].Channel = cvMats[i].Dims;
mats[i].Format = PixelFormat.BGR;
mats[i].Type = DataType.Int8;
mats[i].Device = null;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions demo/csharp/object_detection/object_detection.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MMDeploy" Version="1.0.0" />
<PackageReference Include="MMDeployCSharp" Version="1.0.0-rc1" />
<PackageReference Include="OpenCvSharp4" Version="4.5.5.20211231" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.5.20211231" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions demo/csharp/ocr_detection/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static void CvMatToMat(OpenCvSharp.Mat[] cvMats, out MMDeploy.Mat[] mats)
mats[i].Channel = cvMats[i].Dims;
mats[i].Format = PixelFormat.BGR;
mats[i].Type = DataType.Int8;
mats[i].Device = null;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion demo/csharp/ocr_detection/ocr_detection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MMDeploy" Version="1.0.0" />
<PackageReference Include="MMDeployCSharp" Version="1.0.0-rc1" />
<PackageReference Include="OpenCvSharp4" Version="4.5.5.20211231" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.5.20211231" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions demo/csharp/ocr_recognition/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static void CvMatToMat(OpenCvSharp.Mat[] cvMats, out MMDeploy.Mat[] mats)
mats[i].Channel = cvMats[i].Dims;
mats[i].Format = PixelFormat.BGR;
mats[i].Type = DataType.Int8;
mats[i].Device = null;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion demo/csharp/ocr_recognition/ocr_recognition.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MMDeploy" Version="1.0.0" />
<PackageReference Include="MMDeployCSharp" Version="1.0.0-rc1" />
<PackageReference Include="OpenCvSharp4" Version="4.5.5.20211231" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.5.20211231" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions demo/csharp/pose_detection/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static void CvMatToMat(OpenCvSharp.Mat[] cvMats, out MMDeploy.Mat[] mats)
mats[i].Channel = cvMats[i].Dims;
mats[i].Format = PixelFormat.BGR;
mats[i].Type = DataType.Int8;
mats[i].Device = null;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion demo/csharp/pose_detection/pose_detection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MMDeploy" Version="1.0.0" />
<PackageReference Include="MMDeployCSharp" Version="1.0.0-rc1" />
<PackageReference Include="OpenCvSharp4" Version="4.5.5.20211231" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.5.20211231" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions demo/csrc/cpp/pose_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ class Tracker {

float ObjectKeypointSimilarity(const Points& pts_a, const Bbox& box_a, const Points& pts_b,
const Bbox& box_b) {
assert(pts_a.size() == sigmas.size());
assert(pts_b.size() == sigmas.size());
assert(pts_a.size() == params.sigmas.size());
assert(pts_b.size() == params.sigmas.size());
auto scale = [](const Bbox& bbox) -> float {
auto a = bbox[2] - bbox[0];
auto b = bbox[3] - bbox[1];
Expand Down