Views
No views yet
dataset/
├── train/
│ ├── images/ # 98 training images
│ └── labels/ # YOLO format annotations
├── valid/
│ ├── images/ # 12 validation images
│ └── labels/ # YOLO format annotations
└── test/
├── images/ # 12 test images
└── labels/ # YOLO format annotations<class_id> <x_center> <y_center> <width> <height>0 0.5234 0.4123 0.1234 0.0987pip install ultralytics opencv-python numpy torch torchvision1from ultralytics import YOLO
2
3# Load the trained model
4model = YOLO('best.pt')
5
6# Predict on a grayscale image
7results = model.predict(
8 source='path/to/xray/image.jpg',
9 conf=0.25, # Confidence threshold
10 save=True, # Save results
11 imgsz=640 # Image size
12)
13
14# Process results
15for result in results:
16 boxes = result.boxes
17 for box in boxes:
18 cls = int(box.cls[0])
19 conf = float(box.conf[0])
20 xyxy = box.xyxy[0].tolist()
21 print(f"Cavity detected - Confidence: {conf:.2%}")1# Predict on multiple images
2results = model.predict(
3 source='path/to/images/folder/',
4 save=True,
5 conf=0.25
6)dataset.yaml:1path: /path/to/dataset
2
3train: train/images
4val: valid/images
5test: test/images
6
7nc: 1
8names:
9 0: Cavity1# Using Python API
2from ultralytics import YOLO
3
4model = YOLO('ultralytics/cfg/models/v12/yolov12_triple.yaml')
5
6results = model.train(
7 data='dataset.yaml',
8 epochs=100,
9 imgsz=640,
10 batch=16,
11 device=0,
12 patience=50,
13 optimizer='AdamW',
14 lr0=0.001
15)| Parameter | Value | Description |
|---|---|---|
epochs | 100-300 | Number of training epochs |
batch | 8-32 | Batch size |
imgsz | 640 | Input image size |
device | 0 or 'cpu' | GPU device or CPU |
lr0 | 0.001 | Initial learning rate |
| Feature | Original (Triple) | Modified (Grayscale) |
|---|---|---|
| Input Channels | 9 | 1 |
| First Layer | TripleInputConv | Conv |
| Memory Usage | 3x baseline | 1/3x baseline |
1from ultralytics import YOLO
2
3model = YOLO('best.pt')
4
5# Export to ONNX
6model.export(format='onnx', imgsz=640)
7
8# Export to TensorRT
9model.export(format='engine', imgsz=640, half=True)1@misc{yolov12-grayscale-cavity,
2 title={YOLOv12 Grayscale for Cavity Detection},
3 author={Suphawut},
4 year={2025},
5 publisher={Hugging Face},
6 howpublished={\url{https://huggingface.co/suphawutq56789/yolov12-grayscale-cavity}}
7}