Dr-Swopt 2 týždňov pred
rodič
commit
91b2d69f4f
6 zmenil súbory, kde vykonal 86 pridanie a 30 odobranie
  1. 1 0
      .gitignore
  2. 0 12
      test_model.py
  3. 19 0
      train_palm.py
  4. 0 18
      train_script.py
  5. 66 0
      unify.py
  6. BIN
      yolo26n.pt

+ 1 - 0
.gitignore

@@ -38,5 +38,6 @@ wheels/
 .DS_Store
 Thumbs.db
 
+unified_dataset
 datasets
 runs

+ 0 - 12
test_model.py

@@ -1,12 +0,0 @@
-from ultralytics import YOLO
-import cv2
-
-# 1. Load your newly trained model
-model = YOLO('best.pt')
-
-# 2. Run prediction on an image from your 'test' folder
-# Change 'path/to/your/test/image.jpg' to a real path
-results = model.predict(source='datasets/test/images/TestRipe-1-_jpg.rf.1d329242e7510efbc0c6a2c94bc43edb.jpg', save=True, conf=0.5)
-
-# 3. Check your 'runs/detect/predict' folder for the result image!
-print("Check runs/detect/predict for the annotated image.")

+ 19 - 0
train_palm.py

@@ -0,0 +1,19 @@
+from ultralytics import YOLO
+
+def main():
+    # 1. Load the YOLO26n model (Nano version for Mobile)
+    model = YOLO("yolo26n.pt") 
+
+    # 2. Start Training
+    model.train(
+        data="data.yaml",      # Points to your unified_dataset
+        epochs=100,            # 100 is a good baseline for R&D
+        imgsz=640,             # Standard mobile resolution
+        batch=16,              # Adjust based on your GPU VRAM
+        name="palm_health_v1", # Folder name for results
+        device=0,              # Use '0' for NVIDIA GPU, or 'cpu'
+        patience=20            # Stops early if the model stops improving
+    )
+
+if __name__ == '__main__':
+    main()

+ 0 - 18
train_script.py

@@ -1,18 +0,0 @@
-from ultralytics import YOLO
-
-def main():
-    model = YOLO('yolov8n.pt') 
-
-    model.train(
-        data='datasets/data.yaml', 
-        epochs=50, 
-        imgsz=640, 
-        device='cpu',
-        # --- RESOURCE LIMITS ---
-        batch=4,          # Lower = less RAM used. Start with 4. 
-        workers=1,        # 1 or 2. Prevents the CPU from maxing all cores for data loading.
-        cache=False       # Don't store the whole dataset in RAM.
-    )
-
-if __name__ == '__main__':
-    main()

+ 66 - 0
unify.py

@@ -0,0 +1,66 @@
+import os
+import shutil
+
+# Master Configuration: Maps {Original_ID: Master_ID}
+CONFIG = {
+    "suharjito_dataset": {"0": "0", "1": "1", "2": "2", "3": "3", "4": "4", "5": "5"},
+    "darren_dataset": {"0": "4", "1": "5", "2": "3"},
+    "fy_dataset": {"0": "1", "1": "3", "2": "5"},
+    "nazwa_dataset": {"0": "2", "1": "0", "2": "5", "3": "3", "4": "1", "5": "4"}
+}
+
+BASE_DIR = "datasets"
+OUTPUT_DIR = "unified_dataset"
+
+# Prepare Directories
+for split in ['train', 'val']:
+    os.makedirs(f"{OUTPUT_DIR}/images/{split}", exist_ok=True)
+    os.makedirs(f"{OUTPUT_DIR}/labels/{split}", exist_ok=True)
+
+def process_and_merge():
+    for ds_name, mapping in CONFIG.items():
+        print(f"Processing {ds_name}...")
+        
+        # Roboflow uses 'valid', Suharjito might use 'valid' or 'test'
+        # Adjusting splits to unify them into train/val
+        splits = {
+            'train': 'train',
+            'valid': 'val',
+            'test': 'val' # Adding test images to validation for a more robust PoC
+        }
+
+        for src_split, target_split in splits.items():
+            img_path = os.path.join(BASE_DIR, ds_name, src_split, "images")
+            lbl_path = os.path.join(BASE_DIR, ds_name, src_split, "labels")
+
+            if not os.path.exists(lbl_path): continue
+
+            for label_file in os.listdir(lbl_path):
+                if not label_file.endswith(".txt"): continue
+                
+                # 1. Re-index Labels
+                new_lines = []
+                with open(os.path.join(lbl_path, label_file), 'r') as f:
+                    for line in f:
+                        parts = line.split()
+                        if parts[0] in mapping:
+                            parts[0] = mapping[parts[0]]
+                            new_lines.append(" ".join(parts))
+                
+                if new_lines:
+                    # 2. Save new label with dataset prefix to avoid filename collisions
+                    new_name = f"{ds_name}_{label_file}"
+                    with open(os.path.join(OUTPUT_DIR, "labels", target_split, new_name), 'w') as f:
+                        f.write("\n".join(new_lines))
+                    
+                    # 3. Copy Image
+                    img_exts = ['.jpg', '.jpeg', '.png', '.JPG']
+                    for ext in img_exts:
+                        img_name = label_file.replace(".txt", ext)
+                        src_img = os.path.join(img_path, img_name)
+                        if os.path.exists(src_img):
+                            shutil.copy(src_img, os.path.join(OUTPUT_DIR, "images", target_split, f"{ds_name}_{img_name}"))
+                            break
+
+process_and_merge()
+print("Successfully created unified_dataset!")

BIN
yolo26n.pt