Skip to content

Commit

Permalink
Replaced prints with a tqdm progressbar for the preprocessing loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosalov committed Aug 7, 2024
1 parent 949d840 commit caacf44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 3 additions & 7 deletions preprocess_imagenet_using_opencv/code_axs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import os
import cv2
import numpy as np
import json
import sys
import shutil
from tqdm import trange

def get_files_from_subdirs(directory, supported_extensions):
all_files = []
Expand Down Expand Up @@ -117,7 +115,8 @@ def preprocess_files(selected_filenames, images_directory, destination_dir, crop
"Go through the selected_filenames and preprocess all the files (optionally normalize and subtract mean)"
output_filenames = []

for current_idx in range(len(selected_filenames)):
print("Preprocessing images...")
for current_idx in trange(len(selected_filenames)):
input_filename = selected_filenames[current_idx]

full_input_path = os.path.join(images_directory, input_filename)
Expand All @@ -144,9 +143,6 @@ def preprocess_files(selected_filenames, images_directory, destination_dir, crop

full_output_path = os.path.join(destination_dir, output_filename)
image_data.tofile(full_output_path)

print("[{}]: Stored {}".format(current_idx+1, full_output_path) )

output_filenames.append(output_filename)

return sorted(output_filenames)
Expand Down
8 changes: 7 additions & 1 deletion preprocess_imagenet_using_opencv/data_axs.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

"numpy_query": [ "python_package", "package_name=numpy", ["desired_python_version", ["^", "kernel_python_major_dot_minor"]] ],
"opencv_query": [ "python_package", "package_name=opencv-python", ["desired_python_version", ["^", "kernel_python_major_dot_minor"]] ],
"tqdm_query": [ "python_package", "package_name=tqdm", ["desired_python_version", ["^", "kernel_python_major_dot_minor"]] ],


"_BEFORE_CODE_LOADING": [ "^^", "execute", [[
["get_kernel"],
Expand All @@ -47,7 +49,11 @@
[],
["get_kernel"],
["byquery", [[ "^^", "get", "opencv_query" ]] ],
["use"]
["use"],
[],
["get_kernel"],
["byquery", [[ "^^", "get", "tqdm_query" ]] ],
["use"]
]] ],

"imagenet_query": [ "extracted", "imagenet" ],
Expand Down

0 comments on commit caacf44

Please sign in to comment.