darknet icon indicating copy to clipboard operation
darknet copied to clipboard

JNA support for darknet

Open peterdn1 opened this issue 4 years ago • 4 comments

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();
        

peterdn1 avatar Dec 20 '19 17:12 peterdn1

@peterdn1 Thanks!

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

AlexeyAB avatar Dec 20 '19 18:12 AlexeyAB

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 avatar Dec 20 '19 20:12 peterdn1

... 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 avatar Dec 25 '19 23:12 peterdn1

Working on a better solution using javacpp vs jna

peterdn1 avatar Dec 26 '19 22:12 peterdn1