|
1 | | -# Installation |
2 | | - |
3 | | -VisDet is published as a normal Python package. In most cases you **do not** need to clone this repository to use it. |
4 | | - |
5 | | -Cloning the repo is only needed if you want to: |
6 | | - |
7 | | -- Develop VisDet itself (editable install, tests, docs) |
8 | | -- Use the repo’s training scripts under `tools/` |
9 | | -- Use the repo’s example assets/configs as-is |
| 1 | +# Prerequisites |
10 | 2 |
|
11 | | -## Requirements |
| 3 | +In this section we demonstrate how to prepare an environment with PyTorch. |
12 | 4 |
|
13 | | -- Python `>=3.10,<3.13` |
14 | | -- PyTorch + torchvision |
15 | | - - For CUDA / GPU support, install PyTorch following https://pytorch.org first (so you get the correct CUDA build). |
| 5 | +This framework works on Linux, Windows and macOS. It requires Python 3.7+, CUDA 9.2+ and PyTorch 1.5+. |
16 | 6 |
|
17 | | -## Install with uv (recommended) |
| 7 | +```{note} |
| 8 | +If you are experienced with PyTorch and have already installed it, just skip this part and jump to the [next section](#installation). Otherwise, you can follow these steps for the preparation. |
| 9 | +``` |
18 | 10 |
|
19 | | -**Step 0.** Install [uv](https://docs.astral.sh/uv/) (if you don’t already have it). |
| 11 | +**Step 0.** Install [uv](https://docs.astral.sh/uv/) - a fast Python package manager. |
20 | 12 |
|
21 | 13 | ```shell |
22 | | -# macOS / Linux |
| 14 | +# On macOS and Linux |
23 | 15 | curl -LsSf https://astral.sh/uv/install.sh | sh |
24 | 16 |
|
25 | | -# Windows |
| 17 | +# On Windows |
26 | 18 | powershell -c "irm https://astral.sh/uv/install.ps1 | iex" |
27 | 19 | ``` |
28 | 20 |
|
29 | | -**Step 1.** Create a virtual environment. |
| 21 | +**Step 1.** uv will automatically manage Python versions and virtual environments for you. No separate setup needed! |
30 | 22 |
|
31 | | -```shell |
32 | | -uv venv --python 3.12 |
33 | | -``` |
| 23 | +# Installation |
34 | 24 |
|
35 | | -**Step 2.** Activate it. |
| 25 | +We recommend that users follow our best practices to install VisDet using uv. However, the whole process is highly customizable. See [Customize Installation](#customize-installation) section for more information. |
36 | 26 |
|
37 | | -```shell |
38 | | -# macOS / Linux |
39 | | -source .venv/bin/activate |
| 27 | +## Best Practices |
40 | 28 |
|
41 | | -# Windows (PowerShell) |
42 | | -.venv\Scripts\Activate.ps1 |
| 29 | +**Step 0.** Clone the repository and navigate to it. |
| 30 | + |
| 31 | +```shell |
| 32 | +git clone <your-repository-url> |
| 33 | +cd visdet |
43 | 34 | ``` |
44 | 35 |
|
45 | | -**Step 3.** Install VisDet. |
| 36 | +**Step 1.** Install dependencies using uv. |
| 37 | + |
| 38 | +For development (includes all dependencies): |
46 | 39 |
|
47 | 40 | ```shell |
48 | | -uv pip install visdet |
| 41 | +uv sync |
49 | 42 | ``` |
50 | 43 |
|
51 | | -### Optional extras |
| 44 | +For specific extras (e.g., just documentation): |
52 | 45 |
|
53 | 46 | ```shell |
54 | | -# Extra (optional) dependencies used by some features |
55 | | -uv pip install "visdet[optional]" |
56 | | - |
57 | | -# Everything in the optional group |
58 | | -uv pip install "visdet[all]" |
| 47 | +uv sync --extra mkdocs |
59 | 48 | ``` |
60 | 49 |
|
61 | | -## Install with pip |
| 50 | +**Step 2.** That's it! uv has: |
| 51 | +- Created a virtual environment |
| 52 | +- Installed Python 3.12 (or the version specified in `.python-version`) |
| 53 | +- Installed all dependencies from `pyproject.toml` |
| 54 | +- Installed the package in editable mode |
| 55 | + |
| 56 | +## Verify the installation |
| 57 | + |
| 58 | +To verify whether This framework installed correctly, we provide some sample codes to run an inference demo. |
62 | 59 |
|
63 | | -If you prefer standard tooling: |
| 60 | +**Step 1.** We need to download config and checkpoint files. |
64 | 61 |
|
65 | 62 | ```shell |
66 | | -python -m venv .venv |
67 | | -source .venv/bin/activate # or .venv\Scripts\activate on Windows |
68 | | -pip install -U pip |
69 | | -pip install visdet |
| 63 | +uv run mim download mmdet --config yolov3_mobilenetv2_320_300e_coco --dest . |
70 | 64 | ``` |
71 | 65 |
|
72 | | -## Verify the installation |
| 66 | +The downloading will take several seconds or more, depending on your network environment. When it is done, you will find two files `yolov3_mobilenetv2_320_300e_coco.py` and `yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth` in your current folder. |
73 | 67 |
|
74 | | -A minimal smoke-check (no repo clone required): |
| 68 | +**Step 2.** Verify the inference demo. |
75 | 69 |
|
76 | 70 | ```shell |
77 | | -python -c "import visdet; print(visdet.__version__)" |
| 71 | +uv run python demo/image_demo.py demo/demo.jpg yolov3_mobilenetv2_320_300e_coco.py yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth --device cpu --out-file result.jpg |
78 | 72 | ``` |
79 | 73 |
|
80 | | -Optional: run a quick inference using a built-in YAML preset (this may download model weights on first use): |
| 74 | +You will see a new image `result.jpg` on your current folder, where bounding boxes are plotted on cars, benches, etc. |
| 75 | + |
| 76 | +Alternatively, you can run Python code directly: |
81 | 77 |
|
82 | 78 | ```python |
83 | | -from visdet.apis import DetInferencer |
| 79 | +# Run with: uv run python |
| 80 | +from mmdet.apis import init_detector, inference_detector |
| 81 | + |
| 82 | +config_file = 'yolov3_mobilenetv2_320_300e_coco.py' |
| 83 | +checkpoint_file = 'yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth' |
| 84 | +model = init_detector(config_file, checkpoint_file, device='cpu') # or device='cuda:0' |
| 85 | +inference_detector(model, 'demo/demo.jpg') |
| 86 | +``` |
84 | 87 |
|
85 | | -inferencer = DetInferencer(model="rtmdet-s", device="cpu") |
86 | | -results = inferencer("path/to/your_image.jpg") |
87 | | -print(results) |
| 88 | +You will see a list of arrays printed, indicating the detected bounding boxes. |
| 89 | + |
| 90 | +## Customize Installation |
| 91 | + |
| 92 | +### CUDA versions |
| 93 | + |
| 94 | +When installing PyTorch, you need to specify the version of CUDA. If you are not clear on which to choose, follow our recommendations: |
| 95 | + |
| 96 | +- For Ampere-based NVIDIA GPUs, such as GeForce 30 series and NVIDIA A100, CUDA 11 is a must. |
| 97 | +- For older NVIDIA GPUs, CUDA 11 is backward compatible, but CUDA 10.2 offers better compatibility and is more lightweight. |
| 98 | + |
| 99 | +Please make sure the GPU driver satisfies the minimum version requirements. See [this table](https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-major-component-versions__table-cuda-toolkit-driver-versions) for more information. |
| 100 | + |
| 101 | +```{note} |
| 102 | +uv handles PyTorch installation automatically based on your `pyproject.toml` configuration. For specific CUDA versions, you may need to configure the PyTorch index URL in your project settings. |
88 | 103 | ``` |
89 | 104 |
|
90 | | -## Install from source (development) |
| 105 | +### Installing additional packages |
91 | 106 |
|
92 | | -Only needed if you’re contributing to VisDet. |
| 107 | +To add additional packages to your project: |
93 | 108 |
|
94 | 109 | ```shell |
95 | | -git clone <your-repository-url> |
96 | | -cd visdet |
97 | | -uv sync |
| 110 | +# Add a new dependency |
| 111 | +uv add package-name |
| 112 | + |
| 113 | +# Add a development dependency |
| 114 | +uv add --dev package-name |
| 115 | + |
| 116 | +# Add an optional dependency to a specific group |
| 117 | +uv add --optional group-name package-name |
98 | 118 | ``` |
99 | 119 |
|
100 | | -That will: |
| 120 | +### Install on CPU-only platforms |
| 121 | + |
| 122 | +This framework can be built for CPU only environment. In CPU mode you can train, test or inference a model. |
| 123 | + |
| 124 | +However some functionalities are gone in this mode: |
| 125 | + |
| 126 | +- Deformable Convolution |
| 127 | +- Modulated Deformable Convolution |
| 128 | +- ROI pooling |
| 129 | +- Deformable ROI pooling |
| 130 | +- CARAFE |
| 131 | +- SyncBatchNorm |
| 132 | +- CrissCrossAttention |
| 133 | +- MaskedConv2d |
| 134 | +- Temporal Interlace Shift |
| 135 | +- nms_cuda |
| 136 | +- sigmoid_focal_loss_cuda |
| 137 | +- bbox_overlaps |
101 | 138 |
|
102 | | -- Create a virtual environment |
103 | | -- Install dependencies from `pyproject.toml` |
104 | | -- Install VisDet in editable mode |
| 139 | +If you try to train/test/inference a model containing above ops, an error will be raised. |
| 140 | +The following table lists affected algorithms. |
105 | 141 |
|
106 | | -## Install on Google Colab |
| 142 | +| Operator | Model | |
| 143 | +| :-----------------------------------------------------: | :--------------------------------------------------------------------------------------: | |
| 144 | +| Deformable Convolution/Modulated Deformable Convolution | DCN、Guided Anchoring、RepPoints、CentripetalNet、VFNet、CascadeRPN、NAS-FCOS、DetectoRS | |
| 145 | +| MaskedConv2d | Guided Anchoring | |
| 146 | +| CARAFE | CARAFE | |
| 147 | +| SyncBatchNorm | ResNeSt | |
107 | 148 |
|
108 | | -Colab usually already has PyTorch installed. |
| 149 | +### Install on Google Colab |
| 150 | + |
| 151 | +[Google Colab](https://research.google.com/) usually has PyTorch installed. |
| 152 | +Here's how to install visdet with uv on Colab: |
| 153 | + |
| 154 | +**Step 1.** Install uv in Colab. |
109 | 155 |
|
110 | 156 | ```shell |
111 | 157 | !curl -LsSf https://astral.sh/uv/install.sh | sh |
112 | | -!uv venv --python 3.12 |
113 | | -!uv pip install visdet |
114 | 158 | ``` |
115 | 159 |
|
| 160 | +**Step 2.** Clone and install visdet. |
| 161 | + |
| 162 | +```shell |
| 163 | +!git clone <your-repository-url> |
| 164 | +%cd visdet |
| 165 | +!uv sync |
| 166 | +``` |
| 167 | + |
| 168 | +**Step 3.** Verification. |
| 169 | + |
116 | 170 | ```python |
117 | | -import visdet |
118 | | -print(visdet.__version__) |
| 171 | +!uv run python -c "import mmdet; print(mmdet.__version__)" |
119 | 172 | ``` |
120 | 173 |
|
121 | 174 | ```{note} |
122 | | -Within Jupyter, the exclamation mark `!` runs shell commands. |
| 175 | +Within Jupyter, the exclamation mark `!` is used to call external executables and `%cd` is a [magic command](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-cd) to change the current working directory of Python. |
123 | 176 | ``` |
124 | 177 |
|
125 | | -## Using VisDet with Docker |
| 178 | +### Using VisDet with Docker |
126 | 179 |
|
127 | | -The repo contains a `docker/` folder with a Dockerfile. This path **does** require cloning the repository. |
| 180 | +We provide a Dockerfile in the `docker/` directory to build an image. Ensure that your [docker version](https://docs.docker.com/engine/install/) >=19.03. |
128 | 181 |
|
129 | 182 | ```shell |
| 183 | +# build an image with PyTorch 1.6, CUDA 10.1 |
| 184 | +# If you prefer other versions, just modified the Dockerfile |
130 | 185 | docker build -t visdet docker/ |
131 | 186 | ``` |
132 | 187 |
|
133 | | -Run it with: |
| 188 | +Run it with |
134 | 189 |
|
135 | 190 | ```shell |
136 | 191 | docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/visdet/data visdet |
137 | 192 | ``` |
138 | 193 |
|
139 | | -## Troubleshooting |
| 194 | +### Running commands with uv |
| 195 | + |
| 196 | +All commands should be prefixed with `uv run` to ensure they use the project's virtual environment: |
| 197 | + |
| 198 | +```shell |
| 199 | +# Running Python scripts |
| 200 | +uv run python your_script.py |
| 201 | + |
| 202 | +# Running installed CLI tools |
| 203 | +uv run pytest tests/ |
| 204 | + |
| 205 | +# Running prek hooks |
| 206 | +uv run prek run --all-files |
| 207 | + |
| 208 | +# Building documentation |
| 209 | +uv run mkdocs build |
| 210 | +``` |
| 211 | + |
| 212 | +Alternatively, you can activate the virtual environment manually: |
| 213 | + |
| 214 | +```shell |
| 215 | +source .venv/bin/activate # On Linux/macOS |
| 216 | +# or |
| 217 | +.venv\Scripts\activate # On Windows |
| 218 | + |
| 219 | +# Now you can run commands without 'uv run' prefix |
| 220 | +python your_script.py |
| 221 | +pytest tests/ |
| 222 | +``` |
| 223 | + |
| 224 | +## Trouble shooting |
| 225 | + |
| 226 | +If you have some issues during the installation, please check the documentation carefully. |
| 227 | + |
| 228 | +Common issues and solutions: |
| 229 | + |
| 230 | +- **Import errors**: Make sure you have installed the package with `uv sync` |
| 231 | +- **CUDA issues**: Verify your CUDA version matches your PyTorch installation |
| 232 | +- **Version conflicts**: Try creating a fresh virtual environment |
140 | 233 |
|
141 | | -- **Import errors**: ensure you installed into the environment you’re running (`which python` / `python -V`). |
142 | | -- **CUDA issues**: install PyTorch for your CUDA version (then reinstall `visdet` if needed). |
143 | | -- **Version conflicts**: try a fresh env: `rm -rf .venv && uv venv && uv pip install visdet`. |
| 234 | +If you encounter problems not covered in the documentation, please refer to the [Contributing Guide](../development/contributing.md) for how to report issues. |
0 commit comments