Skip to content

Commit

Permalink
Merge pull request #210 from Glas42/main
Browse files Browse the repository at this point in the history
some fixes and new features
  • Loading branch information
Glas42 authored Feb 14, 2024
2 parents ac6b0d0 + d10433a commit 82519e4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions plugins/NavigationDetection/automatic_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ def CreateSettings(category:str, name:str, data:any):
folder_path = os.path.dirname(__file__)
model_path = os.path.join(folder_path, 'YOLOv5_MapDetectionModel.pt')
try:
torch.hub.set_dir(f"{folder_path}\\YoloFiles")
torch.hub.set_dir(f"{folder_path}\\YOLOFiles")
model = torch.hub.load('ultralytics/yolov5', 'custom', path=model_path)
except:
torch.hub.set_dir(f"{folder_path}\\YoloFiles")
torch.hub.set_dir(f"{folder_path}\\YOLOFiles")
model = torch.hub.load('ultralytics/yolov5', 'custom', path=model_path, force_reload=True)
print("\033[92m" + f"Successfully loaded the YOLOv5_MapDetectionModel.pt model!" + "\033[0m")
startscreen("Setup model successfully loaded!", (0,255,0))
Expand Down
3 changes: 3 additions & 0 deletions plugins/TrafficLightDetection/YOLOModels/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
visibility: hidden
---
36 changes: 31 additions & 5 deletions plugins/TrafficLightDetection/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ def yolo_load_model_thread():
try:
print("\033[92m" + f"Loading the {yolo_model_str} model..." + "\033[0m")
import torch
torch.hub.set_dir(f"{variables.PATH}plugins\\TrafficLightDetection\\YoloFiles")
yolo_model = torch.hub.load("ultralytics/yolov5", yolo_model_str)
torch.hub.set_dir(f"{variables.PATH}plugins\\TrafficLightDetection\\YOLOFiles")
yolo_model = torch.hub.load("ultralytics/yolov5:master", 'custom', f"{variables.PATH}plugins\\TrafficLightDetection\\YOLOModels\\{yolo_model_str}")
print("\033[92m" + f"Successfully loaded the {yolo_model_str} model!" + "\033[0m")
yolo_model_loaded = True
except Exception as e:
Expand Down Expand Up @@ -1324,8 +1324,7 @@ def exampleFunction(self):

helpers.MakeCheckButton(trackeraiFrame, "Do Yolo Detection confirmation\n---------------------------------------------\nIf enabled, the app tracks the detected traffic lights and confirms them with the YOLO object detection.\nWhat this means: higher accuracy, but a small lag every time the detection detects a new traffic light.", "TrafficLightDetection", "yolo_detection", 1, 0, width=100, callback=lambda:UpdateSettings())
helpers.MakeCheckButton(trackeraiFrame, "Show unconfirmed traffic lights\n--------------------------------------------\nIf enabled, the app will show unconfirmed or wrongly detected traffic lights in gray in the output window.", "TrafficLightDetection", "yolo_showunconfirmed", 2, 0, width=100, callback=lambda:UpdateSettings())
helpers.MakeEmptyLine(trackeraiFrame,3,0)
helpers.MakeLabel(trackeraiFrame, "YOLOv5 Model:", 4, 0, sticky="nw")
helpers.MakeLabel(trackeraiFrame, "YOLOv5 Model:", 4, 0, sticky="nw", font=("Segoe UI", 12))
model_ui = tk.StringVar()
previous_model_ui = settings.GetSettings("TrafficLightDetection", "yolo_model")
if previous_model_ui == "yolov5n":
Expand All @@ -1351,7 +1350,8 @@ def model_selection():
yolov5x = ttk.Radiobutton(trackeraiFrame, text="YOLOv5x (slowest, highest accuracy)", variable=model_ui, value="yolov5x", command=model_selection)
yolov5x.grid(row=9, column=0, sticky="nw")
model_selection()
helpers.MakeButton(trackeraiFrame, "Save and Load Model\n-------------------------------\nLoading the model could take some time.", self.save_and_load_model, 10, 0, width=50, sticky="nw")
helpers.MakeButton(trackeraiFrame, "Save and Load Model", self.save_and_load_model, 10, 0, width=100, sticky="nw")
helpers.MakeButton(trackeraiFrame, "Delete all downloaded models and redownload the model you are currently using.\nThis could fix faulty model files and other issues.", self.delete_and_redownload_model, 11, 0, width=100, sticky="nw")

helpers.MakeCheckButton(screencaptureFrame, "Use Full Frame\n----------------------\nIf enabled, the screen capture for the traffic light detection uses the top ⅔ of the screen for\nthe traffic light detection. (not recommended, could have a bad impact on performance)\n\nTo set own screen capture coordinates disable Use Full Frame and use sliders below.", "TrafficLightDetection", "usefullframe", 1, 0, width=80, callback=lambda:UpdateSettings())

Expand Down Expand Up @@ -1728,6 +1728,32 @@ def save_and_load_model(self):
else:
messagebox.showwarning("TrafficLightDetection", f"The code is still loading a different model. Please try again when the other model has finished loading.")

def delete_and_redownload_model(self):
global last_model_load_press
global yolo_model_loaded
if time.time() > last_model_load_press + 1:
last_model_load_press = time.time()
if yolo_model_loaded != "loading...":
try:
import os
yolomodels_path = f"{variables.PATH}plugins\\TrafficLightDetection\\YOLOModels"
for filename in os.listdir(yolomodels_path):
file_path = os.path.join(yolomodels_path, filename)
if os.path.isfile(file_path) and filename.lower() != 'index.md':
os.remove(file_path)
except Exception as e:
messagebox.showwarning("TrafficLightDetection", f"The code encountered an error while deleting the model files. Please try again.")
exc = traceback.format_exc()
SendCrashReport("TrafficLightDetection - Model Delete Error.", str(exc))
print("TrafficLightDetection - Model Delete Error: " + str(e))
yolo_model_loaded = False
yolo_load_model()
UpdateSettings()
else:
messagebox.showwarning("TrafficLightDetection", f"The code is still loading a model. Please try again when the model has finished loading.")
else:
messagebox.showwarning("TrafficLightDetection", f"The code is still loading a model. Please try again when the model has finished loading.")

def update(self, data):
self.root.update()

Expand Down
4 changes: 1 addition & 3 deletions plugins/TruckSimAPI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ def onEnable():

print("Plugin version: " + str(data["scsValues"]["telemetryPluginRevision"]))

devmode = settings.GetSettings("Dev", "disable_warnings", False)
if devmode == False:
if data["scsValues"]["telemetryPluginRevision"] < 2:
if data["scsValues"]["telemetryPluginRevision"] < 2:
print("Plugin not installed")

def onDisable():
Expand Down

0 comments on commit 82519e4

Please sign in to comment.