Skip to content

Commit

Permalink
Refactor: Update downsample_and_save_image function, and update the a…
Browse files Browse the repository at this point in the history
…void overwrite prompt
  • Loading branch information
zoeduan committed Nov 6, 2024
1 parent 92d3c74 commit 7773ae9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/cautiousrobot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ def download_images(data, img_dir, log_filepath, error_log_filepath, filename =
# Don't overwrite resized images either
continue

if not os.path.exists(downsample_dir_path):
os.makedirs(downsample_dir_path, exist_ok=False)

downsample_and_save_image(
image_dir_path=image_dir_path,
image_name=image_name,
Expand Down Expand Up @@ -230,9 +227,7 @@ def main():
# Check for img_dir
img_dir = args.output_dir
if os.path.exists(img_dir):
overwrite = input(f"'{img_dir}' already exists (may impact downsizing too). Overwrite? [y/n]: ")
if overwrite.lower() != "y":
sys.exit("Exited without executing.")
sys.exit(f"'{img_dir}' already exists. Exited without executing.")

# Set location for logs
metadata_path = csv_path.split(".")[0]
Expand Down
3 changes: 2 additions & 1 deletion src/cautiousrobot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def downsample_and_save_image(image_dir_path, image_name, downsample_dir_path, d
Returns:
None
"""

if not os.path.exists(downsample_dir_path):
os.makedirs(downsample_dir_path, exist_ok=False)

try:
img = Image.open(f"{image_dir_path}/{image_name}")
Expand Down

0 comments on commit 7773ae9

Please sign in to comment.