From b63d5854a135cf516e08376f29c4d8696ae18ffa Mon Sep 17 00:00:00 2001 From: Ethan Weber Date: Sat, 2 Apr 2022 20:07:41 +0000 Subject: [PATCH] reworked structure to use packages --- .gitmodules | 3 + .vscode/settings.json | 16 +++++ README.md | 24 +++++++ environment/README.md | 20 ++++++ environment/mattport.dockerfile | 75 ++++++++++++++++++++ environment/requirements.txt | 6 ++ external/goat | 1 + nerf/README.md => mattport/nerf/__init__.py | 0 {nerf => mattport/nerf}/encodings.py | 5 +- viewer/README.md => mattport/sfm/__init__.py | 0 mattport/viewer/__init__.py | 0 scripts/run_train_nerf.py | 5 ++ setup.py | 11 +++ 13 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 100644 .vscode/settings.json create mode 100644 environment/README.md create mode 100644 environment/mattport.dockerfile create mode 100644 environment/requirements.txt create mode 160000 external/goat rename nerf/README.md => mattport/nerf/__init__.py (100%) rename {nerf => mattport/nerf}/encodings.py (99%) rename viewer/README.md => mattport/sfm/__init__.py (100%) create mode 100644 mattport/viewer/__init__.py create mode 100644 scripts/run_train_nerf.py create mode 100644 setup.py diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..a1d85b4ff --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/goat"] + path = external/goat + url = git@github.com:ethanweber/goat.git diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..d805b1d30 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,16 @@ +{ + // "python.pythonPath": "/path/to/bin/python", + "files.watcherExclude": { + "**/__pycache__/": true, + "**/.ipynb_checkpoints": true, + "**/*.ipynb": true, + "**/runs*": true, + }, + "python.formatting.provider": "black", + "python.formatting.blackArgs": [ + "--line-length=120" + ], + "python.linting.pylintEnabled": false, + "python.linting.flake8Enabled": true, + "python.linting.enabled": true, +} \ No newline at end of file diff --git a/README.md b/README.md index e69de29bb..f0be6b824 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,24 @@ +# MattPort + + +# Setup the environment + +``` +# Clone the repo +git clone --recurse-submodules git@github.com:ethanweber/mattport.git + +# Create the python environment +conda create --name mattport python=3.8 +conda activate mattport +pip install -r environment/requirements.txt + +# Install helper library +cd external/goat +python setup.py develop + +# For using with Jupyter +python -m ipykernel install --user --name mattport --display-name "mattport" + +# Install mattport as a library +python setup.py develop +``` \ No newline at end of file diff --git a/environment/README.md b/environment/README.md new file mode 100644 index 000000000..bf98aae6b --- /dev/null +++ b/environment/README.md @@ -0,0 +1,20 @@ +# Environment + +# Installing docker + +#### Troubleshooting + +``` +# https://forums.docker.com/t/failing-to-start-dockerd-failed-to-create-nat-chain-docker/78269 +sudo update-alternatives --set iptables /usr/sbin/iptables-legacy +sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy +sudo service docker start + +VERSION_STRING=18.03.1~ce~3-0~ubuntu +sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io + +# https://github.com/docker/for-linux/issues/123#issuecomment-346546953 +sudo ip link add name docker0 type bridge +sudo ip addr add dev docker0 172.17.0.1/16 +sudo dockerd --debug --iptables=false +``` \ No newline at end of file diff --git a/environment/mattport.dockerfile b/environment/mattport.dockerfile new file mode 100644 index 000000000..aa8bad9b1 --- /dev/null +++ b/environment/mattport.dockerfile @@ -0,0 +1,75 @@ +FROM nvidia/cuda:10.2-devel-ubuntu18.04 + +# Set the shell to /bin/bash instead of /bin/sh so conda works correctly. +# https://towardsdatascience.com/conda-pip-and-docker-ftw-d64fe638dc45 +SHELL [ "/bin/bash", "--login", "-c" ] + +# Prepare and empty machine for building +RUN apt-get update && apt-get install -y \ + git \ + cmake \ + vim \ + build-essential \ + libboost-program-options-dev \ + libboost-filesystem-dev \ + libboost-graph-dev \ + libboost-system-dev \ + libboost-test-dev \ + libeigen3-dev \ + libsuitesparse-dev \ + libfreeimage-dev \ + libgoogle-glog-dev \ + libgflags-dev \ + libglew-dev \ + qtbase5-dev \ + libqt5opengl5-dev \ + libcgal-dev \ + libcgal-qt5-dev \ + wget + +# Build and install ceres solver +RUN apt-get -y install \ + libatlas-base-dev \ + libsuitesparse-dev +RUN git clone https://github.com/ceres-solver/ceres-solver.git --branch 1.14.0 +RUN cd ceres-solver && \ + mkdir build && \ + cd build && \ + cmake .. -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF && \ + make -j4 && \ + make install + +# Clear space # https://askubuntu.com/questions/179955/var-lib-apt-lists-is-huge +RUN rm -rf /var/lib/apt/lists/* + +# Build and install COLMAP + +# Note: This Dockerfile has been tested using COLMAP pre-release 3.6. +# Later versions of COLMAP (which will be automatically cloned as default) may +# have problems using the environment described thus far. If you encounter +# problems and want to install the tested release, then uncomment the branch +# specification in the line below +RUN git clone https://github.com/colmap/colmap.git #--branch 3.6 + +RUN cd colmap && \ + git checkout dev && \ + mkdir build && \ + cd build && \ + cmake .. && \ + make -j4 && \ + make install + +# Install Conda +ENV PATH="/root/miniconda3/bin:${PATH}" +ARG PATH="/root/miniconda3/bin:${PATH}" +RUN wget \ + https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \ + && mkdir /root/.conda \ + && bash Miniconda3-latest-Linux-x86_64.sh -b \ + && rm -f Miniconda3-latest-Linux-x86_64.sh +RUN conda --version + +# Install friends conda environment +COPY ./run_install_friends_conda.sh /tmp/run_install_friends_conda.sh +COPY ./requirements_friends.txt /tmp/requirements_friends.txt +RUN yes "Y" | bash /tmp/run_install_friends_conda.sh diff --git a/environment/requirements.txt b/environment/requirements.txt new file mode 100644 index 000000000..c1b62abdf --- /dev/null +++ b/environment/requirements.txt @@ -0,0 +1,6 @@ +pylint==2.13.4 +torch==1.11.0 +torchvision==0.12.0 +torchaudio==0.11.0 +black +flake8 \ No newline at end of file diff --git a/external/goat b/external/goat new file mode 160000 index 000000000..967c4a806 --- /dev/null +++ b/external/goat @@ -0,0 +1 @@ +Subproject commit 967c4a806eaeb86f5326b8d5b2b8136b079568fa diff --git a/nerf/README.md b/mattport/nerf/__init__.py similarity index 100% rename from nerf/README.md rename to mattport/nerf/__init__.py diff --git a/nerf/encodings.py b/mattport/nerf/encodings.py similarity index 99% rename from nerf/encodings.py rename to mattport/nerf/encodings.py index e89cd60cc..e25c3a50e 100644 --- a/nerf/encodings.py +++ b/mattport/nerf/encodings.py @@ -26,6 +26,7 @@ class Encoding(nn.Module): class RFFEncoding(Encoding): """Random Fourier Feature encoding""" + def encode(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]: """Encodes an input tensor. @@ -40,6 +41,7 @@ class RFFEncoding(Encoding): class HashEncoding(Encoding): """Hash encoding""" + def encode(self, in_tensor: TensorType[..., "input_dim"]) -> TensorType[..., "output_dim"]: """Encodes an input tensor. @@ -51,7 +53,8 @@ class HashEncoding(Encoding): """ raise NotImplementedError + encodings_dict = { "RFF": RFFEncoding, "hash": HashEncoding, -} \ No newline at end of file +} diff --git a/viewer/README.md b/mattport/sfm/__init__.py similarity index 100% rename from viewer/README.md rename to mattport/sfm/__init__.py diff --git a/mattport/viewer/__init__.py b/mattport/viewer/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/scripts/run_train_nerf.py b/scripts/run_train_nerf.py new file mode 100644 index 000000000..aaa3ffc7b --- /dev/null +++ b/scripts/run_train_nerf.py @@ -0,0 +1,5 @@ +import os +import mattport.nerf as nerf + +if __name__ == "__main__": + print("hello mattport") diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..e6753d2cc --- /dev/null +++ b/setup.py @@ -0,0 +1,11 @@ +import setuptools + +setuptools.setup( + name="mattport", + version="1.0.0", + author="MattPort", + url="https://github.com/ethanweber/mattport.git", + description="mattport description", + packages=setuptools.find_packages(), + python_requires=">=3.8", +) \ No newline at end of file