detect
import sys
sys.path.append("/root/ultralytics")
from ultralytics import YOLO
#DOTA8数据集预测yolov8n-obb模型
# Load a model
model = YOLO('yolov8n-obb.pt') # load an official model
model = YOLO('path/to/best.pt') # load a custom model
# Predict with the model
results = model('https://ultralytics.com/images/bus.jpg') # predict on an image
'''
if __name__ == '__main__': #yolov8模型
# Load a model
model = YOLO(r'yolov8n.pt') # pretrained YOlov8
model.predict(
source = r'/root/ultralytics/ultralytics/assets/bus.jpg',
save = True,
imgsz = 640,
conf = 0.25,
iou = 0.45,
show = False,
project = 'runs/predict',
name = 'exp',
save_conf = True,
save_crop = False,
show_labels = True,
show_conf = True,
vid_stride = 1,
line_width = 3,
visualize = False,
augment = False,
agnostic_nms = False,
retina_masks = False,
boxes = True,
)
'''
train
import sys
sys.path.append("/root/ultralytics")
from ultralytics import YOLO
#yolov8n-obb模型
# Load a model
model = YOLO('yolov8n-obb.yaml') # build a new model from YAML
model = YOLO('yolov8n-obb.pt') # load a pretrained model (recommended for training)
model = YOLO('yolov8n-obb.yaml').load('yolov8n.pt') # build from YAML and transfer weights
# Train the model
results = model.train(data='dota8.yaml', epochs=100, imgsz=640)
'''
if __name__ == '__main__':
# Load a model
model = YOLO(r'yolov8.yaml') # 不使用预训练权重训练
# model = YOLO(r'yolov8.yaml').load("yolov8.pt") # 使用预训练权重训练
# Trainparameters---------------------------------------
model.train( #yolov8模型
data=r'/root/ultralytics/ultralytics/cfg/datasets/my-data.yaml',
epochs=100,
patience=50,
batch = 16,
imgsz = 640,
save = True,
save_period = -1,
cache = False,
device = '',
workers = 8,
project = 'runs/train',
name = 'exp',
exist_ok = False,
pretrained=True,
optimizer = 'SGD',
verbose = True,
seed = 0,
deterministic = True,
single_cls = False,
rect = False,
cos_lr = False,
close_mosaic = 0,
resume = False,
amp = True,
fraction =1.0,
profile = False,
#segmensation
overlap_mask=True,
mask_ratio=4,
#classification
dropout = 0.0,
#Hyperparameters
lr0=0.01,
lrf=0.01,
momentum=0.937,
weight_decay=0.0005,
warmup_epochs=3.0,
warmup_momentum=0.8,
warmup_bias_lr=0.1,
box=7.5,
cls=0.5,
dfl=1.5,
pose=12.0,
kobj=1.0,
label_smoothing=0.0,
nbs=64,
hsv_h=0.015,
hsv_s=0.7,
hsv_v=0.4,
degrees=0.0,
translate=0.1,
scale=0.5,
shear=0.0,
perspective = 0.0,
flipud=0.0,
fliplr=0.5,
mosaic=1.0,
mixup=0.0,
copy_paste=0.0,
)
'''
val
import sys
sys.path.append("/root/ultralytics")
from ultralytics import YOLO
#DOTA8数据集验证yolov8n-obb模型的准确性。
# Load a model
model = YOLO('yolov8n-obb.pt') # load an official model
model = YOLO('/root/ultralytics/runs/obb/train/weights/best.pt') # load a custom model
# Validate the model
metrics = model.val(data='dota8.yaml') # no arguments needed, dataset and settings remembered
metrics.box.map # map50-95(B)
metrics.box.map50 # map50(B)
metrics.box.map75 # map75(B)
metrics.box.maps # a list contains map50-95(B) of each category
'''if __name__ == '__main__': #yolov8模型
# Load a model
model = YOLO(r'/root/ultralytics/runs/train/exp7/weights/best.pt') #build a new model from YAML
# Validate the model
model.val(
val=True,
data = r'/root/ultralytics/ultralytics/cfg/datasets/my-data.yaml',
split='test',
batch=1,
imgsz=640,
device='',
workers=8,
save_json=False,
save_hybrid=False,
conf=0.001,
iou=0.6,
project='runs/val',
name='exp',
max_det=300,
half=False,
dnn=False,
plots=True,
)
'''