Skip to content

Commit

Permalink
Merge branch 'main' into efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed May 10, 2024
2 parents ec028ee + aa97a84 commit 3189d36
Show file tree
Hide file tree
Showing 41 changed files with 1,612 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ github.repository }}:$(date +%s)
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@v2
Expand Down
11 changes: 3 additions & 8 deletions .github/workflows/docs-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"
- name: Install GDAL
run: |
python -m pip install --upgrade pip
Expand All @@ -26,11 +26,6 @@ jobs:
pip install --no-cache-dir Cython
pip install -r requirements.txt -r requirements_dev.txt -r requirements_docs.txt
pip install .
- name: Discover typos with codespell
run: codespell --skip="*.csv,*.geojson,*.json,*.js,*.html,*cff,*.pdf" --ignore-words-list="aci,acount,acounts,fallow,hart,hist,nd,ned,ois,wqs,pres"
# - name: PKG-TEST
# run: |
# python -m unittest discover tests/
- run: mkdocs build
- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v2.0
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/draft-pdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
name: Paper Draft
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ jobs:
fail-fast: false
matrix:
config:
- { os: macOS-latest, py: "3.10" }
- { os: macOS-latest, py: "3.11" }
env:
SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
steps:
- name: CHECKOUT CODE
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: SETUP PYTHON
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.config.py }}
# - name: Install GDAL
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ jobs:
SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
steps:
- name: CHECKOUT CODE
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: SETUP PYTHON
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.config.py }}
- name: Install GDAL
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install miniconda
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
auto-activate-base: true
python-version: "3.10"
Expand Down
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
types: [python]
- id: trailing-whitespace
- id: requirements-txt-fixer
- id: check-added-large-files
args: ["--maxkb=500"]

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black-jupyter
language_version: python3.11

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args: [--toml, pyproject-codespell.precommit-toml]

- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
hooks:
- id: nbstripout
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LABEL repo="https://github.com/opengeos/segment-geospatial"

RUN mamba install -c conda-forge leafmap localtileserver segment-geospatial -y && \
pip install -U segment-geospatial jupyter-server-proxy && \
jupyter serverextension enable --sys-prefix jupyter_server_proxy && \
jupyter server extension enable --sys-prefix jupyter_server_proxy && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"

Expand All @@ -18,6 +18,5 @@ ARG LOCALTILESERVER_CLIENT_PREFIX='proxy/{port}'
ENV LOCALTILESERVER_CLIENT_PREFIX=$LOCALTILESERVER_CLIENT_PREFIX

USER root
RUN apt update; apt install -y libgl1
RUN chown -R ${NB_UID} ${HOME}
USER ${NB_USER}
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ The **segment-geospatial** package draws its inspiration from [segment-anything-

## Citations

- Wu, Q., & Osco, L. (2023). samgeo: A Python package for segmenting geospatial data with the Segment Anything Model (SAM). _Journal of Open Source Software_, 8(89), 5663, <https://doi.org/10.21105/joss.05663>
- Wu, Q., & Osco, L. (2023). samgeo: A Python package for segmenting geospatial data with the Segment Anything Model (SAM). _Journal of Open Source Software_, 8(89), 5663. <https://doi.org/10.21105/joss.05663>
- Osco, L. P., Wu, Q., de Lemos, E. L., Gonçalves, W. N., Ramos, A. P. M., Li, J., & Junior, J. M. (2023). The Segment Anything Model (SAM) for remote sensing applications: From zero to one shot. _International Journal of Applied Earth Observation and Geoinformation_, 124, 103540. <https://doi.org/10.1016/j.jag.2023.103540>

## Features

Expand Down Expand Up @@ -56,16 +57,16 @@ conda install -c conda-forge mamba
mamba install -c conda-forge segment-geospatial
```

Samgeo-geospatial has some optional dependencies that are not included in the default conda environment. To install these dependencies, run the following command:
If your system has a GPU, but the above commands do not install the GPU version of pytorch, you can force the installation of the GPU version of pytorch using the following command:

```bash
mamba install -c conda-forge groundingdino-py segment-anything-fast
mamba install -c conda-forge segment-geospatial "pytorch=*=cuda*"
```

As of July 9th, 2023 Linux systems have also required that `libgl1` be installed for segment-geospatial to work. The following command will install that dependency
Samgeo-geospatial has some optional dependencies that are not included in the default conda environment. To install these dependencies, run the following command:

```bash
apt update; apt install -y libgl1
mamba install -c conda-forge groundingdino-py segment-anything-fast
```

## Examples
Expand Down
6 changes: 2 additions & 4 deletions docs/examples/arcgis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"sam.show_anns(axis=\"off\", alpha=1, output=\"ag_annotations.tif\")"
Expand Down Expand Up @@ -431,7 +429,7 @@
"metadata": {},
"outputs": [],
"source": [
"sam.generate('agriculture.tif', output=\"ag_masks2.tif\", foreground=True)"
"sam.generate(\"agriculture.tif\", output=\"ag_masks2.tif\", foreground=True)"
]
},
{
Expand Down
12 changes: 9 additions & 3 deletions docs/examples/automatic_mask_generator_hq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@
"source": [
"import os\n",
"import leafmap\n",
"from samgeo.hq_sam import SamGeo, show_image, download_file, overlay_images, tms_to_geotiff"
"from samgeo.hq_sam import (\n",
" SamGeo,\n",
" show_image,\n",
" download_file,\n",
" overlay_images,\n",
" tms_to_geotiff,\n",
")"
]
},
{
Expand Down Expand Up @@ -147,7 +153,7 @@
"outputs": [],
"source": [
"sam = SamGeo(\n",
" model_type=\"vit_h\", # can be vit_h, vit_b, vit_l, vit_tiny\n",
" model_type=\"vit_h\", # can be vit_h, vit_b, vit_l, vit_tiny\n",
" sam_kwargs=None,\n",
")"
]
Expand Down Expand Up @@ -288,7 +294,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down
7 changes: 3 additions & 4 deletions docs/examples/box_prompts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
"metadata": {},
"outputs": [],
"source": [
"m.add_raster('mask.tif', cmap='viridis', nodata=0, layer_name='Mask')\n",
"m.add_raster(\"mask.tif\", cmap=\"viridis\", nodata=0, layer_name=\"Mask\")\n",
"m"
]
},
Expand All @@ -260,7 +260,7 @@
"metadata": {},
"outputs": [],
"source": [
"url = 'https://opengeos.github.io/data/sam/tree_boxes.geojson'\n",
"url = \"https://opengeos.github.io/data/sam/tree_boxes.geojson\"\n",
"geojson = \"tree_boxes.geojson\"\n",
"leafmap.download_file(url, geojson)"
]
Expand Down Expand Up @@ -350,8 +350,7 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
},
"orig_nbformat": 4
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/fast_sam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"outputs": [],
"source": [
"from samgeo.fast_sam import SamGeo\n",
"\n",
"sam = SamGeo(model=\"FastSAM-x.pt\")"
]
},
Expand Down Expand Up @@ -259,8 +260,7 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
},
"orig_nbformat": 4
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
7 changes: 3 additions & 4 deletions docs/examples/input_prompts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -147,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -260,8 +260,7 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
},
"orig_nbformat": 4
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
3 changes: 1 addition & 2 deletions docs/examples/input_prompts_hq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
},
"orig_nbformat": 4
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
Loading

0 comments on commit 3189d36

Please sign in to comment.