mirror of
https://github.com/THU-MIG/yolov10.git
synced 2025-05-23 21:44:22 +08:00
Pip debug fixes (#139)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
340376f7a6
commit
d74de2582c
@ -3,56 +3,50 @@ import torch
|
|||||||
from ultralytics import YOLO
|
from ultralytics import YOLO
|
||||||
from ultralytics.yolo.utils import ROOT
|
from ultralytics.yolo.utils import ROOT
|
||||||
|
|
||||||
|
MODEL = ROOT / 'weights/yolov8n.pt'
|
||||||
|
CFG = 'yolov8n.yaml'
|
||||||
|
|
||||||
|
|
||||||
def test_model_forward():
|
def test_model_forward():
|
||||||
model = YOLO("yolov8n.yaml")
|
model = YOLO(CFG)
|
||||||
img = torch.rand(1, 3, 320, 320)
|
img = torch.rand(1, 3, 320, 320)
|
||||||
model.forward(img)
|
model.forward(img)
|
||||||
model(img)
|
model(img)
|
||||||
|
|
||||||
|
|
||||||
def test_model_info():
|
def test_model_info():
|
||||||
model = YOLO("yolov8n.yaml")
|
model = YOLO(CFG)
|
||||||
model.info()
|
model.info()
|
||||||
model = YOLO("yolov8n.pt")
|
model = YOLO(MODEL)
|
||||||
model.info(verbose=True)
|
model.info(verbose=True)
|
||||||
|
|
||||||
|
|
||||||
def test_model_fuse():
|
def test_model_fuse():
|
||||||
model = YOLO("yolov8n.yaml")
|
model = YOLO(CFG)
|
||||||
model.fuse()
|
model.fuse()
|
||||||
model = YOLO("yolov8n.pt")
|
model = YOLO(MODEL)
|
||||||
model.fuse()
|
model.fuse()
|
||||||
|
|
||||||
|
|
||||||
def test_predict_dir():
|
def test_predict_dir():
|
||||||
model = YOLO("yolov8n.pt")
|
model = YOLO(MODEL)
|
||||||
model.predict(source=ROOT / "assets")
|
model.predict(source=ROOT / "assets")
|
||||||
|
|
||||||
|
|
||||||
def test_val():
|
def test_val():
|
||||||
model = YOLO("yolov8n.pt")
|
model = YOLO(MODEL)
|
||||||
model.val(data="coco128.yaml", imgsz=32)
|
model.val(data="coco128.yaml", imgsz=32)
|
||||||
|
|
||||||
|
|
||||||
def test_train_resume():
|
|
||||||
model = YOLO("yolov8n.yaml")
|
|
||||||
model.train(epochs=1, imgsz=32, data="coco128.yaml")
|
|
||||||
try:
|
|
||||||
model.resume(task="detect")
|
|
||||||
except AssertionError:
|
|
||||||
print("Successfully caught resume assert!")
|
|
||||||
|
|
||||||
|
|
||||||
def test_train_scratch():
|
def test_train_scratch():
|
||||||
model = YOLO("yolov8n.yaml")
|
model = YOLO(CFG)
|
||||||
model.train(data="coco128.yaml", epochs=1, imgsz=32)
|
model.train(data="coco128.yaml", epochs=1, imgsz=32)
|
||||||
img = torch.rand(1, 3, 320, 320)
|
img = torch.rand(1, 3, 320, 320)
|
||||||
model(img)
|
model(img)
|
||||||
|
|
||||||
|
|
||||||
def test_train_pretrained():
|
def test_train_pretrained():
|
||||||
model = YOLO("yolov8n.pt")
|
model = YOLO(MODEL)
|
||||||
model.train(data="coco128.yaml", epochs=1, imgsz=32)
|
model.train(data="coco128.yaml", epochs=1, imgsz=32)
|
||||||
img = torch.rand(1, 3, 320, 320)
|
img = torch.rand(1, 3, 320, 320)
|
||||||
model(img)
|
model(img)
|
||||||
@ -77,27 +71,27 @@ def test_export_torchscript():
|
|||||||
from ultralytics.yolo.engine.exporter import export_formats
|
from ultralytics.yolo.engine.exporter import export_formats
|
||||||
print(export_formats())
|
print(export_formats())
|
||||||
|
|
||||||
model = YOLO("yolov8n.yaml")
|
model = YOLO(MODEL)
|
||||||
model.export(format='torchscript')
|
model.export(format='torchscript')
|
||||||
|
|
||||||
|
|
||||||
def test_export_onnx():
|
def test_export_onnx():
|
||||||
model = YOLO("yolov8n.yaml")
|
model = YOLO(MODEL)
|
||||||
model.export(format='onnx')
|
model.export(format='onnx')
|
||||||
|
|
||||||
|
|
||||||
def test_export_openvino():
|
def test_export_openvino():
|
||||||
model = YOLO("yolov8n.yaml")
|
model = YOLO(MODEL)
|
||||||
model.export(format='openvino')
|
model.export(format='openvino')
|
||||||
|
|
||||||
|
|
||||||
def test_export_coreml():
|
def test_export_coreml():
|
||||||
model = YOLO("yolov8n.yaml")
|
model = YOLO(MODEL)
|
||||||
model.export(format='coreml')
|
model.export(format='coreml')
|
||||||
|
|
||||||
|
|
||||||
def test_export_paddle():
|
def test_export_paddle():
|
||||||
model = YOLO("yolov8n.yaml")
|
model = YOLO(MODEL)
|
||||||
model.export(format='paddle')
|
model.export(format='paddle')
|
||||||
|
|
||||||
|
|
||||||
|
@ -292,7 +292,8 @@ def attempt_load_weights(weights, device=None, inplace=True, fuse=False):
|
|||||||
ckpt = (ckpt.get('ema') or ckpt['model']).to(device).float() # FP32 model
|
ckpt = (ckpt.get('ema') or ckpt['model']).to(device).float() # FP32 model
|
||||||
|
|
||||||
# Model compatibility updates
|
# Model compatibility updates
|
||||||
ckpt.args = {k: v for k, v in args.items() if k in DEFAULT_CONFIG_KEYS}
|
ckpt.args = {k: v for k, v in args.items() if k in DEFAULT_CONFIG_KEYS} # attach args to model
|
||||||
|
ckpt.pt_path = weights # attach *.pt file path to model
|
||||||
if not hasattr(ckpt, 'stride'):
|
if not hasattr(ckpt, 'stride'):
|
||||||
ckpt.stride = torch.tensor([32.])
|
ckpt.stride = torch.tensor([32.])
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ class Exporter:
|
|||||||
jit, onnx, xml, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs, paddle = flags # export booleans
|
jit, onnx, xml, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs, paddle = flags # export booleans
|
||||||
|
|
||||||
# Load PyTorch model
|
# Load PyTorch model
|
||||||
self.device = select_device(self.args.device)
|
self.device = select_device(self.args.device or 'cpu')
|
||||||
if self.args.half:
|
if self.args.half:
|
||||||
if self.device.type == 'cpu' or not coreml:
|
if self.device.type == 'cpu' or not coreml:
|
||||||
LOGGER.info('half=True only compatible with GPU or CoreML export, i.e. use device=0 or format=coreml')
|
LOGGER.info('half=True only compatible with GPU or CoreML export, i.e. use device=0 or format=coreml')
|
||||||
@ -172,7 +172,9 @@ class Exporter:
|
|||||||
|
|
||||||
# Input
|
# Input
|
||||||
im = torch.zeros(self.args.batch_size, 3, *self.imgsz).to(self.device)
|
im = torch.zeros(self.args.batch_size, 3, *self.imgsz).to(self.device)
|
||||||
file = Path(getattr(model, 'yaml_file', None) or Path(model.yaml['yaml_file']).name)
|
file = Path(getattr(model, 'pt_path', None) or model.yaml['yaml_file'])
|
||||||
|
if file.suffix == '.yaml':
|
||||||
|
file = Path(file.name)
|
||||||
|
|
||||||
# Update model
|
# Update model
|
||||||
model = deepcopy(model)
|
model = deepcopy(model)
|
||||||
|
@ -213,9 +213,8 @@ class YOLO:
|
|||||||
|
|
||||||
@smart_inference_mode()
|
@smart_inference_mode()
|
||||||
def __call__(self, imgs):
|
def __call__(self, imgs):
|
||||||
if not self.model:
|
device = next(self.model.parameters()).device # get model device
|
||||||
LOGGER.info("model not initialized!")
|
return self.model(imgs.to(device))
|
||||||
return self.model(imgs)
|
|
||||||
|
|
||||||
def forward(self, imgs):
|
def forward(self, imgs):
|
||||||
return self.__call__(imgs)
|
return self.__call__(imgs)
|
||||||
|
@ -81,12 +81,11 @@ class BaseTrainer:
|
|||||||
overrides = {}
|
overrides = {}
|
||||||
self.args = get_config(config, overrides)
|
self.args = get_config(config, overrides)
|
||||||
self.check_resume()
|
self.check_resume()
|
||||||
init_seeds(self.args.seed + 1 + RANK, deterministic=self.args.deterministic)
|
|
||||||
|
|
||||||
self.console = LOGGER
|
self.console = LOGGER
|
||||||
self.validator = None
|
self.validator = None
|
||||||
self.model = None
|
self.model = None
|
||||||
self.callbacks = defaultdict(list)
|
self.callbacks = defaultdict(list)
|
||||||
|
init_seeds(self.args.seed + 1 + RANK, deterministic=self.args.deterministic)
|
||||||
|
|
||||||
# Dirs
|
# Dirs
|
||||||
project = self.args.project or f"runs/{self.args.task}"
|
project = self.args.project or f"runs/{self.args.task}"
|
||||||
|
@ -62,6 +62,7 @@ HELP_MSG = \
|
|||||||
pd.options.display.max_columns = 10
|
pd.options.display.max_columns = 10
|
||||||
cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with PyTorch DataLoader)
|
cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with PyTorch DataLoader)
|
||||||
os.environ['NUMEXPR_MAX_THREADS'] = str(NUM_THREADS) # NumExpr max threads
|
os.environ['NUMEXPR_MAX_THREADS'] = str(NUM_THREADS) # NumExpr max threads
|
||||||
|
os.environ['CUBLAS_WORKSPACE_CONFIG'] = ':4096:8' # for deterministic training
|
||||||
|
|
||||||
# Default config dictionary
|
# Default config dictionary
|
||||||
with open(DEFAULT_CONFIG, errors='ignore') as f:
|
with open(DEFAULT_CONFIG, errors='ignore') as f:
|
||||||
|
@ -189,10 +189,11 @@ class Loss:
|
|||||||
def train(cfg):
|
def train(cfg):
|
||||||
cfg.model = cfg.model or "yolov8n.yaml"
|
cfg.model = cfg.model or "yolov8n.yaml"
|
||||||
cfg.data = cfg.data or "coco128.yaml" # or yolo.ClassificationDataset("mnist")
|
cfg.data = cfg.data or "coco128.yaml" # or yolo.ClassificationDataset("mnist")
|
||||||
# cfg.imgsz = 160
|
# trainer = DetectionTrainer(cfg)
|
||||||
# cfg.epochs = 5
|
# trainer.train()
|
||||||
trainer = DetectionTrainer(cfg)
|
from ultralytics import YOLO
|
||||||
trainer.train()
|
model = YOLO(cfg.model)
|
||||||
|
model.train(**cfg)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -176,8 +176,11 @@ class SegLoss:
|
|||||||
def train(cfg):
|
def train(cfg):
|
||||||
cfg.model = cfg.model or "yolov8n-seg.yaml"
|
cfg.model = cfg.model or "yolov8n-seg.yaml"
|
||||||
cfg.data = cfg.data or "coco128-seg.yaml" # or yolo.ClassificationDataset("mnist")
|
cfg.data = cfg.data or "coco128-seg.yaml" # or yolo.ClassificationDataset("mnist")
|
||||||
trainer = SegmentationTrainer(cfg)
|
# trainer = SegmentationTrainer(cfg)
|
||||||
trainer.train()
|
# trainer.train()
|
||||||
|
from ultralytics import YOLO
|
||||||
|
model = YOLO(cfg.model)
|
||||||
|
model.train(**cfg)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user