{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Starting copy with 48 processes...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Copying files: 100%|██████████| 7680/7680 [00:12<00:00, 626.66it/s]\n" ] } ], "source": [ "import os\n", "import shutil\n", "from multiprocessing import Pool\n", "from pathlib import Path\n", "from tqdm import tqdm\n", "\n", "def copy_file(args):\n", " src, dst = args\n", " os.makedirs(os.path.dirname(dst), exist_ok=True)\n", " shutil.copy2(src, dst)\n", " return src\n", "\n", "def parallel_copy():\n", " # Source and destination paths\n", " src_dir = \"/l/users/chaimaa.abi/all_code_thesis/finetune-DM/dataset_upscaled/upscaled_VLCS\"\n", " dst_dir = \"/l/users/sarim.hashmi/Thesis/ICCV/chimaa_data/upscaled_VLCS\"\n", " \n", " # Get all files from source directory\n", " src_files = []\n", " dst_files = []\n", " \n", " for root, _, files in os.walk(src_dir):\n", " for file in files:\n", " src_path = os.path.join(root, file)\n", " # Create corresponding destination path\n", " rel_path = os.path.relpath(src_path, src_dir)\n", " dst_path = os.path.join(dst_dir, rel_path)\n", " \n", " src_files.append(src_path)\n", " dst_files.append(dst_path)\n", " \n", " # Create file pairs for mapping\n", " file_pairs = list(zip(src_files, dst_files))\n", " \n", " # Create destination directory\n", " os.makedirs(dst_dir, exist_ok=True)\n", " \n", " # Use Process Pool for parallel copying\n", " num_processes = os.cpu_count() # Use all available CPU cores\n", " print(f\"Starting copy with {num_processes} processes...\")\n", " \n", " with Pool(num_processes) as pool:\n", " # Use tqdm to show progress\n", " for _ in tqdm(pool.imap_unordered(copy_file, file_pairs), \n", " total=len(file_pairs),\n", " desc=\"Copying files\"):\n", " pass\n", "\n", "if __name__ == \"__main__\":\n", " parallel_copy()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "AI702", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.1" } }, "nbformat": 4, "nbformat_minor": 2 }