Skip to content

Commit

Permalink
Fix cache_dir and yolo conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
triklozoid committed Jan 9, 2025
1 parent f581261 commit 0bbdb80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def get_local_path(
if is_uploaded_file and os.path.exists(image_dir):
project_id = url.split("/")[-2] # To retrieve project_id
filepath = os.path.join(image_dir, project_id, os.path.basename(url))
if cache_dir and download_resources:
shutil.copy(filepath, cache_dir)
if os.path.exists(filepath):
if cache_dir and download_resources:
shutil.copy(filepath, cache_dir)
logger.debug(f"Uploaded file: Path exists in image_dir: {filepath}")
return filepath

Expand Down
14 changes: 9 additions & 5 deletions src/label_studio_sdk/converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ def add_image(images, width, height, image_id, image_path):
url=image_path,
hostname=self.hostname,
project_dir=self.project_dir,
image_dir=self.upload_dir,
cache_dir=output_image_dir,
download_resources=self.download_resources,
access_token=self.access_token,
Expand Down Expand Up @@ -813,14 +814,17 @@ def convert_to_yolo(
for image_path in reversed(image_paths):
if not os.path.exists(image_path):
try:
image_path = download(
image_path,
output_image_dir,
image_path = get_local_path(
url=image_path,
hostname=self.hostname,
project_dir=self.project_dir,
return_relative_path=True,
upload_dir=self.upload_dir,
image_dir=self.upload_dir,
cache_dir=output_image_dir,
download_resources=self.download_resources,
access_token=self.access_token,
)
# make path relative to output_image_dir
image_path = os.path.relpath(image_path, output_dir)
except:
logger.info(
"Unable to download {image_path}. The item {item} will be skipped".format(
Expand Down

0 comments on commit 0bbdb80

Please sign in to comment.