Skip to content

Remove a slash in path to save the file correctly on Linux #8053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions computer_vision/flip_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def main() -> None:
letter_code = random_chars(32)
file_name = paths[index].split(os.sep)[-1].rsplit(".", 1)[0]
file_root = f"{OUTPUT_DIR}/{file_name}_FLIP_{letter_code}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
file_root = f"{OUTPUT_DIR}/{file_name}_FLIP_{letter_code}"
file_root = os.path.join(OUTPUT_DIR, f"{file_name}_FLIP_{letter_code}")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use pathlib instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
file_root = f"{OUTPUT_DIR}/{file_name}_FLIP_{letter_code}"
file_root = Path(OUTPUT_DIR, f"{file_name}_FLIP_{letter_code}")

cv2.imwrite(f"/{file_root}.jpg", image, [cv2.IMWRITE_JPEG_QUALITY, 85])
cv2.imwrite(f"{file_root}.jpg", image, [cv2.IMWRITE_JPEG_QUALITY, 85])
print(f"Success {index+1}/{len(new_images)} with {file_name}")
annos_list = []
for anno in new_annos[index]:
obj = f"{anno[0]} {anno[1]} {anno[2]} {anno[3]} {anno[4]}"
annos_list.append(obj)
with open(f"/{file_root}.txt", "w") as outfile:
with open(f"{file_root}.txt", "w") as outfile:
outfile.write("\n".join(line for line in annos_list))


Expand Down