@@ -456,25 +456,29 @@ public ResponseEntity<Object> downloadCVReport(@PathVariable(name = "id") String
456
456
public ResponseEntity <Object > downloadDataset (
457
457
@ PathVariable ("id" ) String idStr ,
458
458
@ RequestParam (name = "type" , required = false ) String type ,
459
- @ RequestParam (name = "datasetName" , required = false ) String datasetName
459
+ @ RequestParam (name = "ratio" , required = false ) String ratioStr ,
460
+ @ RequestParam (name = "name" , required = false ) String datasetName
460
461
) throws IOException {
461
462
try {
462
- // 参数验证
463
+ long repOrDocId = Long .parseLong (idStr );
464
+ if (repOrDocId <= 0 ) {
465
+ throw new IllegalArgumentException ("id 必须为 > 0 的 reportId 或 documentId 有效整数!" );
466
+ }
467
+
463
468
if (StringUtil .isNotEmpty (type )) {
464
469
validateCocoType (type );
465
470
} else {
466
471
type = "" ;
467
472
}
468
473
469
- String dataset = StringUtil .isEmpty (datasetName ) ? type + "_dataset" : datasetName ;
470
- String exportDir = fileUploadRootDir + dataset + "/" ;
471
-
472
- long repOrDocId = Long .parseLong (idStr );
473
- if (repOrDocId <= 0 ) {
474
- throw new IllegalArgumentException ("id 必须为 > 0 的 reportId 或 documentId 有效整数!" );
474
+ int ratio = StringUtil .isEmpty (ratioStr ) ? 20 : Integer .parseInt (ratioStr );
475
+ if (ratio < 0 || ratio > 100 ) {
476
+ throw new IllegalArgumentException ("测试集比例 ratio 必须为 0 ~ 100 范围内的有效整数!" );
475
477
}
476
478
477
- String name = "CVAuto_" + dataset + repOrDocId + ".zip" ;
479
+ String dataset = StringUtil .isNotEmpty (datasetName ) ? datasetName : "CVAuto_" + (StringUtil .isNotEmpty (type ) ? type + "_" : "" ) + "dataset_" + repOrDocId ;
480
+ String exportDir = fileUploadRootDir + dataset + "/" ;
481
+ String name = dataset + ".zip" ;
478
482
String path = fileUploadRootDir + name ;
479
483
480
484
File file = new File (path );
@@ -499,8 +503,8 @@ public ResponseEntity<Object> downloadDataset(
499
503
500
504
{ // [] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
501
505
JSONObject item = new JSONObject ();
502
- // item.put("count", 0);
503
- item .put ("count" , 3 );
506
+ item .put ("count" , 0 );
507
+ // item.put("count", 3);
504
508
item .put ("join" , "@/TestRecord" );
505
509
506
510
{ // Random <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@@ -545,17 +549,29 @@ public ResponseEntity<Object> downloadDataset(
545
549
//long documentId = lastTr == null ? 0 : lastTr.getLongValue("documentId");
546
550
//long randomId = lastTr == null ? 0 : lastTr.getLongValue("randomId");
547
551
if (reportId != repOrDocId ) {
548
- name = "CVAuto_" + dataset + (reportId > 0 ? reportId : repOrDocId + "_last" ) + ".zip" ;
552
+ dataset = StringUtil .isNotEmpty (datasetName ) ? datasetName : "CVAuto_" + (StringUtil .isNotEmpty (type ) ? type + "_" : "" ) + "dataset_" + (reportId > 0 ? reportId : repOrDocId + "_last" );
553
+ exportDir = fileUploadRootDir + dataset + "/" ;
554
+ name = dataset + ".zip" ;
549
555
path = fileUploadRootDir + name ;
550
556
}
551
557
552
558
JSONArray array = response .getJSONArray ("[]" );
553
559
554
- List <JSONObject > list = new ArrayList <>();
560
+ List <JSONObject > trainList = new ArrayList <>();
561
+ List <JSONObject > validList = new ArrayList <>();
555
562
if (array != null ) {
556
- for (int i = 0 ; i < array .size (); i ++) {
563
+ int len = array .size ();
564
+ for (int i = 0 ; i < len ; i ++) {
557
565
JSONObject item = array .getJSONObject (i );
558
- list .add (item );
566
+ if (item == null || item .isEmpty ()) {
567
+ continue ;
568
+ }
569
+
570
+ if (ratio <= 0 || ratio <= 100 - 100.0 *i /len ) {
571
+ trainList .add (item );
572
+ } else {
573
+ validList .add (item );
574
+ }
559
575
560
576
//JSONObject random = item == null ? null : item.getJSONObject("Random");
561
577
//JSONObject testRecord = item == null ? null : item.getJSONObject("TestRecord");
@@ -586,7 +602,9 @@ public ResponseEntity<Object> downloadDataset(
586
602
//generateCocoDatasetFromApiJson(exportDir, type, dataset, list);
587
603
588
604
Set <DatasetUtil .TaskType > detectionTasks = new HashSet <>(Collections .singletonList (DatasetUtil .TaskType .DETECTION ));
589
- DatasetUtil .generate (exportDir , detectionTasks , list );
605
+
606
+ DatasetUtil .generate (trainList , detectionTasks , exportDir , "train" );
607
+ DatasetUtil .generate (validList , detectionTasks , exportDir , "val" );
590
608
591
609
createZipFromDirectory (exportDir , path );
592
610
0 commit comments