{"id":33140338,"url":"https://github.com/trincadev/samgis-be","last_synced_at":"2025-11-16T00:01:10.962Z","repository":{"id":211986022,"uuid":"730410566","full_name":"trincadev/samgis-be","owner":"trincadev","description":"SamGIS can do machine learning-based (Segment Anything by Meta - Facebook) image segmentation tasks applied to GIS and geo data (there is also a SPA frontend similar to https://github.com/trincadev/samgis-fe used on HuggingFace)","archived":false,"fork":false,"pushed_at":"2025-11-05T21:44:18.000Z","size":3885,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-05T23:31:54.496Z","etag":null,"topics":["geospatial","gis","image-segmentation","machine-learning","machinelearning-python","segment-anything"],"latest_commit_sha":null,"homepage":"https://huggingface.co/spaces/aletrn/samgis","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trincadev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-12-11T21:37:39.000Z","updated_at":"2025-11-05T21:43:02.000Z","dependencies_parsed_at":"2023-12-12T00:53:25.439Z","dependency_job_id":"7bc1f23d-8630-4a68-8f7d-ecd7bac0cb61","html_url":"https://github.com/trincadev/samgis-be","commit_stats":null,"previous_names":["trincadev/samgis-be"],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/trincadev/samgis-be","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trincadev%2Fsamgis-be","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trincadev%2Fsamgis-be/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trincadev%2Fsamgis-be/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trincadev%2Fsamgis-be/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trincadev","download_url":"https://codeload.github.com/trincadev/samgis-be/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trincadev%2Fsamgis-be/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284640341,"owners_count":27039411,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-15T02:00:06.050Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geospatial","gis","image-segmentation","machine-learning","machinelearning-python","segment-anything"],"created_at":"2025-11-15T12:00:39.031Z","updated_at":"2025-11-16T00:01:10.954Z","avatar_url":"https://github.com/trincadev.png","language":"Python","funding_links":[],"categories":["Deep Learning","Software"],"sub_categories":["Geospatial"],"readme":"---\ntitle: SamGIS\nemoji: 🗺️\ncolorFrom: red\ncolorTo: blue\nsdk: docker\npinned: false\nlicense: mit\n---\n\n# About this README\n\nI tested these instructions on macOS, but should work on linux as well.\n\n## Segment Anything models\n\nIt's possible to prepare the model files using \u003chttps://github.com/vietanhdev/samexporter/\u003e or using the ones\nfrom \u003chttps://huggingface.co/aletrn/sam-quantized\u003e. By default the project contains that submodule.\nIf you want to use this (recommended) after the clone of this repository it's best to initialize the `sam-quantized` submodule:\n\n```bash\ngit submodule update --init --recursive\n```\n\n## SamGIS - Gradio SDK version\n\nAfter developed your project using [the gradio quickstart](https://www.gradio.app/guides/quickstart),\nyou can declare the specific gradio version you want to use in the HuggingFace space using\nthe README.md header section. You need to compile these fields:\n\n```\nsdk: gradio\nsdk_version: [current Gradio version, e.g. 4.44.0]\napp_file: app.py\n```\n\nFor some reason the space won't work if the app_file setting points to a file not\nwithin the root folder project.\n\nUnder the hood, HuggingFace install the gradio SDK using docker. If you need to install some dependencies\n(for this project I needed `nodejs`) you can add some system\n[debian packages](https://huggingface.co/docs/hub/spaces-dependencies#adding-your-own-dependencies)\nwithin the `pre-requirements.txt` file.\n\nIf you want to run locally the project not from a docker container you can install the optional gradio poetry group like this:\n\n```bash\npoetry install --with gradio --with --no-root\n```\n\n\n## SamGIS - Docker version\n\nThe SamGIS HuggingSpace url is \u003chttps://huggingface.co/spaces/aletrn/samgis\u003e.\nBuild the docker image this way:\n\n```bash\n# clean any old active containers\ndocker stop $(docker ps -a -q); docker rm $(docker ps -a -q)\n\n# build the base docker image from the repository root folder.\n# The SAMGIS_BASE_DOCKER_VERSION env variable read from the pyproject.toml is used to tag the docker image\n(\n  SAMGIS_BASE_DOCKER_VERSION=$(grep version pyproject.toml |head -1|cut -d'=' -f2|cut -d'\"' -f2);\n  set -o allexport \u0026\u0026 source \u003c(cat ./static/.env|grep VITE__) \u0026\u0026 set +o allexport;\n  env|grep VITE__;\n  docker build . -f dockerfiles/dockerfile-samgis-base --progress=plain \\\n  --build-arg VITE__MAP_DESCRIPTION=\"${VITE__MAP_DESCRIPTION}\" \\\n  --build-arg VITE__SAMGIS_SPACE=\"${VITE__SAMGIS_SPACE}\" \\\n  --build-arg VITE__STATIC_INDEX_URL=\"${VITE__STATIC_INDEX_URL}\" \\\n  --tag registry.gitlab.com/aletrn/gis-prediction:${SAMGIS_BASE_DOCKER_VERSION}\n)\n\n# build the image, use the tag \"samgis-huggingface\"\ndocker build . --tag registry.gitlab.com/aletrn/samgis-huggingface --progress=plain\n```\n\nRun the container (keep it on background) and show logs\n\n```bash\ndocker run  -d --name samgis-huggingface -p 7860:7860 \\\n  -e VITE__STATIC_INDEX_URL=${VITE__STATIC_INDEX_URL} \\\n  -e VITE__INDEX_URL=${VITE__INDEX_URL} \\\n  -e MOUNT_GRADIO_APP=\"\" \\\n  registry.gitlab.com/aletrn/samgis-huggingface; docker logs -f samgis-huggingface\n```\n\nTest it with curl using a json payload:\n\n```bash\nURL=http://localhost:7860/infer_samgis\ncurl -d@./events/payload_point_eolie.json -H 'content-type: application/json' ${URL}\n# or:\ncurl -d@./events/payload_point_colico.json -H 'content-type: application/json' ${URL}\n```\n\nor better visiting the swagger page on \u003chttp://localhost:7860/docs\u003e\n\n### Dependencies installation, local execution and local tests\n\nThe docker build process needs only the base dependency group plus the `aws_lambda` or `fastapi` optional one (right now I use almost only the `fastapi` version). Install also the `test` and/or `docs` groups if needed.\n\n#### Local execution\n\nIf you need to use the SPA frontend follow the frontend instruction [here](/static/README.md).\n\nYou can run the local server using this python command:\n\n```python\nuvicorn app:app --host 127.0.0.1 --port 7860\n```\n\nChange the port and/or the host ip if needed. Test it with curl using a json payload:\n\n```bash\nURL=http://localhost:7860/infer_samgis\ncurl -d@./events/payload_point_eolie.json -H 'content-type: application/json' ${URL}\n```\n\n#### Local execution on MacOS\n\nThere is a known issue running the project on macOS. SamGIS still work also without executing it within a docker container, but is slower during image embedding because of a memory leak caused by CoreML. Here a log about this bug:\n\n```less\n[...]\n2024-05-15T18:38:37.478698+0200 - INFO - predictors.py - samexporter_predict - (be2506dc-0887-4752-9889-cf12db7501f5) missing instance model mobile_sam, instantiating it now! \n2024-05-15T18:38:37.479582+0200 - INFO - sam_onnx2.py - __init__ - (be2506dc-0887-4752-9889-cf12db7501f5) Available providers for ONNXRuntime: %s \n2024-05-15 18:38:37.673229 [W:onnxruntime:, coreml_execution_provider.cc:81 GetCapability] CoreMLExecutionProvider::GetCapability, number of partitions supported by CoreML: 104 number of nodes in the graph: 566 number of nodes supported by CoreML: 383\nContext leak detected, CoreAnalytics returned false\nContext leak detected, CoreAnalytics returned false\nContext leak detected, CoreAnalytics returned false\nContext leak detected, CoreAnalytics returned false\nContext leak detected, CoreAnalytics returned false\nContext leak detected, CoreAnalytics returned false\n2024-05-15T18:38:47.691608+0200 - INFO - sam_onnx2.py - __init__ - (be2506dc-0887-4752-9889-cf12db7501f5) encoder_input_name: \n2024-05-15 18:38:47.913677 [W:onnxruntime:, coreml_execution_provider.cc:81 GetCapability] CoreMLExecutionProvider::GetCapability, number of partitions supported by CoreML: 48 number of nodes in the graph: 496 number of nodes supported by CoreML: 221\nContext leak detected, CoreAnalytics returned false\nContext leak detected, CoreAnalytics returned false\nContext leak detected, CoreAnalytics returned false\nContext leak detected, CoreAnalytics returned false\n2024-05-15T18:38:50.926801+0200 - DEBUG - predictors.py - samexporter_predict - (be2506dc-0887-4752-9889-cf12db7501f5) using a mobile_sam instance model... \n[...]\n```\n\nThis problem doesn't rise if running it within the docker container.\n\n### Tests\n\nTests are defined in the `tests` folder in this project. Use PIP to install the test dependencies and run tests.\n\n```bash\npython -m pytest --cov=samgis --cov-report=term-missing \u0026\u0026 coverage html\n```\n\n### How to update the static documentation with sphinx\n\nThis project documentation uses sphinx-apidoc: it's a tool for automatic generation of Sphinx sources that, using the autodoc\nextension, document a whole package in the style of other automatic API documentation tools. See the\n[documentation page](https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html) for details.\nRun the command from the project root:\n\n```bash\n# missing docs folder (run from project root) initialize this way\n# \ncd docs \u0026\u0026 sphinx-quickstart --project SamGIS --release 1.0.0 --language python --master index\n\n# update docs folder (from project root) referring to the other packages folder\nsphinx-apidoc -f -o docs /path/to/samgis_web\nsphinx-apidoc -f -o docs /path/to/samgis_core\n```\n\nThen it's possible to generate the HTML pages\n\n```bash\ncd docs \u0026\u0026 make html \u0026\u0026 ../\n\n# to clean old files\ncd docs \u0026\u0026 make clean html \u0026\u0026 cd ../\n```\n\nThe static documentation it's now ready at the path `docs/_build/html/index.html`.\n\nTo create a work in progress openapi json or yaml file use\n\n- `extract-openapi-fastapi.py`\n- `extract-openapi-lambda.py` (useful to export the json schema request and response from lambda app api)\n\n\n### Update `requirements.txt` using poetry\n\n```bash\npoetry export --without-hashes --format=requirements.txt |grep -w -E \"$(sed -z -e 's/\\n/=|/g' requirements_no_versions.txt)\" \u003e requirements.txt\n```\n\nAvoid newlines after the last pip package within the `requirements_no_versions.txt` file or the grep command will fail.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrincadev%2Fsamgis-be","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrincadev%2Fsamgis-be","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrincadev%2Fsamgis-be/lists"}