{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":71885,"databundleVersionId":8143495,"sourceType":"competition"},{"sourceId":8009917,"sourceType":"datasetVersion","datasetId":4717145},{"sourceId":8012513,"sourceType":"datasetVersion","datasetId":4716621},{"sourceId":8020861,"sourceType":"datasetVersion","datasetId":4726332},{"sourceId":8020877,"sourceType":"datasetVersion","datasetId":4726098},{"sourceId":8029536,"sourceType":"datasetVersion","datasetId":4732630},{"sourceId":8030577,"sourceType":"datasetVersion","datasetId":4726448}],"dockerImageVersionId":30674,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!git clone --recursive https://github.com/borglab/gtsfm.git","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:28:13.819839Z","iopub.execute_input":"2024-04-04T18:28:13.820647Z","iopub.status.idle":"2024-04-04T18:28:29.332038Z","shell.execute_reply.started":"2024-04-04T18:28:13.820600Z","shell.execute_reply":"2024-04-04T18:28:29.331061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nos.chdir('./gtsfm')\n!pwd","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:28:29.334001Z","iopub.execute_input":"2024-04-04T18:28:29.334288Z","iopub.status.idle":"2024-04-04T18:28:30.269157Z","shell.execute_reply.started":"2024-04-04T18:28:29.334260Z","shell.execute_reply":"2024-04-04T18:28:30.268134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install black\n!pip install coverage\n!pip install mypy\n!pip install pylint\n!pip install pytest\n!pip install flake8\n!pip install isort\n  # dask and related\n!pip install dask[complete]\n!pip install asyncssh\n!pip install python-graphviz\n  # core functionality and APIs\n!pip install matplotlib==3.4.2\n!pip install networkx\n!pip install numpy\n!pip install nodejs\n!pip install pandas\n!pip install pillow>=8.0.1\n!pip install scikit-learn\n!pip install seaborn\n!pip install scipy\n!pip install hydra-core\n  # 3rd party algorithms for different modules\n!pip install cudatoolkit>=10.2\n!pip install pytorch>=1.12.0\n!pip install torchvision>=0.13.0\n!pip install kornia\n  # io\n!pip install h5py\n!pip install plotly=4.14.3\n!pip install tabulate\n!pip install simplejson\n  # testing\n!pip install parameterized\n!pip install open3d\n!pip install opencv-python>=4.5.4.58\n!pip install pydegensac\n!pip install colour\n!pip install pycolmap==0.4.0\n!pip install trimesh[easy]\n!pip install gtsam==4.2\n!pip install pydot","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:28:30.270680Z","iopub.execute_input":"2024-04-04T18:28:30.270992Z","iopub.status.idle":"2024-04-04T18:37:24.466169Z","shell.execute_reply.started":"2024-04-04T18:28:30.270963Z","shell.execute_reply":"2024-04-04T18:37:24.464969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -e .","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:37:24.470376Z","iopub.execute_input":"2024-04-04T18:37:24.470701Z","iopub.status.idle":"2024-04-04T18:37:41.292496Z","shell.execute_reply.started":"2024-04-04T18:37:24.470671Z","shell.execute_reply":"2024-04-04T18:37:41.291398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!./download_model_weights.sh","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:37:41.293847Z","iopub.execute_input":"2024-04-04T18:37:41.294151Z","iopub.status.idle":"2024-04-04T18:37:58.325836Z","shell.execute_reply.started":"2024-04-04T18:37:41.294123Z","shell.execute_reply":"2024-04-04T18:37:58.324674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import gtsfm\nimport gtsam","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:37:58.327612Z","iopub.execute_input":"2024-04-04T18:37:58.328561Z","iopub.status.idle":"2024-04-04T18:37:58.393787Z","shell.execute_reply.started":"2024-04-04T18:37:58.328519Z","shell.execute_reply":"2024-04-04T18:37:58.392774Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir sad\n%cd sad\n!mkdir images\n!cp -r /kaggle/input/random-scenes-for-3d-rec /kaggle/working/sad/images","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:37:58.394957Z","iopub.execute_input":"2024-04-04T18:37:58.395218Z","iopub.status.idle":"2024-04-04T18:38:01.232148Z","shell.execute_reply.started":"2024-04-04T18:37:58.395196Z","shell.execute_reply":"2024-04-04T18:38:01.231219Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image, ExifTags\nimport os\n \n# Function to resize images in a directory\ndef resize_images_in_directory(input_dir, output_dir, new_width, new_height):\n    # Create the output directory if it doesn't exist\n    if not os.path.exists(output_dir):\n        os.makedirs(output_dir)\n \n    # Loop through all files in the input directory\n    for filename in os.listdir(input_dir):\n        try:\n            # Open the image file\n            image = Image.open(os.path.join(input_dir, filename))\n \n            # Resize the image\n            resized_image = image.resize((new_width, new_height), Image.LANCZOS)\n \n            # Preserve EXIF data\n            if \"exif\" in image.info:\n                exif_info = image.info[\"exif\"]\n                resized_image.save(os.path.join(output_dir, filename), exif=exif_info)\n            else:\n                resized_image.save(os.path.join(output_dir, filename))\n \n        except Exception as e:\n            print(f\"Error resizing {filename}: {e}\")\n\n","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:28:10.074626Z","iopub.status.idle":"2024-04-04T18:28:10.075357Z","shell.execute_reply.started":"2024-04-04T18:28:10.075160Z","shell.execute_reply":"2024-04-04T18:28:10.075179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\nimport os\n\ndef move_files(source_dir, dest_dir):\n    # Get a list of all files in the source directory\n    files = os.listdir(source_dir)\n    \n    # Move each file to the destination directory\n    for file in files:\n        source_path = os.path.join(source_dir, file)\n        dest_path = os.path.join(dest_dir, file)\n        shutil.copy(source_path, dest_path)\n\n# # Example usage:\n# source_directory = '/kaggle/input/dataset-home/data'\n# destination_directory = '/kaggle/working/images'\n\n# move_files(source_directory, destination_directory)","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:38:01.233558Z","iopub.execute_input":"2024-04-04T18:38:01.233825Z","iopub.status.idle":"2024-04-04T18:38:01.240404Z","shell.execute_reply.started":"2024-04-04T18:38:01.233798Z","shell.execute_reply":"2024-04-04T18:38:01.239439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# %cd /kaggle/working/gtsfm\n!rm -r /kaggle/working/images\n# mkdir /kaggle/working/images\n# !pwd\n# %cd .. \n!mkdir /kaggle/working/images\nnew_width = 1524\nnew_height = 2032\n\nmove_files('/kaggle/input/room60/collegelabbb', '/kaggle/working/images')\n","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:38:01.241689Z","iopub.execute_input":"2024-04-04T18:38:01.242146Z","iopub.status.idle":"2024-04-04T18:38:04.818218Z","shell.execute_reply.started":"2024-04-04T18:38:01.242114Z","shell.execute_reply":"2024-04-04T18:38:04.816955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import time\n\nstart_time = time.time()\n\n!python /kaggle/working/gtsfm/gtsfm/runner/run_scene_optimizer_olssonloader.py >/dev/null --dataset_root /kaggle/working --config_name deep_front_end.yaml --num_workers 4 --output_root /kaggle/working/\n\nend_time = time.time()\nexecution_time = end_time - start_time\n\nprint(\"Execution time:\", execution_time, \"seconds\")\n","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:38:04.822090Z","iopub.execute_input":"2024-04-04T18:38:04.822724Z","iopub.status.idle":"2024-04-04T18:44:11.657034Z","shell.execute_reply.started":"2024-04-04T18:38:04.822691Z","shell.execute_reply":"2024-04-04T18:44:11.655953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !ls /kaggle/input/random-scenes-for-3d-rec","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:28:10.081455Z","iopub.status.idle":"2024-04-04T18:28:10.081778Z","shell.execute_reply.started":"2024-04-04T18:28:10.081621Z","shell.execute_reply":"2024-04-04T18:28:10.081635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from PIL import Image\n# from PIL.ExifTags import TAGS\n# import os \n# def get_exif_data(image_path):\n#     counter = 0\n#     for i in os.listdir(image_path):\n#         exif_data = {}\n#         try:\n#             print(image_path + \"/\" + i)\n#             with Image.open(image_path + \"/\" + i) as img:\n#                 # Check if the image contains EXIF metadata\n#                 if hasattr(img, '_getexif'):\n#                     # Get the EXIF metadata\n#                     exif_info = img._getexif()\n#                     if exif_info:\n#                         for tag, value in exif_info.items():\n#                             tag_name = TAGS.get(tag, tag)\n#                             exif_data[tag_name] = value\n#         except:\n#             print(\"An error occurred while processing the image.\")\n#         print(counter)\n#         counter+=1\n\n# # Example usage:?\n# image_path = '/kaggle/input/dataset-home/data'  # Replace with the path to your JPEG image\n# exif_data = get_exif_data(image_path)\n# for tag, value in exif_data.items():\n#     print(f\"{tag}: {value}\")\n","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:28:10.083436Z","iopub.status.idle":"2024-04-04T18:28:10.083764Z","shell.execute_reply.started":"2024-04-04T18:28:10.083606Z","shell.execute_reply":"2024-04-04T18:28:10.083619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !cat /kaggle/working/gtsfm/gtsfm/loader/loader_base.py","metadata":{"execution":{"iopub.status.busy":"2024-04-04T18:28:10.084883Z","iopub.status.idle":"2024-04-04T18:28:10.085222Z","shell.execute_reply.started":"2024-04-04T18:28:10.085065Z","shell.execute_reply":"2024-04-04T18:28:10.085079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}