|
1 | | -Installation |
2 | | ------------- |
| 1 | +******************* |
| 2 | +Building Detectree2 |
| 3 | +******************* |
| 4 | + |
| 5 | +============================== |
| 6 | +Getting up and running quickly |
| 7 | +============================== |
| 8 | + |
| 9 | +To get up and running quickly it is possible to install detectree2 and its dependencies with Conda. Simply do:: |
| 10 | + |
| 11 | + conda install -c ma595 detectree2 |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +========= |
| 16 | +Using pip |
| 17 | +========= |
| 18 | + |
| 19 | +It is easy to install detectree2 on your own system. Simply pip install and all dependencies will be installed automatically. |
| 20 | + |
| 21 | + See workflow `python-app.yaml <https://github.com/PatBall1/detectree2/tree/master/.github/workflows/python-app.yml>`_ workflow for a working CPU deployment. |
| 22 | + |
| 23 | +First install ``pytorch``, ``torchvision`` and ``torchaudio`` (compatible versions https://pypi.org/project/torchvision/). Follow `https://pytorch.org/get-started/locally/`_ to get compatible version for your system. Below we run through the process with pip but the conda approach is equally valid. |
| 24 | + |
| 25 | +This can be done inside ``virtualenv`` (if root access is unavailable):: |
| 26 | + |
| 27 | + python3 -m venv ./venv # (check version of python is sufficiently high >=3.7, required by detectron2) |
| 28 | + . venv/bin/activate |
| 29 | + pip install --upgrade pip |
| 30 | + pip install wheel |
| 31 | + pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113 |
| 32 | + |
| 33 | +Then point to preinstalled GDAL header files (not necessary if include directory is already in your path):: |
| 34 | + |
| 35 | + export CPLUS_INCLUDE_PATH=/usr/include/gdal |
| 36 | + export C_INCLUDE_PATH=/usr/include/gdal |
| 37 | + |
| 38 | +then:: |
| 39 | + |
| 40 | + git clone git@github.com:PatBall1/detectree2.git |
| 41 | + cd detectree2 |
| 42 | + pip install . # (add -e flag to allow editable installs) |
| 43 | + |
| 44 | +On other systems the process is more involved especially if root access is not available. |
| 45 | + |
| 46 | + |
| 47 | +.. todo:: |
| 48 | + |
| 49 | + * https://detectron2.readthedocs.io/en/latest/tutorials/install.html |
| 50 | + * http://www.tekroi.in/detectron2/projects/DensePose/setup.py |
| 51 | + * https://stackoverflow.com/questions/66738473/installing-pytorch-with-cuda-in-setup-py |
| 52 | + |
| 53 | + |
| 54 | +Possible issues with GDAL |
| 55 | +------------------------- |
| 56 | +GDAL presents a number of complexities. The issue is covered in `gdal/issue <https://github.com/PatBall1/detectree2/issues/1>`_ We must point to the location of the preinstalled GDAL headers, and the GDAL version must match the pip package version. https://github.com/OSGeo/gdal/issues/2293 |
| 57 | +For instance, on my cluster:: |
| 58 | + |
| 59 | + gdal-config -v # gives 3.0.4 |
| 60 | + |
| 61 | +So this means we must install the corresponding pip version: ``GDAL==3.0.4`` or lower. To avoid problems, the version of the system GDAL should be higher than the version bindings. |
| 62 | +.. |
| 63 | + https://gis.stackexchange.com/questions/188639/adding-gdal-as-dependency-to-python-package |
| 64 | +In the event that GDAL does not exist on the system, install it as so (assuming root access):: |
| 65 | + |
| 66 | + sudo apt install libgdal-dev gdal-bin |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +=============================== |
| 73 | +Building Detectree2 using Conda |
| 74 | +================================ |
| 75 | +Many of the aforementioned complexities with pip, GDAL and detectron2 can be solved with Conda. This is currently working for python 3.9.13, in branch `matt/conda <https://github.com/PatBall1/detectree2/tree/matt/conda>`_. The most important file is `environment.yaml <https://github.com/PatBall1/detectree2/blob/matt/conda/conda/environment.yaml>`_ which specifies the required dependencies. |
| 76 | + |
| 77 | +Install miniconda, and source (usually ``~/.miniconda/bin/activate`` if not in ``.bashrc`` already). Begin by installing ``mamba``:: |
| 78 | + |
| 79 | + conda install mamba -c conda-forge |
| 80 | + |
| 81 | +And then create the detectree2 environment: |
| 82 | + |
| 83 | + mamba env create -f envrironment.yaml |
| 84 | + mamba activate detectree2env |
| 85 | + |
| 86 | +Alternatively we may use a conda lock file which has transitive dependencies pinned. This improves reproducibility.:: |
| 87 | + |
| 88 | + mamba create --name detectree2env --file conda-linux-64.lock |
| 89 | + |
| 90 | +and if we modify our environment, we can update the lock file as so:: |
| 91 | + |
| 92 | + conda-lock -k explicit --conda mamba |
| 93 | + |
| 94 | +and then update conda packages based on the regenerated lock file:: |
| 95 | + |
| 96 | + mamba update --file conda-linux-64.lock |
| 97 | + |
| 98 | +The downside of this approach is that it takes much longer to install compared to pip, even with Mamba's improved dependency resolution. |
| 99 | + |
| 100 | +.. todo:: |
| 101 | + |
| 102 | + * Determine how this can be integrated into current pip install without breaking ``colab`` pip deployment. |
| 103 | + * Investigate use of poetry as it is easier to package a distribution. But detectron2 is not PEP517 compliant. |
| 104 | + * It is possible to combine Conda and Poetry, where Conda is used for packages like GDAL / detectron2 / openCV. |
| 105 | + |
| 106 | + |
3 | 107 |
|
4 | 108 | To use detectree2, first install it using: |
5 | 109 |
|
|
0 commit comments