Skip to content

Commit

Permalink
print upload times
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Mar 6, 2024
1 parent 15da004 commit 32f252b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
53 changes: 35 additions & 18 deletions roboflow/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import warnings
import time

import requests
from PIL import Image, UnidentifiedImageError
Expand Down Expand Up @@ -470,27 +471,36 @@ def single_upload(
if isinstance(annotation_labelmap, str):
annotation_labelmap = load_labelmap(annotation_labelmap)
uploaded_image, uploaded_annotation = None, None
upload_time = None
if image_path:
uploaded_image = retry(
num_retry_uploads,
Exception,
rfapi.upload_image,
self.__api_key,
project_url,
image_path,
hosted_image=hosted_image,
split=split,
batch_name=batch_name,
tag_names=tag_names,
sequence_number=sequence_number,
sequence_size=sequence_size,
**kwargs,
)
image_id = uploaded_image["id"]
t0 = time.time()
try:
uploaded_image = retry(
num_retry_uploads,
Exception,
rfapi.upload_image,
self.__api_key,
project_url,
image_path,
hosted_image=hosted_image,
split=split,
batch_name=batch_name,
tag_names=tag_names,
sequence_number=sequence_number,
sequence_size=sequence_size,
**kwargs,
)
image_id = uploaded_image["id"]
except BaseException as e:
uploaded_image = {"error": e}
finally:
upload_time = time.time() - t0

if annotation_path:
annotation_time = None
if annotation_path and image_id:
annotation_name, annotation_str = self._annotation_params(annotation_path)
try:
t0 = time.time()
uploaded_annotation = rfapi.save_annotation(
self.__api_key,
project_url,
Expand All @@ -503,7 +513,14 @@ def single_upload(
)
except BaseException as e:
uploaded_annotation = {"error": e}
return {"image": uploaded_image, "annotation": uploaded_annotation}
finally:
annotation_time = time.time() - t0
return {
"image": uploaded_image,
"annotation": uploaded_annotation,
"upload_time": upload_time,
"annotation_time": annotation_time,
}

def _annotation_params(self, annotation_path):
annotation_name, annotation_string = None, None
Expand Down
15 changes: 9 additions & 6 deletions roboflow/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,22 @@ def _log_img_upload(image_path, uploadres):
img_success = uploadres.get("image", {}).get("success")
img_duplicate = uploadres.get("image", {}).get("duplicate")
annotation = uploadres.get("annotation")
image = uploadres.get("image")
upload_time_str = f"[{uploadres['upload_time']:.1f}s]" if uploadres.get("upload_time") else ""
annotation_time_str = f"[{uploadres['annotation_time']:.1f}s]" if uploadres.get("annotation_time") else ""
if img_duplicate:
msg = f"[DUPLICATE] {image_path} ({image_id})"
msg = f"[DUPLICATE] {image_path} ({image_id}) {upload_time_str}"
elif img_success:
msg = f"[UPLOADED] {image_path} ({image_id})"
msg = f"[UPLOADED] {image_path} ({image_id}) {upload_time_str}"
else:
msg = f"[ERR] {image_path} ({uploadres})"
msg = f"[ERR] {image_path} ({image}) {upload_time_str}"
if annotation:
if annotation.get("success"):
msg += " / annotations = OK"
msg += f" / annotations = OK {annotation_time_str}"
elif annotation.get("warn"):
msg += f" / annotations = WARN: {annotation['warn']}"
msg += f" / annotations = WARN: {annotation['warn']} {annotation_time_str}"
elif annotation.get("error"):
msg += f" / annotations = ERR: {annotation['error']}"
msg += f" / annotations = ERR: {annotation['error']} {annotation_time_str}"
print(msg)

def _log_img_upload_err(image_path, e):
Expand Down

0 comments on commit 32f252b

Please sign in to comment.