Skip to content

About

This serves as an API implementation of the Project Sidewalk AI models for tagging and validating labels.

Resources

Stars

2 stars

Watchers

2 watching

Forks

Latest commit

 

History

129 Commits

Folders and files

Repository files navigation

sidewalk-ai-api

This serves as an API implementation of the Project Sidewalk AI models for tagging (crosswalk, curb ramp, obstacle, surface problem) and validating labels.

This README contains the basic steps for setting up the API, but for a detailed usage guide on using the API, please see API_USAGE.md

Requirements

After cloning, don't forget to download the submodules

git submodule init
git submodule update

Download checkpoints

./download_models.sh

This fetches the depth model. The tagger and validator models download from HuggingFace on first start, at the revisions pinned in sidewalk_ai_api/model_map.py (the Docker build bakes them into the image).

Build

docker  build  -t  sidewalk-ai-api  .

Run

Every request needs a password, set as SIDEWALK_AI_API_KEY on both this server and the Sidewalk website. Make it long and random (openssl rand -hex 32): nothing slows down guessing, so its length is the protection. Keep it in a file only you can read, which docker_start.sh loads on its own:

echo  'export SIDEWALK_AI_API_KEY=<your-key>'  >  ~/.sidewalk-ai-api.env
chmod  600  ~/.sidewalk-ai-api.env
./docker_start.sh

Or, to run the container by hand, export it first (rather than typing it into the docker run line, so it stays out of your shell history). Keep the 127.0.0.1: in front of the port: without it Docker opens the port to every machine that can reach this one, with no https. Keep the log options too: every request writes a log line, and without a cap the log grows until the disk is full.

export  SIDEWALK_AI_API_KEY=<your-key>
docker  run  --gpus  all  --runtime  nvidia  -d  -p  127.0.0.1:5000:5000  --log-opt  max-size=50m  --log-opt  max-file=5  -e  SIDEWALK_AI_API_KEY  sidewalk-ai-api

To test changes next to the production instance, build and start with dev. This runs a separate sidewalk-ai-api-dev container on 127.0.0.1:60655 (it needs its own ~9–10 GB of VRAM). To reach it from your own machine, tunnel in with ssh -L 60655:127.0.0.1:60655 <server> and send requests to http://localhost:60655/process. Remove it with docker rm -f sidewalk-ai-api-dev when you're done. To check that your changes didn't change the models' outputs, run python3 regression/compare.py on the server while both are running; it compares prod and dev on a fixed set of labels.

./docker_build.sh  dev
./docker_start.sh  dev

To redeploy prod, pull and run ./docker_build.sh && ./docker_start.sh (about a minute or two of downtime while the models load; see How production is deployed for the full procedure and the first-time setup). Each build is also tagged with its version, build time, and commit, e.g. sidewalk-ai-api:1.0.1-2026-10-14-1803-5a9487c. To roll back to an older build:

docker images sidewalk-ai-api                              # list builds, newest first
docker tag sidewalk-ai-api:<older-tag> sidewalk-ai-api
./docker_start.sh

Each build contains its own copy of every model, so rolling back also rolls back the models. Old builds take several GB each; delete ones you don't need with docker rmi sidewalk-ai-api:<tag>.

How production is deployed

Last checked against the server 2026-10-26. Nothing here is secret; the key never goes in this repo.

  • Where it runs. The lab's GPU server. Its Apache serves HTTPS for sidewalk-ai-api.cs.washington.edu and forwards every request to 127.0.0.1:60654, the port ./docker_start.sh publishes. There is no deploy webhook, CI job or cron: merging to main deploys nothing until someone runs the steps below on the server.
  • Docker is rootless and per account. There is no system Docker daemon; each account runs its own, so docker ps shows only your containers and production belongs to whichever account started it. Only that account (or root) can stop it. It survives a reboot via --restart unless-stopped plus loginctl enable-linger. The NVIDIA runtime is already set up for rootless use, so --gpus all works without root.
  • First-time setup (once per account).
    1. Ask CSE IT (support@cs.washington.edu) for subordinate uid/gid ranges in /etc/subuid and /etc/subgid. Rootless Docker won't start without them; they are the usual reason dockerd-rootless-setuptool.sh install fails.
    2. Keep Docker's storage off your NFS home, whose quota the multi-GB images would fill: make /m-make2/make2/<username>_docker and write ~/.config/docker/daemon.json:
      {
          "data-root": "/m-make2/make2/<username>_docker",
          "runtimes": {
              "nvidia": {
                  "path": "/usr/bin/nvidia-container-runtime",
                  "runtimeArgs": []
              }
          }
      }
    3. Run dockerd-rootless-setuptool.sh install. If it says to set DOCKER_HOST, put that in your shell rc, or every docker command says "Cannot connect to the Docker daemon". Then systemctl --user start docker.service; docker ps without an error means the daemon is up. docker info | grep 'Storage Driver' should say overlay2, not vfs, which stores a full copy of every layer.
    4. loginctl enable-linger, so the daemon and container survive logout and reboot. It needs CSE IT here (sudo loginctl enable-linger <username>).
    5. Clone this repo with git clone --recursive onto the local pool, e.g. /m-make2/make2/sidewalk-ai-api/; the build downloads the models itself. Keep a second clone (e.g. /m-make2/make2/sidewalk-ai-api-dev/) for testing branches, so the production clone stays on main.
    6. Put the API key in ~/.sidewalk-ai-api.env (chmod 600). It is the website stages' SIDEWALK_AI_API_KEY, so to change it, change both at the same time. Get it from the current deployer in person, never by chat or ticket.
  • Testing a branch first. In the dev clone, ./docker_build.sh dev && ./docker_start.sh dev runs a second instance beside production (another ~9-10 GB of VRAM; check nvidia-smi). python3 regression/compare.py then sends a fixed set of labels to both and reports every output that changed (its docstring explains the results). Remove it with docker rm -f sidewalk-ai-api-dev.
  • Deploying. In the production clone, on main: git fetch, then git log --oneline HEAD..origin/main to check the incoming commits are ones you expect (the build runs whatever you check out), then git pull. To deploy a tag instead: git fetch --tags, git log --oneline HEAD..<tag>, git checkout <tag>. Either way, then ./docker_build.sh, ./docker_start.sh. Expect a minute or two of 502s while the models load. Check docker logs -f sidewalk-ai-api. Every response, and every label_ai_assessment row on the website, carries api_version and the model revisions, so the database shows what is live.
  • Logs. docker logs sidewalk-ai-api has one line per answered request, rejected ones included: the caller's address, the time, the request, the status, the response size and the time taken. The address is the X-Forwarded-For header (- for a request that didn't come through Apache). Apache adds the real address at the end, so trust only the last address on the line: any before it were sent by the caller and can be made up. A request killed at the 120 s timeout gets no line, only gunicorn's WORKER TIMEOUT. A failed inference also leaves its traceback. docker_start.sh caps the log at 5 files of 50 MB.
  • Handing production to another account. Only one daemon can hold port 60654. The new owner does setup steps 1-6 and runs ./docker_build.sh; the current owner runs docker update --restart=no sidewalk-ai-api && docker stop -t 30 sidewalk-ai-api; the new owner then runs ./docker_start.sh right away. Downtime is the model load, not the build.

Try an example

curl -X POST -H "Authorization: Bearer $SIDEWALK_AI_API_KEY" -F "label_type=curbramp" -F "panorama_id=rZufe3aXwB2Syor0lKAqqw" -F "x=0.77746582031" -F "y=0.58459472656" http://127.0.0.1:5000/process

Please note that x and y are normalized coordinates (between 0 and 1) on the equirectangular image. The sample response below is from API 1.0.4 and the 2025-08 validators; the version, revisions and dates in a current response come from sidewalk_ai_api/model_map.py.

{"api_version":"1.0.4","image_source":"cache","label_type":"curbramp","tag_scores":{"debris / pooled water":1.6009700232189061e-07,"missing tactile warning":0.9999617338180542,"narrow":9.827788744587451e-06,"not enough landing space":1.6410160696977982e-06,"not level with street":5.565861016521012e-08,"points into traffic":1.844670691752981e-06,"steep":4.775402430823306e-06,"surface problem":4.025090305503909e-08},"tagger_model_id":"validated-dino-cls-b-curbramp-tags-best","tagger_revision":"cbd3a9632fc594a6f62de850757ae199761d0c4a","tagger_training_date":"12-03-2024","tags":["missing tactile warning"],"tags_not_present":["points into traffic","surface problem"],"validation_estimated_accuracy":0.9598393574297188,"validation_result":"correct","validation_score":0.999808132648468,"validator_model_id":"sidewalk-validator-ai-curbramp","validator_revision":"969ad5a33079db7885c9e9a4eb5cd0f39d8fe57a","validator_training_date":"08-16-2025"}

Please note that tag_scores and tags will not be returned if the label_type does not match the following: ["crosswalk", "curbramp", "obstacle", "surfaceproblem"]

Likewise, validation_result, validation_score, and validation_estimated_accuracy will not be returned if the label_type does not match the following: ["crosswalk", "curbramp", "obstacle", "surfaceproblem", "nocurbramp"]

This is because we do not have models for other label types yet.

For a more detailed guide on using the API, please see API_USAGE.md

About

This serves as an API implementation of the Project Sidewalk AI models for tagging and validating labels.

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages