Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5658241
Implement a logging function and use it during inference in order to …
scottmartinnet Jun 16, 2025
6a00910
Implement a command line utility to run inference on a single image.
scottmartinnet Jun 16, 2025
b1dc370
Implement an API server to run inference on a single image.
scottmartinnet Jun 16, 2025
2051bcc
Implement environment.yml to let Conda automatically install all need…
scottmartinnet Jun 16, 2025
b8f0299
Add a simple API key system and a working Dockerfile.
scottmartinnet Jun 17, 2025
66196da
Automatically download and decompress model files.
scottmartinnet Jun 18, 2025
54a2bdf
Documentation, formatting, improved caching, download models from Git…
scottmartinnet Jun 20, 2025
05839c0
Accuracy improvements: switch to a bitmap-based polygon merging algor…
scottmartinnet Jul 2, 2025
7672520
Improve ignoring heuristic, use a set kernel_size.
scottmartinnet Jul 2, 2025
c73bdaf
Improve heuristic to look at the entire polygon, add logging.
scottmartinnet Jul 2, 2025
e3b5bfe
More efficient intersection detection.
scottmartinnet Jul 2, 2025
5d5c84c
Use an improved heuristic: look at other tiles for confirmation of ho…
scottmartinnet Jul 7, 2025
d082005
Control debug output and development caching, reject overlapping poly…
scottmartinnet Jul 7, 2025
f74fb14
Stop generating zero-length line segments.
scottmartinnet Jul 7, 2025
65d45a3
Merge pull request #2 from safelease/feature/improved-merging
scottmartinnet Jul 7, 2025
de4ec43
Improve visualization output, improve logging, add 2 pixel merge tole…
scottmartinnet Jul 10, 2025
b4f13b8
Use a specialized building footprint simplifier instead of the generi…
scottmartinnet Jul 10, 2025
abd598a
Simplify and improve code.
scottmartinnet Jul 10, 2025
de7e6b5
Make key parameters configurable through the API request.
scottmartinnet Jul 11, 2025
350b595
Merge pull request #3 from safelease/feature/fine-tuning
scottmartinnet Jul 11, 2025
b6822fd
Handle whatever comes out of findContours.
scottmartinnet Jul 14, 2025
72a2f97
Merge pull request #4 from safelease/feature/fine-tuning
scottmartinnet Jul 14, 2025
9c3ee2e
Further improvements to normalization of findContours results.
scottmartinnet Jul 14, 2025
6049010
Further improvements to normalization of findContours results.
scottmartinnet Jul 14, 2025
d43bc56
Merge pull request #5 from safelease/feature/fine-tuning
scottmartinnet Jul 14, 2025
5d0e308
Load checkpoint weights dynamically to get all pretrained models work…
scottmartinnet Jul 15, 2025
e19b364
Make it possible to control the model through the API request.
scottmartinnet Jul 15, 2025
a0b7e07
Merge pull request #6 from safelease/feature/fine-tuning
scottmartinnet Jul 15, 2025
03ee2e7
Fix bad colors in visualization, remove redundant EXPERIMENT_PATH con…
scottmartinnet Jul 16, 2025
433c49c
Improve visualization.
scottmartinnet Jul 16, 2025
1f2f71b
Remove logging.
scottmartinnet Jul 16, 2025
b193476
Restructure code.
scottmartinnet Jul 16, 2025
5ab737d
Remove unused variables.
scottmartinnet Jul 16, 2025
0cd1b24
Make output filenames consistent.
scottmartinnet Jul 16, 2025
ed5c3aa
Restructuring.
scottmartinnet Jul 16, 2025
1c789a4
Improve logging.
scottmartinnet Jul 16, 2025
1850c85
Improve logging.
scottmartinnet Jul 16, 2025
753c1f5
Improve logging.
scottmartinnet Jul 16, 2025
e22b6ac
Performance improvement.
scottmartinnet Jul 16, 2025
c0ddf25
Documentation.
scottmartinnet Jul 16, 2025
cc9de47
Documentation.
scottmartinnet Jul 16, 2025
4449c02
Regression.
scottmartinnet Jul 16, 2025
8ebcd2c
Restructuring.
scottmartinnet Jul 16, 2025
4ba35a1
Restructuring.
scottmartinnet Jul 16, 2025
9574de9
Add types.
scottmartinnet Jul 16, 2025
27153d0
Log the model being used.
scottmartinnet Jul 16, 2025
3674adb
Merge pull request #7 from safelease/feature/fine-tuning-2
scottmartinnet Jul 16, 2025
546044a
Handle multipolygons coming out of regularization.
scottmartinnet Jul 16, 2025
23d7b94
Merge pull request #8 from safelease/feature/multipolygon
scottmartinnet Jul 16, 2025
dd89688
Listen on all interfaces.
scottmartinnet Jul 18, 2025
ddc9673
Merge pull request #9 from safelease/feature/interface
scottmartinnet Jul 18, 2025
bd1596b
Update build command for cross-platform compatibility.
scottmartinnet Nov 10, 2025
7c393e7
Specify a compatible version of huggingface-hub
scottmartinnet Nov 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM pytorch/pytorch:2.1.2-cuda11.8-cudnn8-runtime

ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
software-properties-common \
git \
wget \
&& rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /opt/program

# Copy environment file
COPY environment.yml .

# Create conda environment
RUN conda env create -f environment.yml && \
conda clean -afy

# Copy the model code
COPY . .

# Set environment variables
ENV PYTHONPATH=/opt/program
ENV OPENBLAS_NUM_THREADS=1

# Use the startup script as entrypoint
ENTRYPOINT ["./start_api.sh"]
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,78 @@ This repository benefits from the following open-source work. We thank the autho
3. [Frame Field Learning](https://github.com/Lydorn/Polygonization-by-Frame-Field-Learning)
4. [PolyWorld](https://github.com/zorzi-s/PolyWorldPretrainedNetwork)
5. [HiSup](https://github.com/SarahwXU/HiSup)

## Docker Usage

Pix2Poly provides a Docker setup for easy deployment and inference. The Docker container includes a FastAPI server for REST API inference and supports command-line inference. The API request and response format are suitable for running as a AWS Sagemaker inference endpoint running on a ml.g4dn.xlarge and the inference AMI version al2-ami-sagemaker-inference-gpu-3-1, where it is able to infer at a rate of 5-10 seconds per tile.

### Building the Docker Image

```bash
docker buildx build --platform linux/amd64 -t pix2poly .
```

### Running the API Server

The Docker container automatically starts a FastAPI server on port 8080. You can run it with:

```bash
docker run -p 8080:8080 pix2poly
```

The API server will automatically download the pretrained model files on first startup and provide the following endpoints:

- `POST /invocations` - Main inference endpoint for processing images
- `GET /ping` - Health check endpoint

#### API Usage

The `/invocations` endpoint accepts images in multiple formats:

1. **File Upload (multipart/form-data):**
```bash
curl -X POST "http://localhost:8080/invocations" \
-H "Content-Type: multipart/form-data" \
-F "file=@your_image.jpg"
```

2. **Base64 Encoded Image:**
```bash
curl -X POST "http://localhost:8080/invocations" \
-H "Content-Type: application/json" \
-d '{"image": "base64_encoded_image_data"}'
```

3. **Raw Image Data:**
```bash
curl -X POST "http://localhost:8080/invocations" \
-H "Content-Type: image/jpeg" \
--data-binary @your_image.jpg
```

The API returns JSON with the detected polygons:

```text
{
"polygons": [
[[x1, y1], [x2, y2], ...],
...
]
}
```

### Environment Variables

You can customize the Docker container behavior with these environment variables:

- `MODEL_URL`: URL to download the pretrained model files (default: `https://github.com/safelease/Pix2Poly/releases/download/main/runs_share.zip`)
- `API_KEY`: Optional API key for authentication (if not set, authentication is disabled)

Example with custom configuration:
```bash
docker run -p 8080:8080 \
-e MODEL_URL=https://github.com/safelease/Pix2Poly/releases/download/main/runs_share.zip \
-e API_KEY=your_secret_key \
pix2poly
```

Loading