Skip to content

Commit

Permalink
add resize and check
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyWangRaining committed Jan 8, 2025
1 parent 786bbf3 commit 15ea56d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion tools/check_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def main():

read_all_images(input_txt,error_txt)


if __name__ == "__main__":
main()

Expand Down
8 changes: 4 additions & 4 deletions tools/resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from concurrent.futures import ThreadPoolExecutor
import argparse

def resize_image(input_path, input_path_replace,output_path_replace,target_size=(768, 384)):
def resize_image(input_path, input_path_root,output_path_root,target_size=(768, 384)):
try:
img = cv2.imread(input_path)
if img is None:
Expand All @@ -14,7 +14,7 @@ def resize_image(input_path, input_path_replace,output_path_replace,target_size=
print("File does not exist:", input_path)
return

output_path = input_path.replace(input_path_replace, output_path_replace)
output_path = input_path.replace(input_path_root, output_path_root)
output_dir = os.path.dirname(output_path)
os.makedirs(output_dir, exist_ok=True)
original_height, original_width = img.shape[:2]
Expand All @@ -40,14 +40,14 @@ def resize_image(input_path, input_path_replace,output_path_replace,target_size=
cv2.imwrite(output_path, resized_img)


def resize_all_images(all_img_txt,input_path_replace,output_path_replace):
def resize_all_images(all_img_txt,input_path_root,output_path_root):
# Use ThreadPoolExecutor to process files in parallel
with open(all_img_txt, 'r') as f:
input_files = sorted([file.strip() for file in f.readlines()])

with ThreadPoolExecutor() as executor:
with tqdm.tqdm(total=len(input_files), desc="Resizing images", unit="img") as pbar:
for _ in executor.map(lambda img_path: resize_image(img_path, input_path_replace,output_path_replace),input_files):
for _ in executor.map(lambda img_path: resize_image(img_path, input_path_root,output_path_root),input_files):
pbar.update(1)

def main():
Expand Down

0 comments on commit 15ea56d

Please sign in to comment.