-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Yolov5 learner truck updates * Yolov5 create an inference demo for the finetuned model * Update object-detection-2d-yolov5.md yolov5_learner.py documentation for download method * Update object-detection-2d-yolov5.md * Refactor yolov5_learner.py download process in constructor for efficiency * Update docs/reference/object-detection-2d-yolov5.md Co-authored-by: Nikolaos Passalis <passalis@users.noreply.github.com> --------- Co-authored-by: Nikolaos Passalis <passalis@users.noreply.github.com> Co-authored-by: Olivier Michel <Olivier.Michel@cyberbotics.com>
- Loading branch information
1 parent
06f9afc
commit 503a646
Showing
3 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
projects/python/perception/object_detection_2d/yolov5/inference_demo_agriculture_vehicles.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2020-2023 OpenDR European Project | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import argparse | ||
from opendr.engine.data import Image | ||
from opendr.perception.object_detection_2d import YOLOv5DetectorLearner | ||
from opendr.perception.object_detection_2d import draw_bounding_boxes | ||
|
||
|
||
if __name__ == '__main__': | ||
# Parse command line arguments | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--model_name", help="Model name or path", type=str, default='yolov5s_trucks') | ||
parser.add_argument("--device", help="Device to use (cpu, cuda)", type=str, default="cuda", choices=["cuda", "cpu"]) | ||
parser.add_argument("--model_dir", help="Model directory", type=str, default="./yolov5s_finetuned_in_trucks.pt") | ||
args = parser.parse_args() | ||
|
||
# Initialize the YOLOv5 detector with the given model and device | ||
yolo = YOLOv5DetectorLearner(model_name=args.model_name, device=args.device, path=args.model_dir) | ||
yolo.download(".", mode="images", verbose=True, img_name="truck4.jpg") | ||
yolo.download(".", mode="images", verbose=True, img_name="truck7.jpg") | ||
|
||
im1 = Image.open('truck4.jpg') | ||
im2 = Image.open('truck7.jpg') | ||
|
||
results = yolo.infer(im1) | ||
draw_bounding_boxes(im1.opencv(), results, yolo.classes, show=True, line_thickness=3) | ||
|
||
results = yolo.infer(im2) | ||
draw_bounding_boxes(im2, results, yolo.classes, show=True, line_thickness=3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters