[Neuralangelo github]
neuralangelo.yaml file이 있어 바로 이를 create 할 수 있도록 만들어두었지만, 그렇게 설치를 하면 cuda version과 cudatoolkit version이 latest version에 fit되어 설치가 되기 때문에 서로 안맞을 수 있음!
                해당 site에서 stable한 파일을 다운로드!!
(basic) 기본적인 환경 version !!
pytorch 2.0.1torchvision 0.15.2cuda 11.7cudnn 8.5.0최종적인 환경 setting 절차는 다음과 같음
  # Conda 환경 설치 (with python version 3.8)
  $ conda create -n neuralangelo python=3.8
  $ conda activate neuralangelo
                
  # [그냥 참고] pytorch 2.0.0 / torchvision 0.15.1 이렇게가 맞는 버전 !!
  **# pytorch 2.0.1 / torchvision 0.15.2 / cuda 11.7 버전으로 설치 !!**
  $ pip3 install torch-2.0.1+cu117.with.pypi.cudnn-cp38-cp38-linux_x86_64.whl
  $ pip3 install torchvision-0.15.2+cu117-cp38-cp38-linux_x86_64.whl
                
  # 나머지 dependencies 들은 pip3로 모두 설치 !!
  $ pip3 install gpustat
  $ pip3 install gdown
  $ pip3 install cmake
  $ pip3 install scipy
  $ pip3 install ipython
  $ pip3 install jupyterlab
  $ pip3 install cython
  $ pip3 install ninja
  $ pip3 install diskcache
                
  # 그리고 나머지 dependencies 들은 requirements.txt에 있음 !!
  **# [중요!!!] git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch 를 지우고 나머지 설치 !!!**
  $ pip3 install -r requirements.txt
                
  # 마지막 cudatoolkit-dev 설치 ! 
  **# (cudatoolkit-dev가 11.8을 작성 당시에는 제공하지 않으므로 11.7로 fit하게 환경을 설정하였음 !)**
  $ conda install -c conda-forge cudatoolkit-dev=11.7 
해당 workspace에 github code clone
  $ git clone https://github.com/NVlabs/neuralangelo.git
tiny-cuda-nn의 package는 따로 github에 가서 clone을 진행하여 수동 설치를 진행해야함! (에러를 해결하기 위해!!)
github site
  $ cd neuralangelo/third_party
  $ git clone --recursive https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch
neuralangelo github page처럼 pip3 install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch 로 해버리면 error가 발생하기 때문에 수동 설치를 진행 !
[1] conda 기반으로 설치를 하였기 때문에 해당 경로를 export하여 지정해줄 필요가 있음
  $ export PATH="/home/sj/anaconda3/envs/neuralangelo/pkgs:$PATH"
  $ export LD_LIBRARY_PATH="/home/sj/anaconda3/envs/neuralangelo/lib:$LD_LIBRARY_PATH"
[2] tiny-cuda-nn 을 설치해줄 python code로 이동
  $ cd tiny-cuda-nn/bindings/torch
[3] setup.py 로 들어가서 마지막 코드 수정 (에러를 방지하기 위해)
  # Before
  cmdclass={"build_ext": BuildExtension}
            
  # After
  cmdclass={'build_ext': BuildExtension.with_options(use_ninja=False)}
[4] 그리고 수정된 setup.py를 install (시간 조금 소요됨 !)
  $ pip3 setup.py install
RuntimeError: Error compiling objects for extensionsetup.py로 들어가서 마지막 코드 수정
  # Before
  cmdclass={"build_ext": BuildExtension}
                
  # After
  cmdclass={'build_ext': BuildExtension.with_options(use_ninja=False)}
fatal error: filesystem: No such file or directorytiny-cuda-nn의 package는 c++ 17 version을 요구 (gcc & g++ 기준 8.x.x 이상) 하고 있는데 본 저자의 desktop에 설치되어 있는 저자의 gcc version은 7.5.0이므로 본 gcc 버전을 upgrade 및 main version으로 지정
[1] gcc version 확인
  $ gcc --version
[2] gcc 버전이 8.x.x 보다 작으면 해당 버전으로 추가 설치
  $ sudo apt install gcc-8 g++-8
[3] 최신 버전의 gcc를 default로 설정
  $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 700 --slave /usr/bin/g++ g++ /usr/bin/g++-7
  $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8
[4] 변경된 default gcc 버전 확인
  $ gcc --version
Neuralangelo에서 요구하는 input dataset 구조 및 이름 (파일 이름도 맞춰주기!)
  DATA_PATH
  ├─ database.db      (COLMAP database)
  ├─ images           (undistorted input images)
  ├─ images_raw       (raw input images)
  ├─ sparse           (COLMAP data from SfM)
  │  ├─ cameras.bin   (camera parameters)
  │  ├─ images.bin    (images and camera poses)
  │  ├─ points3D.bin  (sparse point clouds)
  │  ├─ 0             (a directory containing individual SfM models. There could also be 1, 2... etc.)
  │  ...
  ├─ stereo (COLMAP data for MVS, not used here)
  │
  ├─ transforms.json  (Relative camera poses)
  ├─ {SEQUENCE}.yaml  (Hyperparameters config file)
한번에 요구하는 dataset 구조로 만들어주는 bash file도 있고 순차적으로 만들어주는 bash file도 제공하고 있음 !!
Default Setting !
  SEQUENCE=lego # your custom name for the video sequence.
  PATH_TO_VIDEO=lego.mp4 # absolute/relative path to your video.
  DOWNSAMPLE_RATE=2 # temporal downsampling rate of video sequence (for extracting video frames).
  SCENE_TYPE=object # {outdoor,indoor,object} 중 하나! 
[Case 1] 한번에 변환해주는 shell file !!
  # End-to-end dataset generation !!
  sh ./projects/neuralangelo/scripts/preprocess.sh ${SEQUENCE} ${PATH_TO_VIDEO} ${DOWNSAMPLE_RATE} ${SCENE_TYPE}
[Sample] 본 저자의 custom dataset으로 colmap 만든 결과
  # 1분짜리 / downsample rate 2로 두고 colmap end-to-end로 돌리면 약 887장 이미지 생성 + 약 6시간 정도 걸림
  # **B301.yaml file도 만들어줌**! -> 이거 가지고 train.py에 이용하면 됨!!
  # [Example of b301.yaml]
  _parent_: projects/neuralangelo/configs/base.yaml
  data:
      readjust:
          center:
          - 0.0
          - 0.0
          - 0.0
          scale: 1.0
      root: datasets/b301_ds2
      train:
          image_size:
          - 1065
          - 1894
      type: projects.neuralangelo.data
      val:
          image_size:
          - 300
          - 533
  model:
      appear_embed:
          enabled: false
      background:
          enabled: false
      object:
          sdf:
              encoding:
                  coarse2fine:
                      init_active_level: 8
              mlp:
                  inside_out: true
      render:
          num_samples:
              background: 0
[Case 2] 순차적으로 변환해주는 shell file !! (보고 없는 파일들만 생성하면 좋을듯!!)
  # 이미지 생성만 !
  sh projects/neuralangelo/scripts/run_ffmpeg.sh ${SEQUENCE} ${PATH_TO_VIDEO} ${DOWNSAMPLE_RATE}
                    
  # 이미지들을 이용하여 COLMAP 진행 !
  DATA_PATH=datasets/${SEQUENCE}_ds${DOWNSAMPLE_RATE}
  sh projects/neuralangelo/scripts/run_colmap.sh ${DATA_PATH}
                    
  # COLMAP 결과를 이용하여 JSON file 생성 !
  python3 ./projects/neuralangelo/scripts/convert_data_to_json.py --data_dir ${DATA_PATH} --scene_type ${SCENE_TYPE}
                    
  # 위의 결과들을 이용하여 config file 생성 !
  python3 ./projects/neuralangelo/scripts/generate_config.py --sequence_name ${SEQUENCE} --data_dir ${DATA_PATH} --scene_type ${SCENE_TYPE}
[Reference Site]
Default Setting
  EXPERIMENT=toy_example
  GROUP=example_group
  NAME=example_name
  CONFIG=projects/neuralangelo/configs/custom/${EXPERIMENT}.yaml
  GPUS=1  # use >1 for multi-GPU training!
Training
  torchrun --nproc_per_node=${GPUS} train.py \
  			   --logdir=logs/${GROUP}/${NAME} \
  		     --config=${CONFIG} \
  		     --show_pbar
변경할 hyperparameter 변수 → **model.object.sdf.encoding.hashgrid**
| GPU VRAM | Hyperparamter | 
|---|---|
| 8GB | dict_size=20, dim=4 | 
| 12GB | dict_size=21, dim=4 | 
| 16GB | dict_size=21, dim=8 | 
Reference Site
max_iter: 500000 로 되어 있어 본 저자는 200000로 setting !Default Setting
  CHECKPOINT=logs/${GROUP}/${NAME}/epoch_00451_iteration_000200000_checkpoint.pt # exmaple
  OUTPUT_MESH=xxx.ply
  CONFIG=logs/${GROUP}/${NAME}/config.yaml
  RESOLUTION=2048
  BLOCK_RES=128
  GPUS=1  # use >1 for multi-GPU mesh extraction
Extract Meshing
  torchrun --nproc_per_node=${GPUS} projects/neuralangelo/scripts/extract_mesh.py \
      --config=${CONFIG} \
      --checkpoint=${CHECKPOINT} \
      --output_file=${OUTPUT_MESH} \
      --resolution=${RESOLUTION} \
      --block_res=${BLOCK_RES} \
  		--textured # extract meshes with textures !!
pip3 install open3dVisualization base code
  from open3d import *    
            
  def main():
      ply_path = "./xxx.ply" 
      cloud = io.read_point_cloud(ply_path) # Read point cloud
      visualization.draw_geometries([cloud])    # Visualize point cloud      
            
  if __name__ == "__main__":
      main()
 
  Reference Site
dict_size=21, dim=4 로 train 시키면 Out of Memory 가 발생 
   
   
  