Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
887201f
move to dev-1.x
hanrui1sensetime Feb 16, 2023
6a1c0eb
fix wrong class name
hanrui1sensetime Feb 17, 2023
9d762cd
redesign Params argument mechanisms
hanrui1sensetime Feb 17, 2023
1912dbf
change demo build to ant
hanrui1sensetime Feb 21, 2023
7909d17
remove unused debugging file
hanrui1sensetime Feb 21, 2023
f67dce3
fix demo
hanrui1sensetime Feb 21, 2023
5762131
remove hardcode
hanrui1sensetime Feb 21, 2023
e6d69bc
a general build.xml
hanrui1sensetime Feb 21, 2023
8984dd9
update README
hanrui1sensetime Feb 21, 2023
1591b97
fix clang-format
hanrui1sensetime Feb 21, 2023
8d7fcbc
rename follow java format
hanrui1sensetime Feb 22, 2023
40bc152
update docs
hanrui1sensetime Feb 22, 2023
9a131fe
fix lint
hanrui1sensetime Feb 22, 2023
06d3658
fix java_api build
hanrui1sensetime Feb 22, 2023
901da07
fix ci
hanrui1sensetime Feb 22, 2023
f6ea1de
fix java api ci
hanrui1sensetime Feb 22, 2023
5684e79
fix lint
hanrui1sensetime Feb 22, 2023
4b13c93
fix opencv build privilege
hanrui1sensetime Feb 22, 2023
cb64b99
fix CI ant build
hanrui1sensetime Feb 22, 2023
f3b744f
remove opencv build because is too slow
hanrui1sensetime Feb 23, 2023
d5a5718
fix lib path
hanrui1sensetime Feb 23, 2023
45f2dfe
fix wrong dir
hanrui1sensetime Feb 23, 2023
543da7b
fix run demo location
hanrui1sensetime Feb 23, 2023
f774521
fix ant command
hanrui1sensetime Feb 23, 2023
feadaad
fix opencv
hanrui1sensetime Feb 23, 2023
93c745d
mv opencv to java demo
hanrui1sensetime Feb 23, 2023
a200ff7
fix CI
hanrui1sensetime Feb 24, 2023
22ab270
fix comments
hanrui1sensetime Feb 27, 2023
fb9e2eb
add absolute lib path in ci
hanrui1sensetime Feb 27, 2023
795370e
find lib
hanrui1sensetime Feb 27, 2023
5e13c44
find lib
hanrui1sensetime Feb 27, 2023
a6a7f4e
fix mmdeploy lib path in ci
hanrui1sensetime Feb 27, 2023
0dad098
fix pose ocr pose-tracker
hanrui1sensetime Feb 27, 2023
ed6407d
support RotatedDetection and Segmentation score
hanrui1sensetime Feb 27, 2023
c0d73aa
add cmake
hanrui1sensetime Feb 27, 2023
15c775e
fix lint
hanrui1sensetime Feb 27, 2023
498c9da
fix yapf
hanrui1sensetime Feb 27, 2023
d3fe845
fix clang-format
hanrui1sensetime Feb 27, 2023
bf118ef
fix clang-format
hanrui1sensetime Feb 27, 2023
0ad292f
fix java api ci
hanrui1sensetime Feb 27, 2023
4d5a2ae
fix ocr src pic
hanrui1sensetime Feb 27, 2023
6d4cbd1
add rotate
hanrui1sensetime Feb 27, 2023
1af7608
add opencv lib
hanrui1sensetime Feb 27, 2023
40c05af
fix lib
hanrui1sensetime Feb 27, 2023
1e8e2b5
fix libgstreamer missing
hanrui1sensetime Feb 27, 2023
a5f04d5
add libgstreamer-plugin
hanrui1sensetime Feb 27, 2023
96a058a
fix comments
hanrui1sensetime Feb 27, 2023
442566d
fix comments
hanrui1sensetime Feb 27, 2023
045e906
add avcodec for posetracker
hanrui1sensetime Feb 27, 2023
3ad4089
fix CI
hanrui1sensetime Feb 27, 2023
a1e53d3
fix java ci comments
hanrui1sensetime Feb 27, 2023
a675224
fix test_java_demo format
hanrui1sensetime Feb 27, 2023
934daf3
fix lint and ffmpeg missing
hanrui1sensetime Feb 28, 2023
207315f
fix comments
hanrui1sensetime Feb 28, 2023
4c2b205
a copy of array for java
hanrui1sensetime Feb 28, 2023
f9bb61e
fix demo stuck
hanrui1sensetime Feb 28, 2023
ed9dbc0
fix test_java_demo.py
hanrui1sensetime Feb 28, 2023
d31a6ca
fix popd and pushd
hanrui1sensetime Feb 28, 2023
b7b7823
fix java_api
hanrui1sensetime Feb 28, 2023
e1c7dd7
fix java api handle
hanrui1sensetime Feb 28, 2023
5ab264b
update for api
hanrui1sensetime Feb 28, 2023
9174328
add java docstrings for demo
hanrui1sensetime Feb 28, 2023
bf7a620
add docstring for posetracker java and fix handle
hanrui1sensetime Feb 28, 2023
812a2e5
add some java api docstrings
hanrui1sensetime Feb 28, 2023
16f511b
return ec
hanrui1sensetime Feb 28, 2023
54913ba
add error code for java
hanrui1sensetime Mar 1, 2023
06645c3
add all java docs
hanrui1sensetime Mar 1, 2023
e0933ca
fix clang-format
hanrui1sensetime Mar 1, 2023
54a6ab0
fix PoseTracker apply api for batch inference
hanrui1sensetime Mar 1, 2023
08c9c4f
merge latest dev-1.x
hanrui1sensetime Mar 1, 2023
dfe5daf
fix missing error code
hanrui1sensetime Mar 1, 2023
5f7d031
remove author
hanrui1sensetime Mar 1, 2023
52d8bbc
remove author
hanrui1sensetime Mar 1, 2023
de95a78
remove destroy window
hanrui1sensetime Mar 1, 2023
54602e6
fix wrong code
hanrui1sensetime Mar 1, 2023
7d72ae4
fix Context
hanrui1sensetime Mar 1, 2023
b20b236
fix java docs
hanrui1sensetime Mar 3, 2023
2b411b4
fix comments
hanrui1sensetime Mar 3, 2023
0ea4f8c
fix compile failed
hanrui1sensetime Mar 3, 2023
c22a54b
fix for and if format
hanrui1sensetime Mar 3, 2023
e14baef
fix error code
hanrui1sensetime Mar 3, 2023
bf94084
fix bracket
hanrui1sensetime Mar 6, 2023
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
51 changes: 38 additions & 13 deletions .github/scripts/test_java_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@
'configs': [
'https://media.githubusercontent.com/media/hanrui1sensetime/mmdeploy-javaapi-testdata/master/litehrnet.tar' # noqa: E501
]
},
{
'task':
'PoseTracker',
'configs': [
'https://media.githubusercontent.com/media/hanrui1sensetime/mmdeploy-javaapi-testdata/master/rtmdet-nano.tar', # noqa: E501
'https://media.githubusercontent.com/media/hanrui1sensetime/mmdeploy-javaapi-testdata/master/rtmpose-tiny.tar' # noqa: E501
]
},
{
'task':
'RotatedDetection',
'configs': [
'https://media.githubusercontent.com/media/hanrui1sensetime/mmdeploy-javaapi-testdata/master/gliding-vertex.tar' # noqa: E501
]
}
]

Expand All @@ -60,24 +75,34 @@ def main():
for params in PARAMS:
task = params['task']
configs = params['configs']
java_demo_cmd = [
'java', '-cp', 'csrc/mmdeploy/apis/java:demo/java',
'demo/java/' + task + '.java', 'cpu'
]
java_command = '\"cpu'
for config in configs:
model_url = config
os.system('wget {} && tar xvf {}'.format(model_url,
model_url.split('/')[-1]))
model_dir = model_url.split('/')[-1].split('.')[0]
java_demo_cmd.append(model_dir)
java_demo_cmd.append('/home/runner/work/mmdeploy/mmdeploy/demo' +
'/resources/human-pose.jpg')
java_demo_cmd_str = ' '.join(java_demo_cmd)
os.system('export JAVA_HOME=/home/runner/work/mmdeploy/mmdeploy/' +
'jdk-18 && export PATH=${JAVA_HOME}/bin:${PATH} && java' +
' --version && export LD_LIBRARY_PATH=/home/runner/work/' +
'mmdeploy/mmdeploy/build/lib:${LD_LIBRARY_PATH} && ' +
java_demo_cmd_str)
java_command += (' ' + model_dir)
if task in [
'ImageClassification', 'ObjectDetection', 'ImageSegmentation',
'ImageRestorer', 'PoseDetection', 'RotatedDetection'
]:
java_command += (' $GITHUB_WORKSPACE/demo' +
'/resources/human-pose.jpg\"')
elif task in ['Ocr']:
java_command += (' $GITHUB_WORKSPACE/demo' +
'/resources/text_det.jpg\"')
elif task in ['PoseTracker']:
os.system(
'wget https://media.githubusercontent.com/media/hanrui1sensetime/mmdeploy-javaapi-testdata/master/dance.mp4' # noqa: E501
)
java_command += ' dance.mp4\"'
else:
java_command += '\"'
print(f'java_command: {java_command}')
os.system('ant -DtaskName=' + task +
' -DjarDir=${OPENCV_DIR}/build/bin ' +
'-DlibDir=${OPENCV_DIR}/build/lib:$GITHUB_WORKSPACE/' +
'build/lib -Dcommand=' + java_command)


if __name__ == '__main__':
Expand Down
45 changes: 26 additions & 19 deletions .github/workflows/java_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,45 @@ jobs:
run: |
wget https://download.java.net/java/GA/jdk18/43f95e8614114aeaa8e8a5fcf20a682d/36/GPL/openjdk-18_linux-x64_bin.tar.gz
tar xvf openjdk-18_linux-x64_bin.tar.gz
- name: gcc-multilib
run: sudo apt install gcc-multilib g++-multilib wget libprotobuf-dev protobuf-compiler
export JAVA_HOME=${PWD}/jdk-18
export PATH=${JAVA_HOME}/bin:${PATH}
- name: Install onnxruntime
run: |
wget https://github.com/microsoft/onnxruntime/releases/download/v1.8.1/onnxruntime-linux-x64-1.8.1.tgz
tar -zxvf onnxruntime-linux-x64-1.8.1.tgz
pushd onnxruntime-linux-x64-1.8.1
export ONNXRUNTIME_DIR=${PWD}
export ONNXRUNTIME_DIR=${PWD}/onnxruntime-linux-x64-1.8.1
export LD_LIBRARY_PATH=$ONNXRUNTIME_DIR/lib:$LD_LIBRARY_PATH
popd
- name: Install opencv
- name: Install OpenCV
run: |
sudo apt-get install libopencv-dev
- name: Build java class
sudo apt-get install ffmpeg libgstreamer1.0-0 libgstreamer-plugins-base1.0-0 libavcodec-dev libavformat-dev libswscale-dev
- name: Install ant
run: |
sudo apt-get install ant
- name: Build Java class
run: |
pushd csrc/mmdeploy/apis/java
javac mmdeploy/*.java
popd
pushd demo/java
javac -classpath ../../csrc/mmdeploy/apis/java/ Utils.java
popd
- name: Install mmdeploy with onnxruntime backend and java api
- name: Install mmdeploy with onnxruntime backend and Java API
run: |
mkdir -p build && pushd build
export LD_LIBRARY_PATH=/home/runner/work/mmdeploy/mmdeploy/ncnn/install/lib/:$LD_LIBRARY_PATH
cmake -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_BUILD_SDK_JAVA_API=ON -DMMDEPLOY_TARGET_BACKENDS=ort -DMMDEPLOY_CODEBASES=all -DONNXRUNTIME_DIR=~/work/mmdeploy/mmdeploy/onnxruntime-linux-x64-1.8.1 ..
make install
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/onnxruntime-linux-x64-1.8.1/lib/:$LD_LIBRARY_PATH
cmake -DMMDEPLOY_BUILD_SDK=ON -DMMDEPLOY_BUILD_SDK_JAVA_API=ON -DMMDEPLOY_TARGET_BACKENDS=ort -DMMDEPLOY_CODEBASES=all -DONNXRUNTIME_DIR=$GITHUB_WORKSPACE/onnxruntime-linux-x64-1.8.1 ..
make -j$(nproc) && make install
popd
- name: Test javademo
- name: Prepare OpenCV Java and test Java demo
run: |
export JAVA_HOME=${PWD}/jdk-18
export PATH=${JAVA_HOME}/bin:${PATH}
export LD_LIBRARY_PATH=/build/lib:${LD_LIBRARY_PATH}
java --version
export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}
export JAVA_AWT_LIBRARY=${JAVA_HOME}
export JAVA_INCLUDE_PATH=${JAVA_HOME}/include
export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/darwin
export JAVA_JVM_LIBRARY=${JAVA_HOME}

mkdir -p opencv/build/bin
wget https://media.githubusercontent.com/media/hanrui1sensetime/mmdeploy-javaapi-testdata/master/opencv-470.jar -P opencv/build/bin
wget https://media.githubusercontent.com/media/hanrui1sensetime/mmdeploy-javaapi-testdata/master/opencv470-lib.tar -P opencv/build
tar -xf opencv/build/opencv470-lib.tar -C opencv/build
export OPENCV_DIR=$GITHUB_WORKSPACE/opencv
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/build/lib:${OPENCV_DIR}/build/lib:$LD_LIBRARY_PATH
python .github/scripts/test_java_demo.py
7 changes: 7 additions & 0 deletions csrc/mmdeploy/apis/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,12 @@ add_jar(${PROJECT_NAME} SOURCES
mmdeploy/TextRecognizer.java
mmdeploy/Restorer.java
mmdeploy/PoseDetector.java
mmdeploy/Context.java
mmdeploy/Device.java
mmdeploy/Model.java
mmdeploy/Profiler.java
mmdeploy/Scheduler.java
mmdeploy/PoseTracker.java
mmdeploy/RotatedDetector.java
OUTPUT_NAME mmdeploy
OUTPUT_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
4 changes: 2 additions & 2 deletions csrc/mmdeploy/apis/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export JAVA_HOME=${PWD}/jdk-18
export PATH=${JAVA_HOME}/bin:${PATH}
```

**Step 3.** Switch default Java version:
**Step 3.** Switch default Java version(optional):

```bash
sudo update-alternatives --config java
sudo update-alternatives --config javac
```

You should select the version you will use.
If you have multiple Java versions, you should select the version you will use.

### Installation

Expand Down
46 changes: 42 additions & 4 deletions csrc/mmdeploy/apis/java/mmdeploy/Classifier.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
package mmdeploy;

/** @description: the Java API class of Classifier. */
public class Classifier {
static {
System.loadLibrary("mmdeploy_java");
}

private final long handle;

/** @description: Single classification result of a picture. */
public static class Result {

/** Class id. */
public int label_id;

/** Class score. */
public float score;

/** Initializes a new instance of the Result class.
* @param label_id: class id.
* @param score: class score.
*/
public Result(int label_id, float score) {
this.label_id = label_id;
this.score = score;
}
}

public Classifier(String modelPath, String deviceName, int deviceId) {
/** Initializes a new instance of the Classifier class.
* @param modelPath: model path.
* @param deviceName: device name.
* @param deviceId: device ID.
* @exception Exception: create Classifier failed exception.
*/
public Classifier(String modelPath, String deviceName, int deviceId) throws Exception{
handle = create(modelPath, deviceName, deviceId);
if (handle == -1) {
throw new Exception("Create Classifier failed!");
}
}

public Result[][] apply(Mat[] images) {
/** Get label information of each image in a batch.
* @param images: input mats.
* @return: results of each input mat.
* @exception Exception: apply Classifier failed exception.
*/
public Result[][] apply(Mat[] images) throws Exception{
int[] counts = new int[images.length];
Result[] results = apply(handle, images, counts);
if (results == null) {
throw new Exception("Apply Classifier failed!");
}
Result[][] rets = new Result[images.length][];
int offset = 0;
for (int i = 0; i < images.length; ++i) {
Expand All @@ -36,12 +64,22 @@ public Result[][] apply(Mat[] images) {
return rets;
}

public Result[] apply(Mat image) {
/** Get label information of one image.
* @param image: input mat.
* @return: result of input mat.
* @exception Exception: apply Classifier failed exception.
*/
public Result[] apply(Mat image) throws Exception{
int[] counts = new int[1];
Mat[] images = new Mat[]{image};
return apply(handle, images, counts);
Result[] results = apply(handle, images, counts);
if (results == null) {
throw new Exception("Apply Classifier failed!");
}
return results;
}

/** Release the instance of Classifier. */
public void release() {
destroy(handle);
}
Expand Down
74 changes: 74 additions & 0 deletions csrc/mmdeploy/apis/java/mmdeploy/Context.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

package mmdeploy;

/** @description: the Context class. */
public class Context {
static {
System.loadLibrary("mmdeploy_java");
}

private final long contextHandle;

/** @description: ContextType. */
public enum ContextType {
DEVICE,
STREAM,
MODEL,
SCHEDULER,
MAT,
PROFILER
}

/** Initializes a new instance of the Context class. */
public Context() {
contextHandle = create();
}

/** Add Model to the Context.
* @param name: name.
* @param model: model.
*/
public void add(String name, Model model) {
add(contextHandle, ContextType.MODEL.ordinal(), name, model.handle());
}

/** Add Scheduler to the Context.
* @param name: name.
* @param scheduler: scheduler.
*/
public void add(String name, Scheduler scheduler) {
add(contextHandle, ContextType.SCHEDULER.ordinal(), name, scheduler.handle());
}

/** Add Device to the Context.
* @param device: device.
*/
public void add(Device device) {
add(contextHandle, ContextType.DEVICE.ordinal(), "", device.handle());
}

/** Add Profiler to the Context.
* @param profiler: profiler.
*/
public void add(Profiler profiler) {
add(contextHandle, ContextType.PROFILER.ordinal(), "", profiler.handle());
}

/** Release the instance of Context. */
public void release() {
destroy(contextHandle);
}

/** Get the handle of Context
* @return: the handle of context.
*/
public long handle() {
return contextHandle;
}

private native long create();

public native int add(long context, int contextType, String name, long handle);

private native void destroy(long context);
}
4 changes: 4 additions & 0 deletions csrc/mmdeploy/apis/java/mmdeploy/DataType.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package mmdeploy;

/** @description: DataType. */
public enum DataType {
FLOAT(0),
HALF(1),
INT8(2),
INT32(3);
final int value;

/** Initializes a new instance of the DataType class.
* @param value: the value.
*/
DataType(int value) {
this.value = value;
}
Expand Down
Loading