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 1625, 1715, 1725 to dev-1.x #1726

Merged
merged 3 commits into from
Feb 8, 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
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/c/mmdeploy/pose_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct mmdeploy_pose_tracker_param_t {
int32_t pose_max_num_bboxes;
// threshold for visible key-points, default = 0.5
float pose_kpt_thr;
// min number of key-points for valid poses, default = -1
// min number of key-points for valid poses (-1 indicates ceil(n_kpts/2)), default = -1
int32_t pose_min_keypoints;
// scale for expanding key-points to bbox, default = 1.25
float pose_bbox_scale;
Expand Down
13 changes: 10 additions & 3 deletions csrc/mmdeploy/apis/c/mmdeploy/segmentor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,17 @@ int mmdeploy_segmentor_get_result(mmdeploy_value_t output, mmdeploy_segmentation
results_ptr->height = segmentor_output.height;
results_ptr->width = segmentor_output.width;
results_ptr->classes = segmentor_output.classes;
auto mask_size = results_ptr->height * results_ptr->width;
auto& mask = segmentor_output.mask;
results_ptr->mask = mask.data<int>();
buffers[i] = mask.buffer();
auto& score = segmentor_output.score;
results_ptr->mask = nullptr;
results_ptr->score = nullptr;
if (mask.shape().size()) {
results_ptr->mask = mask.data<int>();
buffers[i] = mask.buffer();
} else {
results_ptr->score = score.data<float>();
buffers[i] = score.buffer();
}
}

*results = results_data;
Expand Down
13 changes: 8 additions & 5 deletions csrc/mmdeploy/apis/c/mmdeploy/segmentor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ extern "C" {
#endif

typedef struct mmdeploy_segmentation_t {
int height; ///< height of \p mask that equals to the input image's height
int width; ///< width of \p mask that equals to the input image's width
int classes; ///< the number of labels in \p mask
int* mask; ///< segmentation mask of the input image, in which mask[i * width + j] indicates
///< the label id of pixel at (i, j)
int height; ///< height of \p mask that equals to the input image's height
int width; ///< width of \p mask that equals to the input image's width
int classes; ///< the number of labels in \p mask
int* mask; ///< segmentation mask of the input image, in which mask[i * width + j] indicates
///< the label id of pixel at (i, j), this field might be null
float* score; ///< segmentation score map of the input image in CHW format, in which
///< score[height * width * k + i * width + j] indicates the score
///< of class k at pixel (i, j), this field might be null
} mmdeploy_segmentation_t;

typedef struct mmdeploy_segmentor* mmdeploy_segmentor_t;
Expand Down
64 changes: 56 additions & 8 deletions csrc/mmdeploy/apis/csharp/MMDeploy/APIs/Segmentor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal unsafe struct CSegment
public int Width;
public int Classes;
public int* Mask;
public float* Score;
}
#pragma warning restore 0649

Expand All @@ -34,36 +35,83 @@ public struct SegmentorOutput
public int Classes;

/// <summary>
/// Mask data.
/// Mask data, mask[i * width + j] indicates the label id of pixel at (i, j).
/// </summary>
public int[] Mask;

/// <summary>
/// Score data, score[height * width * k + i * width + j] indicates the score
/// of class k at pixel (i, j).
/// </summary>
public float[] Score;

/// <summary>
/// Initializes a new instance of the <see cref="SegmentorOutput"/> struct.
/// </summary>
/// <param name="height">height.</param>
/// <param name="width">width.</param>
/// <param name="classes">classes.</param>
/// <param name="mask">mask.</param>
public SegmentorOutput(int height, int width, int classes, int[] mask)
/// <param name="score">score.</param>
public SegmentorOutput(int height, int width, int classes, int[] mask, float[] score)
{
Height = height;
Width = width;
Classes = classes;
Mask = new int[Height * Width];
Array.Copy(mask, this.Mask, mask.Length);
if (mask.Length > 0)
{
Mask = new int[Height * Width];
Array.Copy(mask, this.Mask, mask.Length);
}
else
{
Mask = new int[] { };
}

if (score.Length > 0)
{
Score = new float[Height * Width * Classes];
Array.Copy(score, this.Score, score.Length);
}
else
{
Score = new float[] { };
}
}

internal unsafe SegmentorOutput(CSegment* result)
{
Height = result->Height;
Width = result->Width;
Classes = result->Classes;
Mask = new int[Height * Width];
int nbytes = Height * Width * sizeof(int);
fixed (int* data = this.Mask)
if (result->Mask != null)
{
Mask = new int[Height * Width];

int nbytes = Height * Width * sizeof(int);
fixed (int* data = this.Mask)
{
Buffer.MemoryCopy(result->Mask, data, nbytes, nbytes);
}
}
else
{
Mask = new int[] { };
}

if (result->Score != null)
{
Score = new float[Height * Width * Classes];

int nbytes = Height * Width * Classes * sizeof(float);
fixed (float* data = this.Score)
{
Buffer.MemoryCopy(result->Score, data, nbytes, nbytes);
}
}
else
{
Buffer.MemoryCopy(result->Mask, data, nbytes, nbytes);
Score = new float[] { };
}
}
}
Expand Down
1 change: 1 addition & 0 deletions csrc/mmdeploy/apis/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/common.hpp
install(DIRECTORY ${CMAKE_SOURCE_DIR}/demo/csrc/ DESTINATION example/cpp
FILES_MATCHING
PATTERN "*.cxx"
PATTERN "*.h"
)
22 changes: 16 additions & 6 deletions csrc/mmdeploy/apis/python/segmentor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,22 @@ class PySegmentor {

std::vector<py::array> rets(mats.size());
for (size_t i = 0; i < mats.size(); ++i) {
rets[i] = {
{segm[i].height, segm[i].width}, // shape
segm[i].mask, // data
py::capsule(new Sptr(holder), // handle
[](void* p) { delete reinterpret_cast<Sptr*>(p); }) //
};
if (segm[i].mask != nullptr) {
rets[i] = {
{segm[i].height, segm[i].width}, // shape
segm[i].mask, // mask
py::capsule(new Sptr(holder), // handle
[](void* p) { delete reinterpret_cast<Sptr*>(p); }) //
};
}
if (segm[i].score != nullptr) {
rets[i] = {
{segm[i].classes, segm[i].height, segm[i].width}, // shape
segm[i].score, // score
py::capsule(new Sptr(holder), // handle
[](void* p) { delete reinterpret_cast<Sptr*>(p); }) //
};
}
}
return rets;
}
Expand Down
3 changes: 1 addition & 2 deletions csrc/mmdeploy/codebase/mmaction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ project(mmdeploy_mmaction)

file(GLOB SRCS ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
mmdeploy_add_module(${PROJECT_NAME} "${SRCS}")
add_subdirectory(cpu)
add_subdirectory(cuda)

target_link_libraries(${PROJECT_NAME} PRIVATE
mmdeploy_operation
mmdeploy_transform
Expand Down
15 changes: 0 additions & 15 deletions csrc/mmdeploy/codebase/mmaction/cpu/CMakeLists.txt

This file was deleted.

67 changes: 0 additions & 67 deletions csrc/mmdeploy/codebase/mmaction/cpu/format_shape_impl.cpp

This file was deleted.

18 changes: 0 additions & 18 deletions csrc/mmdeploy/codebase/mmaction/cuda/CMakeLists.txt

This file was deleted.

66 changes: 0 additions & 66 deletions csrc/mmdeploy/codebase/mmaction/cuda/format_shape_impl.cpp

This file was deleted.

Loading