Added dataset and training data
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,254 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"id": "ee6d3405-39e3-4109-84e0-f1ba6c7df74b",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"%matplotlib inline\n",
|
||||||
|
"\n",
|
||||||
|
"import os\n",
|
||||||
|
"import random\n",
|
||||||
|
"import cv2\n",
|
||||||
|
"import matplotlib.pyplot as plt\n",
|
||||||
|
"from ultralytics import YOLO\n",
|
||||||
|
"\n",
|
||||||
|
"# --- CONFIGURATION ---\n",
|
||||||
|
"DATASET_DIR = os.path.abspath(\"dataset\") # Absolute path to your dataset folder\n",
|
||||||
|
"# VIDEO_PATH = \"Screen_Recording_20260710_101822_Hades' Star.mp4\" # Path to your test video\n",
|
||||||
|
"VIDEO_PATH = \"Screen_Recording_20260710_142109_Hades' Star.mp4\"\n",
|
||||||
|
"\n",
|
||||||
|
"# The exact list from your label.py script\n",
|
||||||
|
"CLASS_NAMES = [\n",
|
||||||
|
" \"guardian\",\n",
|
||||||
|
" \"interceptor\",\n",
|
||||||
|
" \"sentinel\",\n",
|
||||||
|
" \"rocket\",\n",
|
||||||
|
" \"bomber\",\n",
|
||||||
|
" \"background\",\n",
|
||||||
|
" \"asteroid\",\n",
|
||||||
|
"]\n",
|
||||||
|
"# ---------------------"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"id": "0245800c-f39d-479d-8093-a8573223d975",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"-> Created dataset.yaml successfully.\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"# === STEP 1: CREATE THE YOLO CONFIGURATION FILE ===\n",
|
||||||
|
"yaml_content = f\"\"\"\n",
|
||||||
|
"path: {DATASET_DIR}\n",
|
||||||
|
"train: images # path relative to 'path'\n",
|
||||||
|
"val: images # for a quick test, we will validate on the same images\n",
|
||||||
|
"\n",
|
||||||
|
"names:\n",
|
||||||
|
"\"\"\"\n",
|
||||||
|
"for idx, name in enumerate(CLASS_NAMES):\n",
|
||||||
|
" yaml_content += f\" {idx}: {name}\\n\"\n",
|
||||||
|
"\n",
|
||||||
|
"yaml_path = \"dataset.yaml\"\n",
|
||||||
|
"with open(yaml_path, \"w\") as f:\n",
|
||||||
|
" f.write(yaml_content.strip())\n",
|
||||||
|
"\n",
|
||||||
|
"print(f\"-> Created {yaml_path} successfully.\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "a3e69197-7565-4464-8381-ffc871818819",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"\n",
|
||||||
|
"-> Initializing YOLO training...\n",
|
||||||
|
"Ultralytics 8.4.92 🚀 Python-3.13.14 torch-2.13.0+cu130 CPU (Intel Core i5-8365U 1.60GHz)\n",
|
||||||
|
"\u001b[34m\u001b[1mengine/trainer: \u001b[0magnostic_nms=False, amp=True, angle=1.0, augment=False, auto_augment=randaugment, batch=16, bgr=0.0, box=7.5, cache=False, cfg=None, classes=None, close_mosaic=10, cls=0.5, cls_pw=0.0, cls_remap=True, compile=False, conf=None, copy_paste=0.0, copy_paste_mode=flip, cos_lr=False, cutmix=0.0, data=dataset.yaml, degrees=0.0, deterministic=True, device=, dfl=1.5, dis=6.0, distill_model=None, dnn=False, dropout=0.0, dynamic=False, embed=None, end2end=None, epochs=75, erasing=0.4, exist_ok=False, fliplr=0.5, flipud=0.0, format=torchscript, fraction=1.0, freeze=None, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, imgsz=640, iou=0.7, keras=False, kobj=1.0, line_width=None, lr0=0.01, lrf=0.01, mask_ratio=4, max_det=300, mixup=0.0, mode=train, model=yolov8n.pt, momentum=0.937, mosaic=1.0, multi_scale=0.0, name=train-3, nbs=64, nms=False, opset=None, optimize=False, optimizer=auto, overlap_mask=True, patience=100, perspective=0.0, plots=True, pose=12.0, pretrained=True, profile=False, project=None, quantize=None, rect=False, resume=False, retina_masks=False, rle=1.0, save=True, save_conf=False, save_crop=False, save_dir=/home/nathan/school/CSE_450/final/runs/detect/train-3, save_frames=False, save_json=False, save_period=-1, save_txt=False, scale=0.5, seed=0, shear=0.0, show=False, show_boxes=True, show_conf=True, show_labels=True, simplify=True, single_cls=False, source=None, split=val, stream_buffer=False, task=detect, time=None, tracker=tracktrack.yaml, translate=0.1, val=True, verbose=True, vid_stride=1, visualize=False, warmup_bias_lr=0.1, warmup_epochs=3.0, warmup_momentum=0.8, weight_decay=0.0005, workers=8, workspace=None\n",
|
||||||
|
"Overriding model.yaml nc=80 with nc=7\n",
|
||||||
|
"\n",
|
||||||
|
" from n params module arguments \n",
|
||||||
|
" 0 -1 1 464 ultralytics.nn.modules.conv.Conv [3, 16, 3, 2] \n",
|
||||||
|
" 1 -1 1 4672 ultralytics.nn.modules.conv.Conv [16, 32, 3, 2] \n",
|
||||||
|
" 2 -1 1 7360 ultralytics.nn.modules.block.C2f [32, 32, 1, True] \n",
|
||||||
|
" 3 -1 1 18560 ultralytics.nn.modules.conv.Conv [32, 64, 3, 2] \n",
|
||||||
|
" 4 -1 2 49664 ultralytics.nn.modules.block.C2f [64, 64, 2, True] \n",
|
||||||
|
" 5 -1 1 73984 ultralytics.nn.modules.conv.Conv [64, 128, 3, 2] \n",
|
||||||
|
" 6 -1 2 197632 ultralytics.nn.modules.block.C2f [128, 128, 2, True] \n",
|
||||||
|
" 7 -1 1 295424 ultralytics.nn.modules.conv.Conv [128, 256, 3, 2] \n",
|
||||||
|
" 8 -1 1 460288 ultralytics.nn.modules.block.C2f [256, 256, 1, True] \n",
|
||||||
|
" 9 -1 1 164608 ultralytics.nn.modules.block.SPPF [256, 256, 5] \n",
|
||||||
|
" 10 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
|
||||||
|
" 11 [-1, 6] 1 0 ultralytics.nn.modules.conv.Concat [1] \n",
|
||||||
|
" 12 -1 1 148224 ultralytics.nn.modules.block.C2f [384, 128, 1] \n",
|
||||||
|
" 13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
|
||||||
|
" 14 [-1, 4] 1 0 ultralytics.nn.modules.conv.Concat [1] \n",
|
||||||
|
" 15 -1 1 37248 ultralytics.nn.modules.block.C2f [192, 64, 1] \n",
|
||||||
|
" 16 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2] \n",
|
||||||
|
" 17 [-1, 12] 1 0 ultralytics.nn.modules.conv.Concat [1] \n",
|
||||||
|
" 18 -1 1 123648 ultralytics.nn.modules.block.C2f [192, 128, 1] \n",
|
||||||
|
" 19 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3, 2] \n",
|
||||||
|
" 20 [-1, 9] 1 0 ultralytics.nn.modules.conv.Concat [1] \n",
|
||||||
|
" 21 -1 1 493056 ultralytics.nn.modules.block.C2f [384, 256, 1] \n",
|
||||||
|
" 22 [15, 18, 21] 1 752677 ultralytics.nn.modules.head.Detect [7, 16, None, [64, 128, 256]] \n",
|
||||||
|
"Model summary: 130 layers, 3,012,213 parameters, 3,012,197 gradients, 8.2 GFLOPs\n",
|
||||||
|
"\n",
|
||||||
|
"Transferred 319/355 items from pretrained weights\n",
|
||||||
|
"Freezing layer 'model.22.dfl.conv.weight'\n",
|
||||||
|
"\u001b[34m\u001b[1mtrain: \u001b[0mFast image access ✅ (ping: 0.0±0.0 ms, read: 2882.6±931.7 MB/s, size: 170.8 KB)\n",
|
||||||
|
"\u001b[K\u001b[34m\u001b[1mtrain: \u001b[0mScanning /home/nathan/school/CSE_450/final/dataset/labels... 200 images, 0 backgrounds, 0 corrupt: 100% ━━━━━━━━━━━━ 200/200 2.2Kit/s 0.1s\n",
|
||||||
|
"\u001b[34m\u001b[1mtrain: \u001b[0m/home/nathan/school/CSE_450/final/dataset/images/Screen_Recording_20260710_110910_Hades' Star_frame_1832.jpg: 1 duplicate labels removed\n",
|
||||||
|
"\u001b[34m\u001b[1mtrain: \u001b[0m/home/nathan/school/CSE_450/final/dataset/images/Screen_Recording_20260710_142109_Hades' Star_frame_500.jpg: 1 duplicate labels removed\n",
|
||||||
|
"\u001b[34m\u001b[1mtrain: \u001b[0mNew cache created: /home/nathan/school/CSE_450/final/dataset/labels.cache\n",
|
||||||
|
"\u001b[34m\u001b[1mval: \u001b[0mFast image access ✅ (ping: 0.0±0.0 ms, read: 3815.1±715.0 MB/s, size: 139.5 KB)\n",
|
||||||
|
"\u001b[K\u001b[34m\u001b[1mval: \u001b[0mScanning /home/nathan/school/CSE_450/final/dataset/labels.cache... 200 images, 0 backgrounds, 0 corrupt: 100% ━━━━━━━━━━━━ 200/200 52.4Mit/s 0.0s\n",
|
||||||
|
"\u001b[34m\u001b[1mtrain: \u001b[0m/home/nathan/school/CSE_450/final/dataset/images/Screen_Recording_20260710_110910_Hades' Star_frame_1832.jpg: 1 duplicate labels removed\n",
|
||||||
|
"\u001b[34m\u001b[1mtrain: \u001b[0m/home/nathan/school/CSE_450/final/dataset/images/Screen_Recording_20260710_142109_Hades' Star_frame_500.jpg: 1 duplicate labels removed\n",
|
||||||
|
"\u001b[34m\u001b[1moptimizer:\u001b[0m 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically... \n",
|
||||||
|
"\u001b[34m\u001b[1moptimizer:\u001b[0m AdamW(lr=0.000909, momentum=0.9) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias(decay=0.0)\n",
|
||||||
|
"Plotting labels to /home/nathan/school/CSE_450/final/runs/detect/train-3/labels.jpg... \n",
|
||||||
|
"Image sizes 640 train, 640 val\n",
|
||||||
|
"Using 0 dataloader workers\n",
|
||||||
|
"Logging results to \u001b[1m/home/nathan/school/CSE_450/final/runs/detect/train-3\u001b[0m\n",
|
||||||
|
"Starting training for 75 epochs...\n",
|
||||||
|
"\n",
|
||||||
|
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
||||||
|
"\u001b[K 1/75 0G 2.958 5.133 1.861 24 640: 100% ━━━━━━━━━━━━ 13/13 5.7s/it 1:144.4ss\n",
|
||||||
|
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 7/7 1.9s/it 13.3s2.4s\n",
|
||||||
|
" all 200 688 0 0 0 0\n",
|
||||||
|
"\n",
|
||||||
|
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
||||||
|
"\u001b[K 2/75 0G 2.32 4.479 1.373 62 640: 100% ━━━━━━━━━━━━ 13/13 6.4s/it 1:234.8ss\n",
|
||||||
|
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 7/7 2.4s/it 16.7s3.1ss\n",
|
||||||
|
" all 200 688 0.000766 0.0548 0.000265 5.24e-05\n",
|
||||||
|
"\n",
|
||||||
|
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
||||||
|
"\u001b[K 3/75 0G 2.113 3.946 1.244 59 640: 100% ━━━━━━━━━━━━ 13/13 6.7s/it 1:276.1ss\n",
|
||||||
|
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 7/7 2.8s/it 19.8s3.5ss\n",
|
||||||
|
" all 200 688 0.0023 0.121 0.00597 0.00267\n",
|
||||||
|
"\n",
|
||||||
|
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
||||||
|
"\u001b[K 4/75 0G 2.018 3.399 1.21 45 640: 100% ━━━━━━━━━━━━ 13/13 6.2s/it 1:215.4ss\n",
|
||||||
|
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 7/7 3.0s/it 21.0s4.0ss\n",
|
||||||
|
" all 200 688 0.0103 0.753 0.0839 0.0235\n",
|
||||||
|
"\n",
|
||||||
|
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
||||||
|
"\u001b[K 5/75 0G 1.965 3.118 1.224 71 640: 100% ━━━━━━━━━━━━ 13/13 6.7s/it 1:274.7ss\n",
|
||||||
|
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 7/7 2.4s/it 16.5s3.0s\n",
|
||||||
|
" all 200 688 0.493 0.128 0.12 0.0565\n",
|
||||||
|
"\n",
|
||||||
|
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
||||||
|
"\u001b[K 6/75 0G 1.819 2.967 1.173 74 640: 100% ━━━━━━━━━━━━ 13/13 7.0s/it 1:315.4ss\n",
|
||||||
|
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 7/7 2.9s/it 20.0s3.6ss\n",
|
||||||
|
" all 200 688 0.171 0.101 0.149 0.0428\n",
|
||||||
|
"\n",
|
||||||
|
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
||||||
|
"\u001b[K 7/75 0G 1.865 2.806 1.192 49 640: 100% ━━━━━━━━━━━━ 13/13 6.3s/it 1:225.3ss\n",
|
||||||
|
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 7/7 3.4s/it 23.8s4.4ss\n",
|
||||||
|
" all 200 688 0.359 0.237 0.224 0.108\n",
|
||||||
|
"\n",
|
||||||
|
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
||||||
|
"\u001b[K 8/75 0G 1.783 2.766 1.169 124 640: 76% ━━━━━━━━━─── 10/13 9.0s/it 1:36<27.1s"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"# === STEP 2: TRAIN A NANO YOLO MODEL ===\n",
|
||||||
|
"print(\"\\n-> Initializing YOLO training...\")\n",
|
||||||
|
"# 'yolov8n.pt' is the Nano model.\n",
|
||||||
|
"model = YOLO(\"yolov8n.pt\")\n",
|
||||||
|
"\n",
|
||||||
|
"# Train the model on your 130 annotations\n",
|
||||||
|
"model.train(data=yaml_path, epochs=75, imgsz=640, verbose=True)\n",
|
||||||
|
"print(\"\\n-> Training complete!\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "138e1424-8ecd-4b76-a487-345bcb3b69f1",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"model = YOLO(\"runs/detect/train/weights/best.pt\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "693c7e66-9c2f-427f-b2a0-311c4e5e8a38",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# === STEP 3: EXTRACT A RANDOM FRAME AND TEST DETECTION ===\n",
|
||||||
|
"print(\"\\n-> Running full-frame inference test...\")\n",
|
||||||
|
"\n",
|
||||||
|
"# Grab a random frame from your video file\n",
|
||||||
|
"cap = cv2.VideoCapture(VIDEO_PATH)\n",
|
||||||
|
"if not cap.isOpened():\n",
|
||||||
|
" print(f\"Error: Could not open video {VIDEO_PATH}\")\n",
|
||||||
|
"else:\n",
|
||||||
|
" total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))\n",
|
||||||
|
" random_idx = random.randint(0, total_frames - 1)\n",
|
||||||
|
" cap.set(cv2.CAP_PROP_POS_FRAMES, random_idx)\n",
|
||||||
|
" ret, frame = cap.read()\n",
|
||||||
|
" cap.release()\n",
|
||||||
|
"\n",
|
||||||
|
" if ret:\n",
|
||||||
|
" # Run our freshly trained model on the single, complete video frame!\n",
|
||||||
|
" results = model.predict(source=frame, conf=0.10, imgsz=640)\n",
|
||||||
|
"\n",
|
||||||
|
" # Ultralytics built-in renderer\n",
|
||||||
|
" annotated_frame = results[0].plot()\n",
|
||||||
|
"\n",
|
||||||
|
" plt.figure(figsize=(24, 16))\n",
|
||||||
|
"\n",
|
||||||
|
" # Display the result directly inside your Jupyter Notebook\n",
|
||||||
|
" # plt.figure(figsize=(12, 8))\n",
|
||||||
|
" # Convert BGR (OpenCV format) to RGB (Matplotlib format)\n",
|
||||||
|
" plt.imshow(cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB))\n",
|
||||||
|
" plt.title(f\"YOLO Object Detection Test (Frame: {random_idx})\", fontsize=14)\n",
|
||||||
|
" plt.axis(\"off\")\n",
|
||||||
|
" plt.show()\n",
|
||||||
|
" else:\n",
|
||||||
|
" print(\"Error: Could not read a random frame from the video.\")"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3 (ipykernel)",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.13.14"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user