mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-12 19:04:03 +08:00
* adding terminal window to jupyter cells for free colab users to train and render * updating torchaudio package dependency * deleting viewer connection cell, replaced with ns-train's sharable URL viewer link * fixing flying apostrophe * fixing pip torch download installation typo --------- Co-authored-by: Gina Wu <42229107+ginazhouhuiwu@users.noreply.github.com>
16 KiB
16 KiB
In [ ]:
#@markdown <h1>Install Nerfstudio and Dependencies (~8 min)</h1>
%cd /content/
!pip install --upgrade pip
!pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 torchaudio==2.0.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118
# Installing TinyCuda
%cd /content/
!gdown "https://drive.google.com/u/1/uc?id=1-7x7qQfB7bIw2zV4Lr6-yhvMpjXC84Q5&confirm=t"
!pip install tinycudann-1.7-cp310-cp310-linux_x86_64.whl
# Installing COLMAP
%cd /content/
!apt-get install colmap
# Install nerfstudio
%cd /content/
!pip install git+https://github.com/nerfstudio-project/nerfstudio.gitIn [ ]:
#@markdown <h1> Downloading and Processing Data</h1>
#@markdown <h3>Pick the preset scene or upload your own images/video</h3>
import os
import glob
from google.colab import files
from IPython.core.display import display, HTML
scene = '\uD83D\uDDBC poster' #@param ['🖼 poster', '🚜 dozer', '🌄 desolation', '📤 upload your images' , '🎥 upload your own video', '🔺 upload Polycam data', '💽 upload your own Record3D data']
scene = ' '.join(scene.split(' ')[1:])
if scene == "upload Polycam data":
%cd /content/
!mkdir -p /content/data/nerfstudio/custom_data
%cd /content/data/nerfstudio/custom_data/
uploaded = files.upload()
dir = os.getcwd()
if len(uploaded.keys()) > 1:
print("ERROR, upload a single .zip file when processing Polycam data")
dataset_dir = [os.path.join(dir, f) for f in uploaded.keys()][0]
!ns-process-data polycam --data $dataset_dir --output-dir /content/data/nerfstudio/custom_data/
scene = "custom_data"
elif scene == 'upload your own Record3D data':
display(HTML('<h3>Zip your Record3D folder, and upload.</h3>'))
display(HTML('<h3>More information on Record3D can be found <a href="https://docs.nerf.studio/en/latest/quickstart/custom_dataset.html#record3d-capture" target="_blank">here</a>.</h3>'))
%cd /content/
!mkdir -p /content/data/nerfstudio/custom_data
%cd /content/data/nerfstudio/custom_data/
uploaded = files.upload()
dir = os.getcwd()
preupload_datasets = [os.path.join(dir, f) for f in uploaded.keys()]
record_3d_zipfile = preupload_datasets[0]
!unzip $record_3d_zipfile -d /content/data/nerfstudio/custom_data
custom_data_directory = glob.glob('/content/data/nerfstudio/custom_data/*')[0]
!ns-process-data record3d --data $custom_data_directory --output-dir /content/data/nerfstudio/custom_data/
scene = "custom_data"
elif scene in ['upload your images', 'upload your own video']:
display(HTML('<h3>Select your custom data</h3>'))
display(HTML('<p/>You can select multiple images by pressing ctrl, cmd or shift and click.<p>'))
display(HTML('<p/>Note: This may take time, especially on higher resolution inputs, so we recommend to download dataset after creation.<p>'))
!mkdir -p /content/data/nerfstudio/custom_data
if scene == 'upload your images':
!mkdir -p /content/data/nerfstudio/custom_data/raw_images
%cd /content/data/nerfstudio/custom_data/raw_images
uploaded = files.upload()
dir = os.getcwd()
else:
%cd /content/data/nerfstudio/custom_data/
uploaded = files.upload()
dir = os.getcwd()
preupload_datasets = [os.path.join(dir, f) for f in uploaded.keys()]
del uploaded
%cd /content/
if scene == 'upload your images':
!ns-process-data images --data /content/data/nerfstudio/custom_data/raw_images --output-dir /content/data/nerfstudio/custom_data/
else:
video_path = preupload_datasets[0]
!ns-process-data video --data $video_path --output-dir /content/data/nerfstudio/custom_data/
scene = "custom_data"
else:
%cd /content/
!ns-download-data nerfstudio --capture-name=$scene
print("Data Processing Succeeded!")In [ ]:
#@markdown <h1>Start Training</h1>
%cd /content
!pip install colab-xterm
%load_ext colabxterm
%env TERM=xterm
from IPython.display import clear_output
clear_output(wait=True)
if os.path.exists(f"data/nerfstudio/{scene}/transforms.json"):
print("\033[1m" + "Copy and paste the following command into the terminal window that pops up under this cell." + "\033[0m")
print(f"ns-train nerfacto --viewer.websocket-port 7007 --viewer.make-share-url True nerfstudio-data --data data/nerfstudio/{scene} --downscale-factor 4")
print()
%xterm
else:
from IPython.core.display import display, HTML
display(HTML('<h3 style="color:red">Error: Data processing did not complete</h3>'))
display(HTML('<h3>Please re-run `Downloading and Processing Data`, or view the FAQ for more info.</h3>'))In [ ]:
#@title # Render Video { vertical-output: true }
#@markdown <h3>Export the camera path from within the viewer, then run this cell.</h3>
#@markdown <h5>The rendered video should be at renders/output.mp4!</h5>
base_dir = "/content/outputs/unnamed/nerfacto/"
training_run_dir = base_dir + os.listdir(base_dir)[0]
from IPython.core.display import display, HTML
display(HTML('<h3>Upload the camera path JSON.</h3>'))
%cd $training_run_dir
uploaded = files.upload()
uploaded_camera_path_filename = list(uploaded.keys())[0]
config_filename = training_run_dir + "/config.yml"
camera_path_filename = training_run_dir + "/" + uploaded_camera_path_filename
camera_path_filename = camera_path_filename.replace(" ", "\\ ").replace("(", "\\(").replace(")", "\\)")
%cd /content/
!ns-render camera-path --load-config $config_filename --camera-path-filename $camera_path_filename --output-path renders/output.mp4[2;36m[19:48:48][0m[2;36m [0mSkipping [1;36m0[0m files in dataset split train. ]8;id=527413;file:///content/nerfstudio/nerfstudio/data/dataparsers/nerfstudio_dataparser.py\[2mnerfstudio_dataparser.py[0m]8;;\[2m:[0m]8;id=243595;file:///content/nerfstudio/nerfstudio/data/dataparsers/nerfstudio_dataparser.py#91\[2m91[0m]8;;\
[2;36m [0m[2;36m [0mSkipping [1;36m0[0m files in dataset split test. ]8;id=109270;file:///content/nerfstudio/nerfstudio/data/dataparsers/nerfstudio_dataparser.py\[2mnerfstudio_dataparser.py[0m]8;;\[2m:[0m]8;id=464675;file:///content/nerfstudio/nerfstudio/data/dataparsers/nerfstudio_dataparser.py#91\[2m91[0m]8;;\
[2KLoading data batch [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [35m100%[0m [36m0:00:00[0m
[?25h/usr/local/lib/python3.7/site-packages/torch/utils/data/dataloader.py:566: UserWarning: This DataLoader will create 4 worker processes in total. Our suggested max number of worker in current system is 2, which is smaller than what this DataLoader is going to create. Please be aware that excessive worker creation might get DataLoader running slow or even freeze, lower the worker number to avoid potential slowness/freeze if necessary.
cpuset_checked))
[2KLoading data batch [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [35m100%[0m [36m0:00:00[0m
[?25h/usr/local/lib/python3.7/site-packages/torchvision/models/_utils.py:209: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead.
f"The parameter '{pretrained_param}' is deprecated since 0.13 and will be removed in 0.15, "
/usr/local/lib/python3.7/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing `weights=AlexNet_Weights.IMAGENET1K_V1`. You can also use `weights=AlexNet_Weights.DEFAULT` to get the most up-to-date weights.
warnings.warn(msg)
Loading latest checkpoint from load_dir
✅ Done loading checkpoint from
outputs/data-nerfstudio-poster/nerfacto/[1;36m2022[0m-[1;36m10[0m-29_192844/nerfstudio_models/step-[1;36m000014000.[0mckpt
[1;32mCreating trajectory video[0m
[2K🎥 Rendering 🎥 [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [35m100%[0m [31m0.14 fps[0m [33m11:47[0m
[2K[32m( ● )[0m [33mSaving video[0m
[1A[2K[92m────────────────────────────────────────────── [0m[32m 🎉 🎉 🎉 Success 🎉 🎉 🎉[0m[92m ──────────────────────────────────────────────[0m
[32mSaved video to renders/output.mp4[0m
[0m