Skip to content

Commit

Permalink
Updated path handling for yolo .names and .data files -resolves #5
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianPlum committed Jul 2, 2023
1 parent 710e830 commit 84f206b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions YOLOader.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ def create_data(self):

print("Created new .data file for the loaded network.")


def update_data(self):
"""
creates a .data file in the location of the config file with the current location of the .names file and sets
the path to the output file as the new .data file.
"""
with open(self.data, "r") as f:
lines = f.readlines()
for l, line in enumerate(lines):
if line.split(" ")[0] == "names":
lines[l] = "names = " + str(self.names).replace("\\", "/") + "\n"

with open(self.data, "w") as f:
for line in lines:
f.write(line)

print("INFO: Updated .data file for the loaded network to include absolute path of .names file")

def update_cfg(self, nw_width, nw_height, encoding="utf-8"):
"""
Updates the cfg file and creates a copy of it in the same directory as the original. The function updates the
Expand Down
5 changes: 4 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"author": "Fabian Plum",
"description": "Deep learning-based multi animal tracker",
"blender": (3, 3, 0),
"version": (0, 2, 2),
"version": (0, 2, 3),
"location": "",
"warning": "RUN IN ADMINISTRATOR MODE DURING INSTALLATION!",
"category": "motion capture"
Expand Down Expand Up @@ -262,6 +262,9 @@ def execute(self, context):

if yolo_paths.data is None:
yolo_paths.create_data()
else:
# update the data file to ensure it points to the correct absolute location of the names file
yolo_paths.update_data()

context.scene.detection_config_path = yolo_paths.cfg
context.scene.detection_data_path = yolo_paths.data
Expand Down

0 comments on commit 84f206b

Please sign in to comment.