Skip to content

Commit

Permalink
Update Java-side JNI
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jan 8, 2024
1 parent b1ce7ec commit 7fa0752
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ build
rknpu2
cmake_build
.gradle

bin
*.onnx
*.jar
4 changes: 1 addition & 3 deletions src/main/java/org/photonvision/rknn/RknnJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public RknnResult(
public static native long destroy(long ptr);

public static native RknnResult[] detect(
long detectorPtr, long blobNCHWPtr,
// letterbox config for rescaling output
int x_pad, int y_pad, float scale
long detectorPtr, long imagePtr
);
}
1 change: 1 addition & 0 deletions src/main/native/include/rkYolov5s.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define RKYOLOV5S_H

#include "rknn_api.h"
#include "postprocess.h"

#include "opencv2/core/core.hpp"

Expand Down
50 changes: 11 additions & 39 deletions src/test/java/org/photonvision/rknn/RknnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,49 +70,21 @@ public void testBasicBlobs() {
System.out.println(Core.getBuildInformation());
System.out.println(Core.OpenCLApiCallError);

long start, end;
start = System.currentTimeMillis();
var net = Dnn.readNetFromDarknet(
"/home/matt/Downloads/yolov4-csp-swish.cfg",
"/home/matt/Downloads/yolov4-csp-swish.weights");


end = System.currentTimeMillis();
System.out.println("Read (ms): " + (end - start));

System.out.println("Setting backends");

net.setPreferableBackend(Dnn.DNN_BACKEND_OPENCV);
net.setPreferableTarget(Dnn.DNN_TARGET_OPENCL);
// net.setPreferableBackend(Dnn.DNN_BACKEND_OPENCV);
// net.setPreferableTarget(Dnn.DNN_TARGET_CPU);
// net.setPreferableBackend(Dnn.DNN_BACKEND_CUDA);
// net.setPreferableTarget(Dnn.DNN_TARGET_CUDA);

System.out.println("Loading bus");
Mat img = Imgcodecs.imread("src/test/resources/bus.jpg");
System.out.println(img);

start = System.currentTimeMillis();
var blob = Dnn.blobFromImage(img, 1.0 / 255.0, new Size(640, 640));
end = System.currentTimeMillis();
System.out.println("Blob (ms): " + (end - start));
System.out.println("Loading rknn-jni");
System.load("/home/coolpi/rknn_java/cmake_build/librknn_jni.so");

for (int i = 0; i < 10; i++) {
start = System.currentTimeMillis();
net.setInput(blob);
end = System.currentTimeMillis();
System.out.println("SetInput (ms): " + (end - start));
List<Mat> result = new ArrayList<>();
var outBlobNames = getOutputNames(net);
System.out.println(outBlobNames);
start = System.currentTimeMillis();
net.forward(result, outBlobNames);
end = System.currentTimeMillis();
System.out.println("Forward (ms): " + (end - start));
// System.out.println(result.stream().map(Mat::dump).collect(Collectors.joining(", ")));
}
System.out.println("Creating detector");
long ptr = RknnJNI.create("/home/coolpi/rknn_java/src/test/resources/RK3588/yolov5s-640-640.rknn");

System.out.println("Running detector");
var ret = RknnJNI.detect(ptr, img.getNativeObjAddr());
System.out.println(Arrays.toString(ret));

img.release();
blob.release();
System.out.println("Killing detector");
RknnJNI.destroy(ptr);
}
}

0 comments on commit 7fa0752

Please sign in to comment.