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

JNA support for darknet #4560

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

JNA support for darknet #4560

wants to merge 7 commits into from

Conversation

peterdn1
Copy link

@peterdn1 peterdn1 commented Dec 20, 2019

Added support to access darknet from java:

network net = darknet.load_network_custom("./cfg/yolov3.cfg","./cfg/yolov3.weights",0,1);
metadata meta = darknet.get_metadata("./cfg/coco.data");
String[] names = meta.names.getStringArray(0, meta.classes);
image im = darknet.load_image_color("./data/dog.jpg",0,0);
IntByReference pnum = new IntByReference(0);
darknet.network_predict_image(net, im);
Pointer p =  darknet.get_network_boxes(net, im.w, im.h, thresh, hier_thresh,  new IntByReference(0), 0, pnum, 0);
int num = pnum.getValue();
detection det = new detection(p);
darknet.do_nms_sort(det, num, meta.classes, nms);
detection[] detections = (detection[])det.toArray(num);
for(int j=0;j<num;j++) {
   detection detect = detections[j];
   float[] probabilites = detect.prob.getFloatArray(0,meta.classes);
   for (int i = 0; i < meta.classes; i++) {
      if (probabilites[i] > 0) {
         String nameTag = names[i];
         out.println("name:"+nameTag+"("+probabilites[i]+")");
      }
   }
}
darknet.free_detections(p, num);
darknet.free_image(im);
int success = darknet.dispose();
        

@AlexeyAB
Copy link
Owner

@peterdn1 Thanks!

  • Should we have too much files?
  • Can you show screenshot of detection result console/window output?

@peterdn1
Copy link
Author

files:
darknet.h & yolo_v2_class.hpp dictate the file count. There are no additional classes with the exception of App and AppTest which illustrate the usage.
screenshot:
I'll post something shortly, have to run out.

@peterdn1
Copy link
Author

...
101 conv 128 1 x 1/ 1 52 x 52 x 256 -> 52 x 52 x 128 0.177 BF
102 conv 256 3 x 3/ 1 52 x 52 x 128 -> 52 x 52 x 256 1.595 BF
103 conv 128 1 x 1/ 1 52 x 52 x 256 -> 52 x 52 x 128 0.177 BF
104 conv 256 3 x 3/ 1 52 x 52 x 128 -> 52 x 52 x 256 1.595 BF
105 Try to load cfg: ./cfg/yolov3.cfg, weights: ./cfg/yolov3.weights, clear = 0
batch = 1, time_steps = 1, train = 0
conv 255 1 x 1/ 1 52 x 52 x 256 -> 52 x 52 x 255 0.353 BF
106 yolo
[yolo] params: iou loss: mse (2), iou_norm: 0.75, cls_norm: 1.00, scale_x_y: 1.00
Total BFLOPS 65.864
Loading weights from ./cfg/yolov3.weights...Done! Loaded 107 layers from weights-file
name:dog(0.99776953)
name:bicycle(0.9898728)
name:truck(0.9314567)

seen 64
Loaded - names_list: data/coco.names, classes = 80
Used AVX
Used FMA & AVX2

@peterdn1
Copy link
Author

Working on a better solution using javacpp vs jna

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants