Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating model versions #552

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MegaDetectorV6(YOLOV8Base):
2: "vehicle"
}

def __init__(self, weights=None, device="cpu", pretrained=True, version='yolov9c'):
def __init__(self, weights=None, device="cpu", version='yolov9c'):
"""
Initializes the MegaDetectorV5 model with the option to load pretrained weights.

Expand All @@ -34,10 +34,24 @@ def __init__(self, weights=None, device="cpu", pretrained=True, version='yolov9c
if version == 'yolov9c':
self.IMAGE_SIZE = 640
url = "https://zenodo.org/records/13357337/files/MDV6b-yolov9c.pt?download=1"
filename = "MDV6b-yolov9c.pt"
elif version == 'yolov9e':
self.IMAGE_SIZE = 640
url = "https://zenodo.org/records/14567879/files/MDV6-yolov9e.pt?download=1"
filename = "MDV6-yolov9e.pt"
elif version == 'yolov10n':
self.IMAGE_SIZE = 640
url = "https://zenodo.org/records/14567879/files/MDV6-yolov10n.pt?download=1"
filename = "MDV6-yolov10n.pt"
elif version == 'yolov10x':
self.IMAGE_SIZE = 640
url = "https://zenodo.org/records/14567879/files/MDV6-yolov10x.pt?download=1"
filename = "MDV6-yolov10x.pt"
elif version =='rtdetrl':
self.IMAGE_SIZE = 640
url = None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be missing?

filename = "MDV6b-rtdetrl.pt"
else:
print('Select a valid model version: yolov9c or rtdetrl')
print('Select a valid model version: yolov9c, yolov9e, yolov10n, yolov10x, or rtdetrl')

super(MegaDetectorV6, self).__init__(weights=weights, device=device, url=url)
super(MegaDetectorV6, self).__init__(weights=weights, device=device, url=url, filename=filename)
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class YOLOV8Base(BaseDetector):
This base detector class is also compatible with all the new ultralytics models including YOLOV9,
RTDetr, and more.
"""
def __init__(self, weights=None, device="cpu", url=None, transform=None):
def __init__(self, weights=None, device="cpu", url=None, filename=None, transform=None):
"""
Initialize the YOLOV8 detector.

Expand All @@ -43,9 +43,9 @@ def __init__(self, weights=None, device="cpu", url=None, transform=None):
"""
self.transform = transform
super(YOLOV8Base, self).__init__(weights=weights, device=device, url=url)
self._load_model(weights, self.device, url)
self._load_model(weights, self.device, url, filename)

def _load_model(self, weights=None, device="cpu", url=None):
def _load_model(self, weights=None, device="cpu", url=None, filename=None):
"""
Load the YOLOV8 model weights.

Expand All @@ -60,19 +60,19 @@ def _load_model(self, weights=None, device="cpu", url=None):
Exception: If weights are not provided.
"""

self.predictor = yolo.detect.DetectionPredictor()
self.predictor = yolo.detect.DetectionPredictor(overrides = dict(verbose=False))
# self.predictor.args.device = device # Will uncomment later
self.predictor.args.imgsz = self.IMAGE_SIZE
self.predictor.args.save = False # Will see if we want to use ultralytics native inference saving functions.

if weights:
self.predictor.setup_model(weights)
elif url:
if not os.path.exists(os.path.join(torch.hub.get_dir(), "checkpoints", "MDV6b-yolov9c.pt")):
if not os.path.exists(os.path.join(torch.hub.get_dir(), "checkpoints", filename)):
os.makedirs(os.path.join(torch.hub.get_dir(), "checkpoints"), exist_ok=True)
weights = wget.download(url, out=os.path.join(torch.hub.get_dir(), "checkpoints"))
else:
weights = os.path.join(torch.hub.get_dir(), "checkpoints", "MDV6b-yolov9c.pt")
weights = os.path.join(torch.hub.get_dir(), "checkpoints", filename)
self.predictor.setup_model(weights)
else:
raise Exception("Need weights for inference.")
Expand Down