Run this cell only if you are uploading your own data. Installation takes a while to complete.
\n",
"\n",
"# Installing COLMAP via conda\n",
"%cd /content\n",
"!conda install -c conda-forge colmap"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "msVLprI4gRA4"
},
"outputs": [],
"source": [
"#@markdown Downloading and Processing Data
\n",
"#@markdown Pick the preset scene or upload your own images/video\n",
"\n",
"import os\n",
"import glob\n",
"from google.colab import files\n",
"from IPython.core.display import display, HTML\n",
"\n",
"scene = '\\uD83D\\uDDBC poster' #@param ['🖼 poster', '🚜 dozer', '🌄 desolation', '📤 upload your images' , '🎥 upload your own video', '🔺 upload Polycam data', '💽 upload your own Record3D data']\n",
"scene = ' '.join(scene.split(' ')[1:])\n",
"\n",
"if scene == \"upload Polycam data\":\n",
" %cd /content/\n",
" !mkdir -p /content/data/nerfstudio/custom_data\n",
" %cd /content/data/nerfstudio/custom_data/\n",
" uploaded = files.upload()\n",
" dir = os.getcwd()\n",
" if len(uploaded.keys()) > 1:\n",
" print(\"ERROR, upload a single .zip file when processing Polycam data\")\n",
" dataset_dir = [os.path.join(dir, f) for f in uploaded.keys()][0]\n",
" !ns-process-data polycam --data $dataset_dir --output-dir /content/data/nerfstudio/custom_data/\n",
" scene = \"custom_data\"\n",
"elif scene == 'upload your own Record3D data':\n",
" display(HTML('Zip your Record3D folder, and upload.
'))\n",
" display(HTML('More information on Record3D can be found here.
'))\n",
" %cd /content/\n",
" !mkdir -p /content/data/nerfstudio/custom_data\n",
" %cd /content/data/nerfstudio/custom_data/\n",
" uploaded = files.upload()\n",
" dir = os.getcwd()\n",
" preupload_datasets = [os.path.join(dir, f) for f in uploaded.keys()]\n",
" record_3d_zipfile = preupload_datasets[0]\n",
" !unzip $record_3d_zipfile -d /content/data/nerfstudio/custom_data\n",
" custom_data_directory = glob.glob('/content/data/nerfstudio/custom_data/*')[0]\n",
" !ns-process-data record3d --data $custom_data_directory --output-dir /content/data/nerfstudio/custom_data/\n",
" scene = \"custom_data\"\n",
"elif scene in ['upload your images', 'upload your own video']:\n",
" display(HTML('Select your custom data
'))\n",
" display(HTML('You can select multiple images by pressing ctrl, cmd or shift and click.'))\n",
" display(HTML('
Note: This may take time, especially on higher resolution inputs, so we recommend to download dataset after creation.'))\n",
" !mkdir -p /content/data/nerfstudio/custom_data\n",
" if scene == 'upload your images':\n",
" !mkdir -p /content/data/nerfstudio/custom_data/raw_images\n",
" %cd /content/data/nerfstudio/custom_data/raw_images\n",
" uploaded = files.upload()\n",
" dir = os.getcwd()\n",
" else:\n",
" %cd /content/data/nerfstudio/custom_data/\n",
" uploaded = files.upload()\n",
" dir = os.getcwd()\n",
" preupload_datasets = [os.path.join(dir, f) for f in uploaded.keys()]\n",
" del uploaded\n",
" %cd /content/\n",
"\n",
" if scene == 'upload your images':\n",
" !ns-process-data images --data /content/data/nerfstudio/custom_data/raw_images --output-dir /content/data/nerfstudio/custom_data/\n",
" else:\n",
" video_path = preupload_datasets[0]\n",
" !ns-process-data video --data $video_path --output-dir /content/data/nerfstudio/custom_data/\n",
"\n",
" scene = \"custom_data\"\n",
"else:\n",
" %cd /content/\n",
" !ns-download-data nerfstudio --capture-name=$scene\n",
"\n",
"print(\"Data Processing Succeeded!\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "m_N8_cLfjoXD"
},
"outputs": [],
"source": [
"#@markdown
Start Training
\n",
"#@markdown Open the generated share url to access viewer.
\n",
"\n",
"%cd /content\n",
"if os.path.exists(f\"data/nerfstudio/{scene}/transforms.json\"):\n",
" !ns-train nerfacto --viewer.websocket-port 7007 --vis viewer_beta --viewer.make-share-url True nerfstudio-data --data data/nerfstudio/$scene --downscale-factor 4\n",
"else:\n",
" from IPython.core.display import display, HTML\n",
" display(HTML('Error: Data processing did not complete
'))\n",
" display(HTML('Please re-run `Downloading and Processing Data`, or view the FAQ for more info.
'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "WGt8ukG6Htg3",
"outputId": "fa946890-c7d8-4e46-a54e-7231bc5a2059"
},
"outputs": [],
"source": [
"#@title # Render Video { vertical-output: true }\n",
"#@markdown Export the camera path from within the viewer, then run this cell.
\n",
"#@markdown The rendered video should be at renders/output.mp4!\n",
"\n",
"base_dir = \"/content/outputs/unnamed/nerfacto/\"\n",
"training_run_dir = base_dir + os.listdir(base_dir)[0]\n",
"\n",
"from IPython.core.display import display, HTML\n",
"display(HTML('Upload the camera path JSON.
'))\n",
"%cd $training_run_dir\n",
"uploaded = files.upload()\n",
"uploaded_camera_path_filename = list(uploaded.keys())[0]\n",
"\n",
"config_filename = training_run_dir + \"/config.yml\"\n",
"camera_path_filename = training_run_dir + \"/\" + uploaded_camera_path_filename\n",
"camera_path_filename = camera_path_filename.replace(\" \", \"\\\\ \").replace(\"(\", \"\\\\(\").replace(\")\", \"\\\\)\")\n",
"\n",
"%cd /content/\n",
"!ns-render camera-path --load-config $config_filename --camera-path-filename $camera_path_filename --output-path renders/output.mp4"
]
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"include_colab_link": true,
"provenance": []
},
"gpuClass": "standard",
"kernelspec": {
"display_name": "Python 3.8.13 ('nerfstudio')",
"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.10.12"
},
"vscode": {
"interpreter": {
"hash": "c59f626636933ef1dc834fb3684b382f705301c5306cf8436d2da634c2289783"
}
}
},
"nbformat": 4,
"nbformat_minor": 0
}