{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":6799,"databundleVersionId":4225553,"sourceType":"competition"}],"dockerImageVersionId":30804,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport json\nfrom tqdm import tqdm\n\ndef collect_image_links(directory):\n    image_links = []\n    \n    # Duyệt qua thư mục và các thư mục con\n    for root, dirs, files in tqdm(os.walk(directory), desc=\"Đang duyệt các file ảnh\", unit=\"thư mục\"):\n        for file in files:\n            # Lưu link ảnh đầy đủ\n            image_links.append(os.path.join(root, file))\n    \n    return image_links\n\ndef split_and_save(image_links, num_parts=4):\n    # Chia thành num_parts phần\n    chunk_size = len(image_links) // num_parts\n    chunks = [image_links[i:i + chunk_size] for i in range(0, len(image_links), chunk_size)]\n    \n    # Lưu mỗi phần vào một file JSON và theo dõi tiến độ\n    for i, chunk in tqdm(enumerate(chunks), desc=\"Lưu các file JSON\", unit=\"file\", total=len(chunks)):\n        with open(f'image_links_part_{i + 1}.json', 'w') as f:\n            json.dump(chunk, f, indent=4)\n\n# Đường dẫn đến thư mục chứa ảnh\ndirectory = \"/kaggle/input/imagenet-object-localization-challenge/ILSVRC/Data/CLS-LOC\"\nimage_links = collect_image_links(directory)\n\n# Chia và lưu các link ảnh vào 4 file JSON\nsplit_and_save(image_links)\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-15T17:55:11.540152Z","iopub.execute_input":"2024-12-15T17:55:11.540622Z","iopub.status.idle":"2024-12-15T18:41:30.129882Z","shell.execute_reply.started":"2024-12-15T17:55:11.540581Z","shell.execute_reply":"2024-12-15T18:41:30.128594Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import shutil\n\n# Đường dẫn nguồn và đích\nsource_path = \"/kaggle/input/imagenet-object-localization-challenge/ILSVRC/Data/CLS-LOC/train/n02105855/n02105855_2933.JPEG\"\ndestination_path = \"/kaggle/working/n02105855_2933.JPEG\"\n\n# Sao chép file\nshutil.copy(source_path, destination_path)\n\nprint(\"File đã được sao chép thành công!\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-17T18:45:25.289614Z","iopub.execute_input":"2024-12-17T18:45:25.290004Z","iopub.status.idle":"2024-12-17T18:45:25.344263Z","shell.execute_reply.started":"2024-12-17T18:45:25.289967Z","shell.execute_reply":"2024-12-17T18:45:25.34314Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}