Skip to content

Commit 34c6866

Browse files
[Sync] Sync Java API to master (#1856)
* sync rotated detector java api to master * sync mmseg score output to master * sync java docs for demo * sync java docs for master
1 parent 48291f0 commit 34c6866

28 files changed

+750
-45
lines changed

.github/scripts/test_java_demo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
'configs': [
4848
'https://media.githubusercontent.com/media/hanrui1sensetime/mmdeploy-javaapi-testdata/master/litehrnet.tar' # noqa: E501
4949
]
50+
},
51+
{
52+
'task':
53+
'RotatedDetection',
54+
'configs': [
55+
'https://media.githubusercontent.com/media/hanrui1sensetime/mmdeploy-javaapi-testdata/master/gliding-vertex.tar' # noqa: E501
56+
]
5057
}
5158
]
5259

csrc/mmdeploy/apis/java/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ add_jar(${PROJECT_NAME} SOURCES
2323
mmdeploy/TextRecognizer.java
2424
mmdeploy/Restorer.java
2525
mmdeploy/PoseDetector.java
26+
mmdeploy/RotatedDetector.java
2627
OUTPUT_NAME mmdeploy
2728
OUTPUT_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})

csrc/mmdeploy/apis/java/mmdeploy/Classifier.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,56 @@
11
package mmdeploy;
22

3+
/** @description: the Java API class of Classifier. */
34
public class Classifier {
45
static {
56
System.loadLibrary("mmdeploy_java");
67
}
78

89
private final long handle;
910

11+
/** @description: Single classification result of a picture. */
1012
public static class Result {
13+
14+
/** Class id. */
1115
public int label_id;
16+
17+
/** Class score. */
1218
public float score;
19+
20+
/** Initializes a new instance of the Result class.
21+
* @param label_id: class id.
22+
* @param score: class score.
23+
*/
1324
public Result(int label_id, float score) {
1425
this.label_id = label_id;
1526
this.score = score;
1627
}
1728
}
1829

19-
public Classifier(String modelPath, String deviceName, int deviceId) {
30+
/** Initializes a new instance of the Classifier class.
31+
* @param modelPath: model path.
32+
* @param deviceName: device name.
33+
* @param deviceId: device ID.
34+
* @exception Exception: create Classifier failed exception.
35+
*/
36+
public Classifier(String modelPath, String deviceName, int deviceId) throws Exception{
2037
handle = create(modelPath, deviceName, deviceId);
38+
if (handle == -1) {
39+
throw new Exception("Create Classifier failed!");
40+
}
2141
}
2242

23-
public Result[][] apply(Mat[] images) {
43+
/** Get label information of each image in a batch.
44+
* @param images: input mats.
45+
* @return: results of each input mat.
46+
* @exception Exception: apply Classifier failed exception.
47+
*/
48+
public Result[][] apply(Mat[] images) throws Exception{
2449
int[] counts = new int[images.length];
2550
Result[] results = apply(handle, images, counts);
51+
if (results == null) {
52+
throw new Exception("Apply Classifier failed!");
53+
}
2654
Result[][] rets = new Result[images.length][];
2755
int offset = 0;
2856
for (int i = 0; i < images.length; ++i) {
@@ -36,12 +64,22 @@ public Result[][] apply(Mat[] images) {
3664
return rets;
3765
}
3866

39-
public Result[] apply(Mat image) {
67+
/** Get label information of one image.
68+
* @param image: input mat.
69+
* @return: result of input mat.
70+
* @exception Exception: apply Classifier failed exception.
71+
*/
72+
public Result[] apply(Mat image) throws Exception{
4073
int[] counts = new int[1];
4174
Mat[] images = new Mat[]{image};
42-
return apply(handle, images, counts);
75+
Result[] results = apply(handle, images, counts);
76+
if (results == null) {
77+
throw new Exception("Apply Classifier failed!");
78+
}
79+
return results;
4380
}
4481

82+
/** Release the instance of Classifier. */
4583
public void release() {
4684
destroy(handle);
4785
}

csrc/mmdeploy/apis/java/mmdeploy/DataType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package mmdeploy;
22

3+
/** @description: DataType. */
34
public enum DataType {
45
FLOAT(0),
56
HALF(1),
67
INT8(2),
78
INT32(3);
89
final int value;
910

11+
/** Initializes a new instance of the DataType class.
12+
* @param value: the value.
13+
*/
1014
DataType(int value) {
1115
this.value = value;
1216
}

csrc/mmdeploy/apis/java/mmdeploy/Detector.java

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
package mmdeploy;
22

3+
/** @description: the Java API class of Detector. */
34
public class Detector {
45
static {
56
System.loadLibrary("mmdeploy_java");
67
}
78

89
private final long handle;
910

11+
/** @description: Single detection result of a picture. */
1012
public static class Result {
13+
14+
/** Bbox class id. */
1115
public int label_id;
16+
17+
/** Bbox score. */
1218
public float score;
19+
20+
/** Bbox coordinates. */
1321
public Rect bbox;
22+
23+
/** Bbox mask. */
1424
public InstanceMask mask;
25+
26+
/** Initializes a new instance of the Result class.
27+
* @param label_id: bbox class id.
28+
* @param score: bbox score.
29+
* @param bbox: bbox coordinates.
30+
* @param mask: bbox mask.
31+
*/
1532
public Result(int label_id, float score, Rect bbox, InstanceMask mask) {
1633
this.label_id = label_id;
1734
this.score = score;
@@ -20,13 +37,30 @@ public Result(int label_id, float score, Rect bbox, InstanceMask mask) {
2037
}
2138
}
2239

23-
public Detector(String modelPath, String deviceName, int deviceId) {
40+
/** Initializes a new instance of the Detector class.
41+
* @param modelPath: model path.
42+
* @param deviceName: device name.
43+
* @param deviceId: device ID.
44+
* @exception Exception: create Detector failed exception.
45+
*/
46+
public Detector(String modelPath, String deviceName, int deviceId) throws Exception {
2447
handle = create(modelPath, deviceName, deviceId);
48+
if (handle == -1) {
49+
throw new Exception("Create Detector failed!");
50+
}
2551
}
2652

27-
public Result[][] apply(Mat[] images) {
53+
/** Get information of each image in a batch.
54+
* @param images: input mats.
55+
* @return: results of each input mat.
56+
* @exception Exception: apply Detector failed exception.
57+
*/
58+
public Result[][] apply(Mat[] images) throws Exception {
2859
int[] counts = new int[images.length];
2960
Result[] results = apply(handle, images, counts);
61+
if (results == null) {
62+
throw new Exception("Apply Detector failed!");
63+
}
3064
Result[][] rets = new Result[images.length][];
3165
int offset = 0;
3266
for (int i = 0; i < images.length; ++i) {
@@ -40,12 +74,22 @@ public Result[][] apply(Mat[] images) {
4074
return rets;
4175
}
4276

43-
public Result[] apply(Mat image) {
77+
/** Get information of one image.
78+
* @param image: input mat.
79+
* @return: result of input mat.
80+
* @exception Exception: apply Detector failed exception.
81+
*/
82+
public Result[] apply(Mat image) throws Exception{
4483
int[] counts = new int[1];
4584
Mat[] images = new Mat[]{image};
46-
return apply(handle, images, counts);
85+
Result[] results = apply(handle, images, counts);
86+
if (results == null) {
87+
throw new Exception("Apply Detector failed!");
88+
}
89+
return results;
4790
}
4891

92+
/** Release the instance of Detector. */
4993
public void release() {
5094
destroy(handle);
5195
}

csrc/mmdeploy/apis/java/mmdeploy/InstanceMask.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
package mmdeploy;
22

3+
/** @description: InstanceMask. */
34
public class InstanceMask {
5+
6+
/** Mask shape. */
47
public int[] shape;
5-
public char[] data;
68

9+
/** Mask data. */
10+
public char[] data;
711

12+
/** Initialize a new instance of the InstanceMask class.
13+
* @param height: height.
14+
* @param width: width.
15+
* @param data: mask data.
16+
*/
817
public InstanceMask(int height, int width, char[] data) {
918
shape = new int[]{height, width};
1019
this.data = data;

csrc/mmdeploy/apis/java/mmdeploy/Mat.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
package mmdeploy;
22

3+
/** @description: Mat. */
34
public class Mat {
5+
6+
/** Shape. */
47
public int[] shape;
8+
9+
/** Pixel format. */
510
public int format;
11+
12+
/** Data type. */
613
public int type;
7-
public byte[] data;
814

15+
/** Mat data. */
16+
public byte[] data;
917

18+
/** Initialize a new instance of the Mat class.
19+
* @param height: height.
20+
* @param width: width.
21+
* @param channel: channel.
22+
* @param format: pixel format.
23+
* @param type: data type.
24+
* @param data: mat data.
25+
*/
1026
public Mat(int height, int width, int channel,
1127
PixelFormat format, DataType type, byte[] data) {
1228
shape = new int[]{height, width, channel};

csrc/mmdeploy/apis/java/mmdeploy/PixelFormat.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package mmdeploy;
22

3+
/** @description: PixelFormat. */
34
public enum PixelFormat {
45
BGR(0),
56
RGB(1),
@@ -9,6 +10,9 @@ public enum PixelFormat {
910
BGRA(5);
1011
final int value;
1112

13+
/** Initialize a new instance of the PixelFormat class.
14+
* @param value: the value.
15+
*/
1216
PixelFormat(int value) {
1317
this.value = value;
1418
}

csrc/mmdeploy/apis/java/mmdeploy/PointF.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package mmdeploy;
22

3+
/** @description: the PointF class. */
34
public class PointF {
5+
6+
/** x coordinate. */
47
public float x;
5-
public float y;
68

9+
/** y coordinate. */
10+
public float y;
711

12+
/** Initialize a new instance of the PointF class.
13+
* @param x: x coordinate.
14+
* @param y: y coordinate.
15+
*/
816
public PointF(float x, float y) {
917
this.x = x;
1018
this.y = y;

csrc/mmdeploy/apis/java/mmdeploy/PoseDetector.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,55 @@
11
package mmdeploy;
22

3+
/** @description: the Java API class of PoseDetector. */
34
public class PoseDetector {
45
static {
56
System.loadLibrary("mmdeploy_java");
67
}
78

89
private final long handle;
910

11+
/** @description: Single pose estimation result of a picture. */
1012
public static class Result {
13+
14+
/** Points. */
1115
public PointF[] point;
16+
17+
/** Scores of points */
1218
public float[] score;
19+
20+
/** Initializes a new instance of the Result class.
21+
* @param point: points.
22+
* @param score: scores of points.
23+
*/
1324
public Result(PointF[] point, float [] score) {
1425
this.point = point;
1526
this.score = score;
1627
}
1728
}
1829

19-
public PoseDetector(String modelPath, String deviceName, int deviceId) {
30+
/** Initializes a new instance of the PoseDetector class.
31+
* @param modelPath: model path.
32+
* @param deviceName: device name.
33+
* @param deviceId: device ID.
34+
* @exception Exception: create PoseDetector failed exception.
35+
*/
36+
public PoseDetector(String modelPath, String deviceName, int deviceId) throws Exception{
2037
handle = create(modelPath, deviceName, deviceId);
38+
if (handle == -1) {
39+
throw new Exception("Create PoseDetector failed!");
40+
}
2141
}
2242

23-
public Result[][] apply(Mat[] images) {
43+
/** Get information of each image in a batch.
44+
* @param images: input mats.
45+
* @return: results of each input mat.
46+
* @exception Exception: apply PoseDetector failed exception.
47+
*/
48+
public Result[][] apply(Mat[] images) throws Exception{
2449
Result[] results = apply(handle, images);
50+
if (results == null) {
51+
throw new Exception("Apply PoseDetector failed!");
52+
}
2553
Result[][] rets = new Result[images.length][];
2654
int offset = 0;
2755
for (int i = 0; i < images.length; ++i) {
@@ -33,11 +61,21 @@ public Result[][] apply(Mat[] images) {
3361
return rets;
3462
}
3563

36-
public Result[] apply(Mat image) {
64+
/** Get information of one image.
65+
* @param image: input mat.
66+
* @return: result of input mat.
67+
* @exception Exception: apply PoseDetector failed exception.
68+
*/
69+
public Result[] apply(Mat image) throws Exception{
3770
Mat[] images = new Mat[]{image};
38-
return apply(handle, images);
71+
Result[] results = apply(handle, images);
72+
if (results == null) {
73+
throw new Exception("Apply PoseDetector failed!");
74+
}
75+
return results;
3976
}
4077

78+
/** Release the instance of PoseDetector. */
4179
public void release() {
4280
destroy(handle);
4381
}

0 commit comments

Comments
 (0)