Skip to content

Commit e54c3f0

Browse files
guillemc23Moreno Castaño, Guillermopre-commit-ci[bot]giswqs
authored
feat: Optional imports (#420)
* feat: First approach to optimizing imports * fix: Fixed OpenCV headless package name * fix: Added core imports to `requirements.txt` * fix: Added `samgeo2` missing import * fix: Validates SAMGeo 2 * chore: Refactor package requirements * fix: Optimized imports, code cleanup and notebooks to reflect changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore: Add docs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: Update tests with new syntax * fix: Update `requirements.txt` * fix: Add torchvision to `requirements.txt` * fix: Revert package version to 0.12.6 * Update segment-anything-fast dependency in pyproject.tom * Fix typo in fast dependencies list --------- Co-authored-by: Moreno Castaño, Guillermo <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Qiusheng Wu <[email protected]>
1 parent 812b558 commit e54c3f0

27 files changed

+309
-150
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,28 @@ The **segment-geospatial** package draws its inspiration from [segment-anything-
4242

4343
### Install from PyPI
4444

45-
**segment-geospatial** is available on [PyPI](https://pypi.org/project/segment-geospatial/). To install **segment-geospatial**, run this command in your terminal:
45+
**segment-geospatial** is available on [PyPI](https://pypi.org/project/segment-geospatial/) and can be installed in several ways so that its dependencies can be controlled more granularly. This reduces package size for CI environments, since not every time all of the models will be used.
46+
47+
Depending on what tools you need to use, you might want to do:
48+
* `segment-geospatial` or `segment-geospatial[samgeo]`: Installs only the minimum required dependencies to run SAMGeo
49+
* `segment-geospatial[samgeo2]`: Installs the dependencies to run SAMGeo 2
50+
* `segment-geospatial[fast]`: Installs the dependencies to run Fast SAM
51+
* `segment-geospatial[hq]`: Installs the dependencies to run HQ-SAM
52+
* `segment-geospatial[text]`: Installs Grounding DINO to use SAMGeo 1 and 2 with text prompts
53+
* `segment-geospatial[fer]`: Installs the dependencies to run the feature
54+
edge reconstruction algorithm
55+
56+
Additionally, these other two optional imports are defined:
57+
* `segment-geospatial[all]`: Installs the dependencies to run all of the SAMGeo models
58+
* `segment-geospatial[extra]`: Installs the dependencies to run all of the SAMGeo models and other utilities to run the examples like Jupyter notebook support, `leafmap`, etc.
59+
60+
Simply running the following should install the dependencies for each use case:
4661

4762
```bash
48-
pip install segment-geospatial
63+
pip install segment-geospatial[samgeo2] # Or any other choice of the above
4964
```
65+
To see more in detail what packages come with each choice, please refer to `pyproject.toml`.
66+
5067

5168
### Install from conda-forge
5269

docs/examples/automatic_mask_generator.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
"metadata": {},
4141
"outputs": [],
4242
"source": [
43-
"import os\n",
4443
"import leafmap\n",
45-
"from samgeo import SamGeo, show_image, download_file, overlay_images, tms_to_geotiff"
44+
"from samgeo import SamGeo\n",
45+
"from samgeo.common import overlay_images, tms_to_geotiff"
4646
]
4747
},
4848
{

docs/examples/automatic_mask_generator_hq.ipynb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,9 @@
3636
"metadata": {},
3737
"outputs": [],
3838
"source": [
39-
"import os\n",
4039
"import leafmap\n",
41-
"from samgeo.hq_sam import (\n",
42-
" SamGeo,\n",
43-
" show_image,\n",
44-
" download_file,\n",
45-
" overlay_images,\n",
46-
" tms_to_geotiff,\n",
47-
")"
40+
"from samgeo.hq_sam import SamGeo\n",
41+
"from samgeo.common import overlay_images, tms_to_geotiff"
4842
]
4943
},
5044
{

docs/examples/box_prompts.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"outputs": [],
4040
"source": [
4141
"import leafmap\n",
42-
"from samgeo import tms_to_geotiff\n",
42+
"from samgeo.common import tms_to_geotiff\n",
4343
"from samgeo import SamGeo"
4444
]
4545
},

docs/examples/fast_sam.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
"outputs": [],
4040
"source": [
4141
"import leafmap\n",
42-
"from samgeo import tms_to_geotiff\n",
43-
"from samgeo.fast_sam import SamGeo"
42+
"from samgeo.common import tms_to_geotiff"
4443
]
4544
},
4645
{

docs/examples/input_prompts.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
"metadata": {},
4141
"outputs": [],
4242
"source": [
43-
"import os\n",
4443
"import leafmap\n",
45-
"from samgeo import SamGeo, tms_to_geotiff"
44+
"from samgeo import SamGeo\n",
45+
"from samgeo.common import tms_to_geotiff"
4646
]
4747
},
4848
{

docs/examples/input_prompts_hq.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
"metadata": {},
3939
"outputs": [],
4040
"source": [
41-
"import os\n",
4241
"import leafmap\n",
43-
"from samgeo.hq_sam import SamGeo, tms_to_geotiff"
42+
"from samgeo.hq_sam import SamGeo\n",
43+
"from samgeo.common import tms_to_geotiff"
4444
]
4545
},
4646
{

docs/examples/maxar_open_data.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
},
4242
"outputs": [],
4343
"source": [
44-
"import os\n",
4544
"import leafmap\n",
46-
"from samgeo import SamGeo, raster_to_vector, overlay_images"
45+
"from samgeo import SamGeo\n",
46+
"from samgeo.common import raster_to_vector, overlay_images"
4747
]
4848
},
4949
{

docs/examples/sam2_box_prompts.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"outputs": [],
4040
"source": [
4141
"import leafmap\n",
42-
"from samgeo import SamGeo2, raster_to_vector, regularize"
42+
"from samgeo import SamGeo2\n",
43+
"from samgeo.common import raster_to_vector, regularize"
4344
]
4445
},
4546
{

docs/examples/sam2_point_prompts.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"outputs": [],
4747
"source": [
4848
"import leafmap\n",
49-
"from samgeo import SamGeo2, regularize"
49+
"from samgeo import SamGeo2\n",
50+
"from samgeo.common import regularize"
5051
]
5152
},
5253
{

0 commit comments

Comments
 (0)