{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":91249,"databundleVersionId":11294684,"sourceType":"competition"}],"dockerImageVersionId":30918,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session\n\nimport os\nimport glob\nimport cv2\nfrom pathlib import Path\nfrom joblib import Parallel, delayed\n\ndef process_image(img_path, size, folder_path):\n    \"\"\"Process a single image: resize and save it\"\"\"\n    try:\n        img = cv2.imread(img_path)\n        img = cv2.resize(img, size, interpolation=cv2.INTER_AREA)\n        file_name = f'{folder_path}/{img_path.split(\"/\")[-1]}'\n        cv2.imwrite(file_name, img)\n        return True\n    except Exception as e:\n        print(f\"Error processing {img_path}: {e}\")\n        return False\n\ndef process_folder(folder, size):\n    \"\"\"Process all images in a folder\"\"\"\n    folder_names = folder.split(\"/\")[-2:]\n    folder_path = f'/kaggle/working/{folder_names[0]}/{folder_names[1]}'\n    Path(folder_path).mkdir(parents=True, exist_ok=True)\n    \n    img_paths = glob.glob(f'{folder}/*.jpg')\n    \n    # Process images in parallel within this folder\n    results = Parallel(n_jobs=2, verbose=5)(\n        delayed(process_image)(img_path, size, folder_path) for img_path in img_paths\n    )\n    \n    return sum(results)  # Return number of successfully processed images\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-03-06T04:41:01.10942Z","iopub.execute_input":"2025-03-06T04:41:01.109825Z","iopub.status.idle":"2025-03-06T04:41:01.117923Z","shell.execute_reply.started":"2025-03-06T04:41:01.109784Z","shell.execute_reply":"2025-03-06T04:41:01.116706Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"size = (384, 384)\n\nPath(\"/kaggle/working/train\").mkdir(parents=True, exist_ok=True)\n\nfolders = glob.glob('/kaggle/input/byu-locating-bacterial-flagellar-motors-2025/train/*')\n\nresults = Parallel(n_jobs=2, verbose=5)(\n    delayed(process_folder)(folder, size) for folder in folders\n)\n\nprint(f\"Successfully processed {sum(results)} images across {len(folders)} folders\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-06T04:41:01.11933Z","iopub.execute_input":"2025-03-06T04:41:01.119676Z","iopub.status.idle":"2025-03-06T04:41:37.897673Z","shell.execute_reply.started":"2025-03-06T04:41:01.119651Z","shell.execute_reply":"2025-03-06T04:41:37.896192Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}