File size: 1,597 Bytes
34ecf0d
 
 
 
be470bb
34ecf0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae4852a
34ecf0d
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: SW Fish Identifier
emoji: ๐ŸŸ
colorFrom: blue
colorTo: green
sdk: docker
app_port: 7860
pinned: false
---

# SW Fish Identifier

Upload a photo and SWClassifier will detect every fish in it, segment their outline,
and identify the species โ€” returning both the common name and scientific name.

## Pipeline

| Step | Model | Notes |
|---|---|---|
| Detection | YOLO v8 nano | Bounding boxes |
| Segmentation | FPN ResNet-18 | Per-fish polygon mask |
| Classification | BEiT v2 Base + FAISS kNN | 775 species |

## API

The Space exposes a REST API alongside the web UI.

### Identify fish in an image

```
POST /api/v1/predict
X-API-Key: <your-key>
Content-Type: multipart/form-data

file=<image>
```

**Response**

```json
{
  "detections": [
    {
      "bbox": { "x1": 120, "y1": 45, "x2": 380, "y2": 290, "confidence": 0.91 },
      "polygon": [[120, 180], [135, 170], "..."],
      "predictions": [
        { "name": "Wahoo", "taxon": "Acanthocybium solandri", "accuracy": 0.87, "species_id": "..." }
      ]
    }
  ],
  "image_size": { "width": 1280, "height": 720 },
  "timing": { "detect_ms": 210, "segment_ms": 85, "classify_ms": 430, "total_ms": 730 }
}
```

Full interactive docs available at `/api/docs`.

## Configuration (Space Secrets)

| Secret | Description |
|---|---|
| `SW_API_KEYS` | Comma-separated list of valid API keys |
| `SW_ADMIN_KEY` | Key required to create / revoke API keys via `/api/v1/keys` |

Set these under **Settings โ†’ Variables and Secrets** in the Space dashboard.
If not set, keys are auto-generated at startup (lost on container restart).