Skip to content

Commit e0b8ce3

Browse files
Merge pull request #99 from roboflow/fix/proper_model_path_handling_in_model_deploy
Fix problems related to lack of trailing / at the end of model_path.
2 parents be09139 + 2f27ce8 commit e0b8ce3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

roboflow/core/version.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def deploy(self, model_type: str, model_path: str) -> None:
310310

311311
# add logic to save torch state dict safely
312312
if model_type == "yolov8":
313-
model = torch.load(model_path + "weights/best.pt")
313+
model = torch.load(os.path.join(model_path + "weights/best.pt"))
314314

315315
class_names = []
316316
for i, val in enumerate(model["model"].names):
@@ -345,21 +345,25 @@ def deploy(self, model_type: str, model_path: str) -> None:
345345
"model_type": model_type,
346346
}
347347

348-
with open(model_path + "model_artifacts.json", "w") as fp:
348+
with open(os.path.join(model_path + "model_artifacts.json", "w")) as fp:
349349
json.dump(model_artifacts, fp)
350350

351-
torch.save(model["model"].state_dict(), model_path + "state_dict.pt")
351+
torch.save(
352+
model["model"].state_dict(), os.path.join(model_path + "state_dict.pt")
353+
)
352354

353355
lista_files = [
354356
"results.csv",
355357
"results.png",
356358
"model_artifacts.json",
357359
"state_dict.pt",
358360
]
359-
with zipfile.ZipFile(model_path + "roboflow_deploy.zip", "w") as zipMe:
361+
with zipfile.ZipFile(
362+
os.path.join(model_path + "roboflow_deploy.zip", "w")
363+
) as zipMe:
360364
for file in lista_files:
361365
zipMe.write(
362-
model_path + file,
366+
os.path.join(model_path + file),
363367
arcname=file,
364368
compress_type=zipfile.ZIP_DEFLATED,
365369
)
@@ -379,7 +383,8 @@ def deploy(self, model_type: str, model_path: str) -> None:
379383
return
380384

381385
res = requests.put(
382-
res.json()["url"], data=open(model_path + "roboflow_deploy.zip", "rb")
386+
res.json()["url"],
387+
data=open(os.path.join(model_path + "roboflow_deploy.zip", "rb")),
383388
)
384389
try:
385390
res.raise_for_status()

0 commit comments

Comments
 (0)