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

TranslatorFactory for yolov8 #2753

Closed
SidneyLann opened this issue Aug 17, 2023 · 9 comments
Closed

TranslatorFactory for yolov8 #2753

SidneyLann opened this issue Aug 17, 2023 · 9 comments
Labels
enhancement New feature or request

Comments

@SidneyLann
Copy link
Contributor

  String onnxFile = "D:\\Sidney\\dev\\ai\\action\\po2\\bestn.onnx";
  Criteria<Image, DetectedObjects> criteria = Criteria.builder().setTypes(Image.class, DetectedObjects.class).optModelPath(Paths.get(onnxFile)).optEngine("OnnxRuntime")
      .optTranslatorFactory(new YoloV5TranslatorFactory()).optProgress(new ProgressBar()).build();

  Path imagePaths = Paths.get("D:\\Sidney\\dev\\ai\\action\\po2\\images\\val");
  Image img = null;
  DetectedObjects detection = null;
  try (ZooModel<Image, DetectedObjects> model = criteria.loadModel()) {
    try (Predictor<Image, DetectedObjects> predictor = model.newPredictor()) {
      String outputDir = "c:/output";
      Path outputPath = Paths.get(outputDir);
      Files.createDirectories(outputPath);

      List<File> imageFiles = Files.list(imagePaths).map(Path::toFile).collect(Collectors.toList());
      for (File imageFile : imageFiles) {
        img = ImageFactory.getInstance().fromFile(imageFile.toPath()).resize(640, 384, false);
        detection = predictor.predict(img);
        if(detection.getNumberOfObjects()>0)
        saveBoundingBoxImage(img, detection, outputPath, imageFile.getName());
      }
    }
  }

Can YoloV5TranslatorFactory.java be used here? Or need to implements YoloV8TranslatorFactory?
Many objects can be detected in python, but no one object can be detected in DJL. problem in YoloV5TranslatorFactory or data preprocess? Thanks.

@SidneyLann SidneyLann added the enhancement New feature or request label Aug 17, 2023
@KexinFeng
Copy link
Contributor

I assume YoloV8TranslatorFactory would be very similar and parallel to YoloV5TranslatorFactory. But the current YoloV5TranslatorFactory is not guaranteed to be used for YoloV8TranslatorFactory out-of-box.

But the good news is that as long as YoloV8 has a onnx model, then we can load it into DJL with OnnxRuntime engine.

You can maybe take a look at PR #2452 , which contains a simple testing example, and see if you can try to build a YoloV8Translator from YoloV5Translator?

@SidneyLann
Copy link
Contributor Author

SidneyLann commented Aug 17, 2023

String onnxFile = "D:\Sidney\dev\ai\action\pp\bestn.onnx";
YoloV5TranslatorFactory yoloV5TranslatorFactory=new YoloV5TranslatorFactory();
Map<String, Object> arguments = new HashMap<>();
arguments.put("width", Integer.valueOf(640));
arguments.put("height", Integer.valueOf(384));
arguments.put("resize", "true");
arguments.put("normalize", "true");
arguments.put("range", "0,1");

  Translator<Image, DetectedObjects> translator =
      yoloV5TranslatorFactory.newInstance(Image.class, DetectedObjects.class, null, arguments);
  
  Criteria<Image, DetectedObjects> criteria = Criteria.builder().setTypes(Image.class, DetectedObjects.class).optModelPath(Paths.get(onnxFile)).optEngine("OnnxRuntime")
      .optTranslator(translator).optProgress(new ProgressBar()).build();

  Path imagePaths = Paths.get("D:\\Sidney\\dev\\ai\\action\\pp\\images\\val");
  Image img = null;
  DetectedObjects detectedObjects = null;
  DetectedObject detectedObject= null;
  try (ZooModel<Image, DetectedObjects> model = criteria.loadModel()) {
    try (Predictor<Image, DetectedObjects> predictor = model.newPredictor()) {
      String outputDir = "c:/output";
      Path outputPath = Paths.get(outputDir);
      Files.createDirectories(outputPath);

      List<File> imageFiles = Files.list(imagePaths).map(Path::toFile).collect(Collectors.toList());
      for (File imageFile : imageFiles) {
        img = ImageFactory.getInstance().fromFile(imageFile.toPath());
        detectedObjects = predictor.predict(img);
        if (detectedObjects.getNumberOfObjects() > 0) {
          List<DetectedObject> detectedObjectList=detectedObjects.items();
          System.out.println(detectedObjects.getProbabilities().size());
          for(int i=0;i<detectedObjectList.size();i++) {
            detectedObject= detectedObjectList.get(i);
            BoundingBox boundingBox=detectedObject.getBoundingBox();
            Rectangle tectangle =boundingBox.getBounds();
            System.out.println(detectedObject.getClassName()+" "+detectedObject.getProbability()+" "+tectangle.getX()+" "+tectangle.getY()+" "+tectangle.getWidth()+" "+tectangle.getHeight());
          }
          saveBoundingBoxImage(img.resize(640, 384, false), detectedObjects, outputPath, imageFile.getName());
      }}
    }
  }

///////////////////////////////////////////////////////////////////////////////////////////////////////
[Console output redirected to file:d:\tmp\piano.log]
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Loading: 100% |========================================|
168
1101 98215.5625 147.8451385498047 152.38482666015625 335.2650451660156 337.0516357421875
6101 116840.2578125 210.1641082763672 59.78143310546875 184.53189086914062 313.253662109375
1102 16448.390625 44.30443572998047 42.880882263183594 83.7625732421875 81.66737365722656
6102 386294.71875 274.3291015625 278.81298828125 590.912109375 602.07275390625
6102 40795.96484375 117.1582260131836 100.69036102294922 182.1123809814453 191.9515838623047
1202 3978.54638671875 29.899276733398438 29.993698120117188 59.986480712890625 59.908355712890625
6202 262835.0 114.3702392578125 130.22569274902344 367.25372314453125 401.2523498535156
6202 2263.206787109375 18.660690307617188 19.020538330078125 40.581756591796875 41.01812744140625
1203 9143.3759765625 46.625640869140625 44.54292297363281 90.81072998046875 92.56790161132812
6203 317823.125 195.13848876953125 201.73971557617188 468.0616455078125 488.53912353515625
1303 359309.5625 258.59033203125 262.19183349609375 547.66015625 555.5531005859375
1303 6269.8447265625 40.307647705078125 37.7308349609375 70.359130859375 69.97283935546875
1303 2714.390380859375 17.29840850830078 16.062667846679688 32.44288635253906 32.2122802734375
6303 12021.939453125 51.42240905761719 44.58129119873047 104.13627624511719 104.86595153808594
1304 142634.828125 171.81094360351562 152.69210815429688 325.95013427734375 362.0706787109375
6304 283671.84375 171.0950927734375 179.2879638671875 417.1187744140625 435.0386962890625
6304 55548.81640625 130.33370971679688 106.650634765625 212.4818115234375 216.76708984375
1305 37618.61328125 86.05056762695312 102.8802490234375 201.54449462890625 194.71633911132812
1305 5896.76806640625 30.272552490234375 28.752883911132812 68.5513916015625 71.28060913085938
6305 30727.5078125 76.57994079589844 79.39740753173828 170.46273803710938 170.88121032714844
6305 9227.9677734375 44.434356689453125 47.188514709472656 90.02413940429688 86.18234252929688
6305 6775.572265625 33.59878921508789 32.641944885253906 69.84131622314453 71.93928527832031
6305 4692.787109375 14.688036918640137 0.0 4.848901271820068 17.442794799804688
1401 5141.904296875 28.551025390625 38.826751708984375 66.831298828125 60.20648193359375
6401 240008.28125 141.32028198242188 148.61065673828125 348.297607421875 363.63031005859375
2101 314010.9375 221.541259765625 223.27256774902344 471.95855712890625 481.3890686035156
2101 23943.013671875 73.91975402832031 76.5525131225586 157.52178955078125 156.55955505371094
2101 5556.31884765625 38.912445068359375 19.25274658203125 61.42584228515625 77.2127685546875
7101 313129.4375 221.9288330078125 226.21908569335938 475.714111328125 483.53533935546875
7101 95357.484375 149.04412841796875 150.4227294921875 299.18756103515625 298.57342529296875
7101 7483.9921875 41.431007385253906 40.52752685546875 79.98027038574219 79.9599609375
7102 28240.74609375 71.84848022460938 70.06723022460938 157.90838623046875 165.78143310546875
7102 6271.8974609375 32.65247344970703 23.973918914794922 63.42637634277344 68.43657684326172
2202 297300.78125 209.9079132080078 212.25152587890625 451.8796691894531 461.93670654296875
2202 4984.8681640625 34.66107177734375 30.16638946533203 57.891357421875 58.38160705566406
7202 294579.5 204.71170043945312 202.62744140625 439.772705078125 454.097900390625
7202 71039.2109375 128.50552368164062 128.24508666992188 257.1578369140625 257.49359130859375
7202 15705.9755859375 40.15043640136719 64.76043701171875 115.59994506835938 96.944580078125
7202 7641.56982421875 55.294586181640625 32.97624206542969 74.67070007324219 85.53976440429688
7202 6215.37353515625 28.373504638671875 29.802963256835938 66.4765625 69.33547973632812
2203 13378.8173828125 54.15361022949219 62.416290283203125 111.20364379882812 99.876220703125
2203 5986.80908203125 20.865402221679688 24.82175064086914 48.661842346191406 47.53596496582031
7203 18677.82421875 60.46846008300781 70.55877685546875 112.23110961914062 107.182373046875
2301 275941.40625 189.49815368652344 200.97525024414062 423.6600646972656 428.55841064453125
2301 4629.57958984375 34.651702880859375 34.235015869140625 61.651611328125 60.18756103515625
2301 965.818115234375 12.582088470458984 12.706926345825195 24.997955322265625 24.775257110595703
7301 272261.59375 188.10018920898438 193.98904418945312 414.23846435546875 421.6287841796875
7301 52886.12109375 110.38059997558594 110.37429809570312 220.96832275390625 221.131103515625
7301 5711.09912109375 33.502685546875 33.5269775390625 67.19427490234375 66.91888427734375
7301 3034.154541015625 17.82974624633789 18.478221893310547 39.486061096191406 40.172325134277344
2303 252636.546875 103.32244873046875 125.6094970703125 342.59423828125 371.012451171875
7303 7752.11083984375 39.92100524902344 40.89105224609375 80.74142456054688 80.10406494140625
2304 259770.9375 179.68296813964844 181.85968017578125 386.6927795410156 395.83544921875
7304 251823.25 174.13241577148438 177.9256134033203 379.3162841796875 387.3774108886719
7304 7282.56298828125 28.792694091796875 28.96087646484375 69.75213623046875 77.0509033203125
7304 3693.946533203125 22.27899169921875 22.211410522460938 44.53997802734375 44.766387939453125
2305 88649.9453125 17.862403869628906 26.012893676757812 113.82383728027344 128.47442626953125
2305 7563.74853515625 39.48890686035156 38.16645812988281 73.61453247070312 73.83895874023438
2401 236114.265625 161.82318115234375 165.89004516601562 355.65728759765625 363.5167236328125
7401 230146.4375 157.01519775390625 160.7734375 344.947998046875 352.938720703125
7401 19838.396484375 63.65514373779297 64.80117797851562 131.0018768310547 130.75927734375
7401 7303.8779296875 29.691246032714844 34.01777648925781 77.56315612792969 79.5323486328125
3101 115205.171875 164.76083374023438 163.98162841796875 328.58599853515625 329.1468505859375
3101 45821.83984375 0.0 13.371261596679688 51.8490104675293 62.675323486328125
8101 5265.912109375 1.4363861083984375 13.8868408203125 71.57455444335938 57.42742919921875
8102 214072.90625 136.41204833984375 139.9244384765625 308.1605224609375 319.79559326171875
8102 12529.248046875 50.6685676574707 50.04887771606445 100.70948028564453 101.6017074584961
8102 8099.439453125 32.770416259765625 35.82740783691406 82.03179931640625 83.9791259765625
3202 207290.390625 141.78750610351562 145.41053771972656 311.44720458984375 318.3143615722656
3202 12172.2802734375 64.37933349609375 62.28108215332031 126.87832641601562 117.49752807617188
8202 4253.07080078125 44.14555358886719 31.311790466308594 51.014556884765625 50.87278747558594
8203 189041.78125 124.27214050292969 127.47164916992188 281.9411926269531 290.93963623046875
8203 2876.26123046875 19.04281234741211 19.832712173461914 39.319068908691406 40.13962936401367
3301 180678.515625 125.8087158203125 124.30485534667969 264.5020751953125 272.2425842285156
8301 16188.1357421875 67.12649536132812 95.04817962646484 138.34115600585938 97.66090393066406
3303 8175.2978515625 39.23283386230469 41.144371032714844 77.59115600585938 75.84382629394531
8303 172368.28125 109.7020263671875 114.35542297363281 257.69287109375 265.3564453125
8303 5953.60693359375 40.027130126953125 39.93363952636719 75.34857177734375 73.38180541992188
8303 730.9758911132812 5.239337921142578 7.767597198486328 18.886585235595703 19.409664154052734
8303 635.2780151367188 3.0897974967956543 3.709045886993408 9.688847541809082 9.875330924987793
3304 164575.5625 104.45686340332031 109.9067611694336 246.46566772460938 253.8174285888672
3304 7637.328125 28.259822845458984 31.521224975585938 69.80706787109375 70.47393798828125
8304 9162.044921875 53.87942886352539 30.014915466308594 70.8334732055664 84.47920227050781
8304 1473.586669921875 47.300689697265625 49.955780029296875 44.95745849609375 44.72650146484375
3305 6636.80322265625 34.65693664550781 41.25286865234375 80.78216552734375 78.21559143066406
8305 150079.96875 98.11840057373047 101.49710083007812 222.6272430419922 229.40655517578125
3401 144440.78125 91.09120178222656 96.19515228271484 212.21035766601562 218.6002960205078
8401 14953.6591796875 0.0 0.0 86.03743743896484 95.22124481201172
8401 9994.861328125 20.327640533447266 34.948448181152344 82.16143798828125 87.00386047363281
4101 137907.390625 182.42788696289062 182.59768676757812 365.75543212890625 365.92877197265625
9101 130247.5390625 77.14749145507812 80.87632751464844 187.81353759765625 196.48080444335938
4102 122277.7890625 70.98690795898438 73.85585021972656 174.888427734375 183.64865112304688
4102 17560.728515625 60.91632843017578 62.34377670288086 122.27397155761719 121.47161102294922
4102 5821.11865234375 35.57432556152344 34.316551208496094 63.8631591796875 63.10667419433594
9102 109338.8203125 162.6364288330078 163.3597412109375 323.0280456542969 320.830810546875
9102 7788.28759765625 37.38465881347656 35.211761474609375 73.81393432617188 75.5732421875
4202 82174.578125 114.83905029296875 128.43618774414062 274.649169921875 275.2449951171875
4202 6618.37109375 42.284278869628906 44.62847900390625 75.26777648925781 68.32098388671875
9202 9618.07421875 48.8526611328125 49.58343505859375 96.80499267578125 92.84796142578125
9202 6420.47509765625 42.7266845703125 35.65081024169922 63.582672119140625 64.82804870605469
4203 105699.4296875 58.07635498046875 63.3065185546875 151.1556396484375 159.74209594726562
4203 10855.904296875 43.195499420166016 48.09344482421875 98.5244369506836 97.79507446289062
4203 5339.259765625 39.894287109375 32.97991943359375 61.81646728515625 64.39752197265625
9203 101695.0 53.8968505859375 57.76036071777344 142.06326293945312 150.97561645507812
9203 83160.34375 139.2407684326172 138.04281616210938 274.8689270019531 274.8660888671875
4301 16444.04296875 53.24615478515625 54.77775573730469 115.87847900390625 117.34841918945312
4303 85244.6640625 46.42315673828125 42.38514709472656 111.05322265625 124.09326171875
4303 73931.3046875 125.09370422363281 122.95079040527344 245.17160034179688 245.95730590820312
4303 5306.89892578125 35.52977752685547 32.58478546142578 65.97305297851562 66.42413330078125
4303 2439.635498046875 20.67487144470215 18.837400436401367 38.72616958618164 39.39303970336914
9303 77775.484375 36.825927734375 41.380409240722656 106.07298278808594 113.88624572753906
9303 63368.62890625 123.16960144042969 122.33059692382812 243.93038940429688 243.66439819335938
9303 6777.21337890625 29.64177894592285 27.752708435058594 62.775394439697266 66.31255340576172
4304 44869.9375 87.53663635253906 66.10020446777344 187.85678100585938 204.002685546875
9304 157.4344482421875 1.9399828910827637 2.32932186126709 5.070935249328613 4.915416717529297
4305 65512.15234375 20.584476470947266 26.545284271240234 86.54058074951172 96.10993194580078
9305 58045.4296875 13.54269027709961 20.18987274169922 74.44855499267578 84.95414733886719
9305 45504.21484375 102.0096206665039 101.83024597167969 202.38853454589844 201.87237548828125
4401 106772.078125 38.54497528076172 50.44758605957031 142.9111328125 156.20645141601562
9401 3902.997314453125 18.09246826171875 19.579429626464844 44.09600830078125 45.80436706542969
5101 39646.9375 14.172443389892578 15.269256591796875 45.82539367675781 52.875518798828125
0101 35670.9453125 4.48951530456543 12.665992736816406 43.29590606689453 48.14234924316406
0101 11855.921875 38.43236541748047 32.03849792480469 85.23521423339844 97.36111450195312
0101 1334.690673828125 12.848799705505371 12.325035095214844 24.141542434692383 24.630836486816406
5102 126091.671875 175.36807250976562 175.53366088867188 351.7357177734375 351.82623291015625
5102 62265.83984375 9.797325134277344 16.973243713378906 72.37155151367188 83.92231750488281
5102 9253.8017578125 51.364505767822266 58.449066162109375 113.65032196044922 94.24716186523438
0102 131285.734375 180.4215087890625 180.1843719482422 356.068115234375 355.0991516113281
5202 31267.564453125 81.14930725097656 80.59133911132812 161.27667236328125 161.84765625
5202 23571.591796875 0.0 9.206356048583984 28.743385314941406 32.455650329589844
5202 11697.9853515625 44.13981246948242 44.753662109375 88.73847198486328 87.69964599609375
0202 22415.51171875 53.60867691040039 64.35173797607422 106.0537338256836 96.97416687011719
0202 19757.697265625 632.2952880859375 0.0 8.36941909790039 26.709577560424805
0202 5478.63037109375 49.6656494140625 51.16161346435547 78.21846008300781 69.01701354980469
5203 108174.59375 162.96841430664062 168.35775756835938 324.30096435546875 321.66375732421875
5203 31197.74609375 612.5068969726562 613.9754028320312 13.053628921508789 41.54417037963867
5203 8175.6064453125 37.3165283203125 44.16563415527344 90.134521484375 89.19180297851562
0203 30339.927734375 87.04364013671875 88.92561340332031 175.0826416015625 172.7474365234375
0203 18156.958984375 44.05757141113281 69.21311950683594 137.22109985351562 131.44680786132812
5301 26450.330078125 82.29298400878906 25.825469970703125 94.15502166748047 121.5526123046875
5301 7568.5048828125 35.525238037109375 26.13189697265625 83.51852416992188 94.12673950195312
0301 404089.3125 296.9132080078125 302.4346008300781 618.924560546875 630.9454956054688
0301 8215.021484375 35.28199005126953 37.81346130371094 74.54585266113281 79.48701477050781
5303 402297.59375 293.6337890625 296.53741455078125 610.078369140625 617.5096435546875
5303 81459.359375 128.78688049316406 127.42193603515625 266.3962097167969 266.9871826171875
5303 334.4308166503906 3.089599609375 3.113525390625 6.244873046875 6.2425537109375
0303 22411.349609375 6.324226379394531 0.33084869384765625 97.45577239990234 129.75839233398438
0303 5450.76318359375 25.183700561523438 24.94216537475586 47.96571350097656 47.54546356201172
5304 3189.866943359375 44.595367431640625 33.92900848388672 6.55499267578125 6.678116321563721
5304 1975.342529296875 16.588430404663086 17.05747413635254 35.17860794067383 35.49452590942383
0304 19806.953125 72.61959838867188 51.669952392578125 128.4718017578125 135.68295288085938
5305 381029.5625 271.92095947265625 276.63653564453125 582.4674072265625 591.5345458984375
5305 56409.89453125 116.20013427734375 117.1220703125 227.790283203125 224.74114990234375
5305 5512.302734375 31.206192016601562 30.630126953125 61.252777099609375 62.19940185546875
0305 12571.0537109375 54.629676818847656 54.618614196777344 107.90257263183594 108.46583557128906
5401 53118.30859375 105.25183868408203 104.48748779296875 207.4582977294922 206.43429565429688
5401 4049.44091796875 5.584625244140625 5.7151641845703125 12.079345703125 12.108795166015625
0401 363111.0625 258.7774353027344 267.6424560546875 555.5056762695312 563.429931640625
A281 39648.2421875 92.9392318725586 91.62850952148438 183.07032775878906 183.93548583984375
A282 302369.4375 190.95578002929688 197.70700073242188 444.48333740234375 460.87591552734375
a282 343904.4375 244.37408447265625 248.784912109375 521.432373046875 529.5565185546875
B281 338240.6875 241.39166259765625 245.920166015625 515.5184326171875 523.2781982421875
B281 22576.689453125 73.27664947509766 73.5392074584961 143.44676208496094 143.2744903564453
B281 11287.236328125 44.812255859375 50.50752258300781 99.25949096679688 100.98638916015625
B282 257622.671875 163.02459716796875 164.5264434814453 373.361328125 396.1394958496094
b282 90159.8125 147.03485107421875 158.8583984375 289.22808837890625 266.2918701171875
b282 41603.37109375 52.535186767578125 55.08191680908203 125.94651794433594 132.66552734375
b282 26111.89453125 77.81584930419922 77.47465515136719 152.8137664794922 151.78988647460938
171
1101 98524.3359375 148.39682006835938 152.22201538085938 335.05792236328125 337.22064208984375
1101 7254.72314453125 28.882965087890625 29.019287109375 69.41510009765625 76.6951904296875
6101 116361.0703125 209.208740234375 58.23741149902344 186.5045166015625 316.8367614746094
1102 16251.056640625 43.512977600097656 42.086036682128906 82.9752197265625 81.40827941894531
6102 386311.125 274.37994384765625 278.8223876953125 590.6319580078125 601.85546875
6102 41987.234375 117.15809631347656 99.99629211425781 181.85189819335938 191.73233032226562
6202 263170.46875 112.165283203125 130.03762817382812 367.3878173828125 401.76727294921875
6202 2277.619140625 18.749664306640625 19.024124145507812 40.63641357421875 41.139617919921875
1203 9155.6123046875 46.43070983886719 44.44842529296875 90.76974487304688 92.56829833984375
6203 317806.8125 195.19140625 202.28793334960938 468.7117919921875 488.5067138671875
1303 359289.96875 258.5819091796875 262.2669677734375 547.7198486328125 555.54931640625
1303 6260.0869140625 40.19856262207031 37.65946960449219 70.36026000976562 69.97116088867188
1303 2685.79052734375 17.36297607421875 16.106300354003906 32.533721923828125 32.31199645996094
6303 11957.4306640625 50.76652526855469 44.00921630859375 103.14762878417969 103.91749572753906
1304 142672.921875 171.76724243164062 151.57217407226562 325.78411865234375 364.12664794921875
6304 283746.34375 171.44671630859375 179.37496948242188 417.17236328125 435.20281982421875
6304 54512.6171875 119.2557373046875 99.90211486816406 210.4261474609375 217.22433471679688
1305 37872.32421875 86.77447509765625 100.79736328125 198.21746826171875 192.70669555664062
1305 5894.98388671875 29.867645263671875 28.611343383789062 68.599853515625 71.32791137695312
6305 31277.99609375 76.77459716796875 79.40647888183594 170.45343017578125 170.87939453125
6305 8743.8544921875 43.81668472290039 46.24213409423828 86.75444793701172 82.68489074707031
1401 5166.57275390625 28.809066772460938 39.419403076171875 67.17098999023438 59.92919921875
1401 4376.77197265625 14.690637588500977 0.0 4.846019744873047 17.474498748779297
6401 240231.734375 141.27069091796875 148.40628051757812 348.30706787109375 363.86480712890625
6401 16244.75390625 52.48748779296875 54.44715881347656 115.864990234375 117.21566772460938
2101 313930.46875 221.62664794921875 223.3207550048828 472.0020751953125 481.3930358886719
2101 24078.896484375 74.21649169921875 75.0555419921875 156.96282958984375 157.09271240234375
2101 5454.45751953125 38.8876953125 19.7906494140625 62.1776123046875 77.736083984375
7101 313160.875 221.93792724609375 226.22869873046875 475.74481201171875 483.5977783203125
7101 95356.6015625 148.99021911621094 150.38681030273438 299.2361145019531 298.64306640625
7101 7470.87841796875 41.243751525878906 40.39897155761719 79.86720275878906 79.83358764648438
2102 7762.3896484375 55.04771423339844 33.07476806640625 74.78997802734375 85.31329345703125
7102 27521.787109375 69.66864013671875 69.48750305175781 156.2548828125 163.88357543945312
2202 297126.4375 209.79306030273438 212.1188507080078 451.791748046875 461.9290466308594
2202 4952.33203125 34.19127655029297 29.94640350341797 57.69541931152344 58.16117858886719
7202 294466.5 204.46563720703125 202.66575622558594 440.066650390625 454.0547790527344
7202 70984.8046875 128.51535034179688 128.25978088378906 257.06304931640625 257.3648376464844
7202 15053.6796875 39.47706604003906 64.26869201660156 115.28250122070312 97.72055053710938
7202 6177.8828125 28.171432495117188 29.528564453125 65.94790649414062 68.75933837890625
2203 10949.4873046875 42.4823112487793 41.205810546875 90.08216094970703 90.82110595703125
2203 5861.60498046875 20.763492584228516 24.956275939941406 48.73314666748047 47.34508514404297
7203 18419.58203125 59.93214416503906 70.08297729492188 110.97604370117188 106.09307861328125
2301 275886.1875 189.47467041015625 200.9993133544922 423.489013671875 428.5150451660156
2301 4789.67529296875 35.118011474609375 34.70379638671875 63.234130859375 61.9945068359375
2301 958.6224365234375 12.572482109069824 12.703475952148438 24.98558235168457 24.756515502929688
7301 272259.71875 188.06768798828125 193.8113250732422 413.95208740234375 421.5010070800781
7301 52870.31640625 110.34577941894531 110.38601684570312 220.98507690429688 221.13482666015625
7301 5643.40966796875 32.52781677246094 32.63990783691406 66.25021362304688 66.19967651367188
7301 3025.5693359375 17.744384765625 18.4227294921875 39.446861267089844 40.179359436035156
2303 252643.453125 107.11314392089844 127.23814392089844 343.1929016113281 370.9018859863281
2303 4007.042236328125 30.10223388671875 30.154769897460938 60.33343505859375 60.324005126953125
7303 7607.22705078125 39.227783203125 40.07177734375 79.130615234375 78.55987548828125
2304 259861.203125 179.6448516845703 181.88677978515625 386.8631896972656 396.01092529296875
7304 251767.59375 174.14291381835938 177.90667724609375 379.25408935546875 387.3153076171875
7304 6778.10107421875 38.95204162597656 36.99407958984375 74.62045288085938 75.5767822265625
7304 3628.119140625 22.07684326171875 22.09735870361328 44.44671630859375 44.63627624511719
2305 87942.421875 16.54983901977539 25.760360717773438 114.46599578857422 128.01583862304688
2305 7585.50439453125 39.46165466308594 38.122894287109375 73.60226440429688 73.79315185546875
2401 236392.234375 162.0963592529297 166.17535400390625 356.1175231933594 363.965087890625
7401 230273.4375 157.27175903320312 161.03530883789062 345.21258544921875 353.136474609375
7401 19837.177734375 63.824005126953125 64.92079162597656 131.14385986328125 130.8973388671875
7401 7251.32861328125 29.385360717773438 34.123199462890625 77.27871704101562 79.0384521484375
3101 115272.609375 164.64002990722656 163.93089294433594 328.6252136230469 329.1945495605469
3101 45678.890625 0.0 13.0224609375 50.979949951171875 61.7125244140625
8101 5125.91162109375 0.99298095703125 13.243667602539062 71.643310546875 57.848785400390625
8102 214476.328125 135.0194549560547 137.8410186767578 307.0708312988281 320.1783142089844
8102 12535.830078125 50.89021682739258 50.362693786621094 101.0557632446289 101.81819152832031
8102 8103.4150390625 31.925392150878906 35.26441192626953 81.21147155761719 83.47215270996094
3202 207300.53125 141.13079833984375 144.7773895263672 311.1104736328125 318.3011779785156
3202 12001.3486328125 64.5289306640625 62.28748321533203 126.82171630859375 117.45237731933594
8202 4190.57763671875 51.743499755859375 37.103515625 50.030303955078125 49.61785888671875
8203 188891.921875 124.33381652832031 126.89820861816406 281.8836364746094 290.7723083496094
8203 2862.25390625 18.757963180541992 19.73272705078125 39.223636627197266 39.95653533935547
3301 180846.5625 125.86346435546875 124.20858764648438 264.5081787109375 272.43780517578125
3301 7265.9189453125 39.64347839355469 37.798431396484375 74.59371948242188 77.649658203125
8301 16076.822265625 66.91526794433594 95.1042251586914 138.48355102539062 97.59831237792969
8303 172163.796875 108.94523620605469 114.69197082519531 258.1654052734375 265.18743896484375
8303 7841.15087890625 37.857627868652344 40.15619659423828 75.00462341308594 73.04866027832031
8303 735.7068481445312 5.382078170776367 8.009516716003418 19.17487335205078 19.641767501831055
8303 618.0466918945312 3.0466508865356445 3.6786556243896484 9.463619232177734 9.612007141113281
3304 164664.859375 104.68150329589844 109.15882873535156 245.67092895507812 253.57025146484375
3304 7602.74365234375 27.80121612548828 31.271682739257812 69.55679321289062 70.267822265625
8304 14513.41796875 0.0 0.0 85.0731201171875 94.12446594238281
8304 9064.18359375 53.753662109375 29.686370849609375 70.72344970703125 84.65017700195312
8304 1458.6822509765625 47.3505859375 49.978424072265625 44.964111328125 44.70648193359375
3305 6005.580078125 35.64312744140625 36.66609191894531 73.10464477539062 69.5438232421875
8305 150935.953125 97.98185729980469 101.46046447753906 223.35617065429688 230.44650268554688
8305 4694.6669921875 49.44868469238281 50.239418029785156 71.7296142578125 60.694580078125
3401 144413.9375 92.23753356933594 96.74836730957031 212.78591918945312 219.09664916992188
8401 9957.2724609375 18.966583251953125 33.09520721435547 80.25591278076172 86.07411193847656
4101 137804.78125 182.46539306640625 182.54153442382812 365.58856201171875 365.79693603515625
9101 130573.4296875 77.16633605957031 80.9446792602539 188.13552856445312 196.88548278808594
4102 124407.1015625 71.02523040771484 74.06380462646484 176.1684112548828 184.5003204345703
4102 17508.123046875 61.65488815307617 63.76106643676758 123.33721160888672 121.15241241455078
4102 6789.41015625 33.41869354248047 32.4907341003418 69.85139465332031 72.0433120727539
9102 109325.109375 162.33758544921875 163.03143310546875 322.7216796875 320.5797119140625
9102 7437.85595703125 36.53065490722656 34.53240966796875 72.63320922851562 74.34783935546875
4202 81773.4375 114.58541870117188 129.31924438476562 274.94354248046875 275.5596923828125
4202 6142.0048828125 40.96449279785156 45.060462951660156 73.50650024414062 64.91737365722656
9202 9668.1416015625 48.69032287597656 49.27049255371094 96.65042114257812 92.82052612304688
9202 4939.4345703125 45.169525146484375 28.934112548828125 68.31399536132812 76.9923095703125
4203 106246.921875 57.73091125488281 62.37882995605469 151.29739379882812 160.50177001953125
4203 10848.31640625 42.84939193725586 48.08837890625 98.7686538696289 98.05413818359375
4203 6407.23095703125 42.55998229980469 34.88481140136719 62.18170166015625 63.853912353515625
9203 101522.2578125 54.031463623046875 57.89891815185547 141.99774169921875 150.8223114013672
9203 82668.59375 138.81982421875 137.54576110839844 273.641845703125 273.5240783691406
4303 85288.2421875 46.67971420288086 41.6962890625 111.14038848876953 125.85049438476562
4303 73826.703125 124.14372253417969 123.91242980957031 245.66845703125 245.66946411132812
4303 5324.42431640625 35.55322265625 32.54658508300781 65.73382568359375 66.24925231933594
4303 2433.474853515625 20.42963409423828 18.655059814453125 38.64247131347656 39.38770294189453
9303 77916.0703125 36.88260269165039 41.36090850830078 106.07147979736328 113.98072814941406
9303 63585.015625 123.10182189941406 122.21688842773438 244.41656494140625 244.41619873046875
9303 6748.35498046875 29.297330856323242 27.51004409790039 62.558040618896484 66.12544250488281
4304 45031.88671875 75.30422973632812 50.26231384277344 161.21255493164062 202.96585083007812
9304 154.02874755859375 1.9150018692016602 2.308852195739746 4.985044479370117 4.823703765869141
4305 65818.5 19.948387145996094 26.42050552368164 86.82872009277344 96.42581939697266
4305 12919.5068359375 46.671722412109375 61.92650604248047 122.58782958984375 106.62467956542969
9305 57887.1875 13.253211975097656 20.072803497314453 74.90364837646484 84.85249328613281
9305 45472.2734375 101.95329284667969 101.82182312011719 202.39614868164062 201.84402465820312
4401 106795.125 38.662940979003906 50.812034606933594 143.54710388183594 156.47764587402344
9401 3764.192138671875 17.801467895507812 19.509719848632812 43.74005126953125 45.226348876953125
5101 39786.328125 13.971609115600586 15.1138916015625 45.56547164916992 52.66474151611328
0101 35586.08203125 4.643238067626953 12.568016052246094 43.16181182861328 47.93732452392578
0101 11840.712890625 37.7353401184082 31.70500946044922 85.08769989013672 97.52320861816406
0101 1331.2872314453125 12.850248336791992 12.414623260498047 24.26732635498047 24.684646606445312
5102 126166.21875 175.4044189453125 175.51947021484375 351.66943359375 351.7620849609375
5102 61921.84765625 9.918689727783203 16.367694854736328 72.12078094482422 83.35440826416016
5102 9086.748046875 51.46815872192383 58.25550079345703 113.57669830322266 94.29441833496094
0102 112049.7265625 170.6594696044922 168.79934692382812 324.5194396972656 322.32196044921875
5202 130883.3984375 180.13232421875 180.05303955078125 355.53363037109375 354.451171875
5202 31169.044921875 80.88715362548828 80.39226531982422 160.9435577392578 161.56788635253906
5202 23339.615234375 0.0 8.834268569946289 28.38434410095215 32.11856460571289
5202 11432.740234375 45.30205535888672 46.74104309082031 91.48197937011719 89.75006103515625
0202 22264.373046875 48.03718566894531 56.19591522216797 101.8138427734375 95.97740173339844
0202 19682.349609375 632.2802734375 0.0 8.382266998291016 26.536739349365234
0202 17564.01953125 69.14364624023438 71.91499328613281 131.63250732421875 126.71200561523438
5203 108189.5546875 162.70294189453125 168.21609497070312 324.2105712890625 321.8153076171875
5203 30723.63671875 612.6378173828125 614.3040161132812 12.802042961120605 40.876220703125
5203 30476.810546875 88.43894958496094 89.61432647705078 175.28201293945312 173.24180603027344
5203 7623.111328125 35.62397003173828 42.678306579589844 87.61064147949219 86.64552307128906
0203 17246.380859375 43.797119140625 68.72908782958984 133.78045654296875 127.20899963378906
5301 26397.80859375 82.52547454833984 25.715606689453125 94.10816955566406 122.31263732910156
5301 7117.67724609375 37.71221923828125 25.798507690429688 81.15469360351562 92.94949340820312
0301 404085.6875 296.8662109375 302.40130615234375 618.9442138671875 630.9388427734375
0301 8148.5498046875 35.20122146606445 37.845943450927734 74.6900405883789 79.45386505126953
5303 402296.15625 293.6922607421875 296.5999755859375 610.07373046875 617.501708984375
5303 81376.75 128.7560272216797 127.3974609375 266.4541320800781 267.00927734375
5303 335.2579650878906 3.122772216796875 3.129302978515625 6.27557373046875 6.27801513671875
0303 89959.234375 147.05654907226562 158.92166137695312 289.3499755859375 266.26605224609375
0303 5422.908203125 25.12714195251465 24.932220458984375 47.97197341918945 47.547142028808594
5304 3156.857421875 44.569061279296875 33.98942947387695 6.55438232421875 6.636007785797119
5304 1955.345947265625 16.600326538085938 17.045976638793945 35.15699768066406 35.46742630004883
0304 52915.63671875 105.30158233642578 104.50823974609375 207.4530487060547 206.42657470703125
0304 18094.287109375 68.38641357421875 50.74684143066406 127.29156494140625 132.9398651123047
5305 381043.65625 271.9959716796875 276.5519714355469 582.367919921875 591.5303344726562
5305 56433.9453125 116.22512817382812 117.11809539794922 227.82843017578125 224.83116149902344
5305 5492.02587890625 31.204177856445312 30.741729736328125 61.295379638671875 62.1844482421875
0305 12563.5810546875 54.531715393066406 54.62616729736328 107.80207824707031 108.28068542480469
5401 3940.017578125 5.622894287109375 5.6913909912109375 11.9482421875 11.978912353515625
0401 363215.09375 258.7518005371094 267.5076904296875 555.3683471679688 563.551513671875
A281 39668.73046875 92.915771484375 91.60932922363281 183.20703125 184.14886474609375
A282 302303.75 190.916748046875 197.89280700683594 444.6964111328125 460.9689025878906
a282 343890.09375 244.36614990234375 248.77114868164062 521.459716796875 529.5814819335938
B281 338253.21875 241.40362548828125 245.91632080078125 515.5374755859375 523.3087158203125
B281 22623.1953125 73.31651306152344 73.5584716796875 143.42764282226562 143.28375244140625
B281 11209.3251953125 45.06608963012695 50.4040412902832 99.3630142211914 101.14759063720703
B282 257698.5625 162.85003662109375 164.66461181640625 373.41552734375 396.29437255859375
b282 41189.76953125 50.50967025756836 56.248023986816406 124.32483673095703 128.8549041748047
b282 26408.00390625 77.8435287475586 77.58490753173828 152.85960388183594 151.83226013183594
b282 21797.083984375 7.488689422607422 0.716094970703125 94.29624938964844 129.40606689453125
b282 5967.61767578125 31.095500946044922 22.45880889892578 59.778358459472656 64.40863037109375

The probabilities are too big and then get too many boxes(big number return by detectedObjects.getNumberOfObjects() in unexpected), what's the possible cause? python return correct label and boxes as expected for the same model.

@SidneyLann
Copy link
Contributor Author

I'm not familiar with yolo5 and yolo8, can help to implement YoloV8Translator.java? Thanks.

@SidneyLann
Copy link
Contributor Author

SidneyLann commented Aug 21, 2023

  private DetectedObjects processFromBoxOutput(NDList list) {
    NDArray features4OneImg = list.get(0);
    int sizeClasses = classes.size();
    long sizeBoxes = features4OneImg.size(1);

    ArrayList<IntermediateResult> intermediateResults = new ArrayList<>();
    for (long b = 0; b < sizeBoxes; b++) {
      float maxClass = 0;
      int maxIndex = 0;
      for (int c = 4; c < sizeClasses; c++) {
        float classProb = features4OneImg.getFloat(c, b);
        if (classProb > maxClass) {
          maxClass = classProb;
          maxIndex = c;
        }
      }

      if (maxClass > threshold) {
        float xPos = features4OneImg.getFloat(0, b);// center x
        float yPos = features4OneImg.getFloat(1, b);// center y
        float w = features4OneImg.getFloat(2, b);
        float h = features4OneImg.getFloat(3, b);
        Rectangle rect = new Rectangle(Math.max(0, xPos - w / 2), Math.max(0, yPos - h / 2), w, h);
        intermediateResults.add(new IntermediateResult(classes.get(maxIndex), maxClass, maxIndex, rect));
      }
    }
    
    return nms(intermediateResults);
  }

yolov8 work after amend this method in YoloV5Translator.java

@KexinFeng
Copy link
Contributor

I'm not familiar with yolo5 and yolo8, can help to implement YoloV8Translator.java? Thanks.

Sorry I forgot to check this reply in time.

yolov8 work after amend this method in YoloV5Translator.java

This is great! It's good to know that yolov8 can resuse the yolov5 Translator in this way.

This in principle agrees with our desgin, where the Translator is nothing but preprocessing + postprocessing. So in theory, if the input(output) of a new model (e.g. yolov8) is of the same or similar "signatures" as the old one (e.g. yolov5), then the similar Translator (i.e. preprocessing + postprocessing) can be reused. And here it is a good example.

Would you mind contributing this feature to DJL? Basically the PR is gonna contain this code and your testing example, which serves as unit test.

@SidneyLann
Copy link
Contributor Author

I had never done a PR in github, I can try if someone guide me, or someone can do a PR to amend only one method in YoloV5Translator.java to get YoloV8Translator.java

@KexinFeng
Copy link
Contributor

@SidneyLann You can use this chance to give it a try. Just fork the djl repo, create a new branch from the master, and then on github website click into "new pull request". We can help you edit the branch afterwards. You creating the PR makes sure your authorship of the feature.

Alternatively, we can create a PR for you too. But could you share the testing code that showcases that the above function works with yolov8?

@SidneyLann
Copy link
Contributor Author

SidneyLann commented Sep 8, 2023

image
image

Can do nothing after click "New Pull Request"

@KexinFeng
Copy link
Contributor

KexinFeng commented Sep 11, 2023

I looked into your repo, there is only one branch, "master". The photo above shows that you didn't do any changes yet on this branch, thus "there isn't anything to compare".

You can use chatgpt or google to find how to create a new branch locally, named say "feature", and make some changes, push it to your repo. Then in the photo above, intead of "compare: master", you can opt to "compare: feature". Then you will see the file difference, and then you can continue to create a PR.

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

No branches or pull requests

2 participants