File size: 5,973 Bytes
65d140c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# cosmos-transfer

REST API microservice wrapper around [NVIDIA Cosmos-Transfer2.5-2B](https://huggingface.co/nvidia/Cosmos-Transfer2.5-2B) β€” a video diffusion model that converts synthetic renders into photorealistic video (Sim2Real).

---

## Installation

```bash
docker pull ghcr.io/eyalenav/cosmos-transfer:latest
```

### Run

```bash
docker run --rm \
  --gpus '"device=0"' \
  -p 8080:8080 \
  -v ~/.cache/huggingface:/root/.cache/huggingface \
  -e HUGGINGFACE_TOKEN=hf_... \
  ghcr.io/eyalenav/cosmos-transfer:latest
```

> **First run:** downloads Cosmos-Transfer2.5-2B weights (~20 GB). Subsequent starts are fast.

---

## API Reference

### `GET /health`

Check server status.

**Request**
```
GET http://localhost:8080/health
```

**Response**
```json
{
  "status": "ok",
  "model": "Cosmos-Transfer2.5-2B",
  "device": "cuda:0"
}
```

---

### `POST /transfer`

Convert a synthetic video to photorealistic using multicontrol (edge + visual).

**Request**
```
POST http://localhost:8080/transfer
Content-Type: multipart/form-data
```

| Field | Type | Default | Description |
|---|---|---|---|
| `video` | file | required | Input synthetic MP4 (max 10s @ 24fps recommended) |
| `prompt` | string | `""` | Text describing the scene (improves realism) |
| `edge_strength` | float | `0.85` | Canny edge control strength (geometry preservation) |
| `vis_strength` | float | `0.45` | Visual/blur control strength (scene structure) |
| `sigma` | int | `100` | Noise level β€” lower = more faithful, higher = more realistic |
| `num_steps` | int | `35` | Diffusion steps (more = slower but higher quality) |
| `seed` | int | `-1` | Random seed (`-1` = random) |

**Response**

Binary MP4 file (`video/mp4`).

**Example**
```bash
curl -X POST http://localhost:8080/transfer \
  -F "video=@synthetic_render.mp4" \
  -F "prompt=surveillance camera footage of a crowded urban street, overcast day" \
  -F "edge_strength=0.85" \
  -F "vis_strength=0.45" \
  -F "sigma=100" \
  --output photorealistic.mp4
```

---

### `POST /transfer_async`

Submit a job and poll for completion (recommended for long clips).

**Submit**
```bash
curl -X POST http://localhost:8080/transfer_async \
  -F "video=@render.mp4" \
  -F "prompt=security incident, parking lot" \
  -F "edge_strength=0.85" \
  --output job.json
# {"job_id": "abc123", "status": "queued"}
```

**Poll**
```bash
curl http://localhost:8080/status/abc123
# {"job_id": "abc123", "status": "running", "progress": 0.42}
# ...
# {"job_id": "abc123", "status": "done"}
```

**Download**
```bash
curl http://localhost:8080/result/abc123 --output photorealistic.mp4
```

---

## Tuned Parameters

Tested across 80+ surveillance clips β€” confirmed sweet spot:

```
edge_strength=0.85 + vis_strength=0.45 + sigma=100
```

| Parameter | Value | Effect |
|---|---|---|
| `edge_strength` | **0.85** | Strong silhouette/geometry preservation from Canny edges |
| `vis_strength` | **0.45** | Moderate scene structure via visual blur control |
| `sigma` | **100** | Balanced noise β€” realistic textures without losing layout |

### When to adjust

| Scenario | Adjustment |
|---|---|
| Subject drifts from synthetic pose | Increase `edge_strength` β†’ 0.90–0.95 |
| Background too synthetic-looking | Increase `vis_strength` β†’ 0.55–0.65 |
| Output too faithful to render colors | Increase `sigma` β†’ 120 |
| Too much motion blur | Decrease `sigma` β†’ 80 |

---

## Hardware Requirements

| Resource | Minimum | Recommended |
|---|---|---|
| GPU | A100 40GB / RTX 6000 Ada | H100 / RTX PRO 6000 Blackwell |
| VRAM | 40 GB | 48+ GB |
| RAM | 64 GB | 128 GB |
| Disk | 30 GB | 50 GB |
| CUDA | 12.1+ | 12.8 |

**Processing time (RTX PRO 6000 Blackwell, 96GB VRAM):**
- 4s clip @ 24fps β†’ ~3 min
- 10s clip @ 24fps β†’ ~7 min

---

## Environment Variables

| Variable | Required | Description |
|---|---|---|
| `HUGGINGFACE_TOKEN` | Yes | HF token with access to `nvidia/Cosmos-Transfer2.5-2B` |
| `CUDA_VISIBLE_DEVICES` | No | Limit to specific GPU (e.g. `"1"`) |
| `PORT` | No | Override default port `8080` |

---

## Integration with VisionAI-Flywheel

```yaml
# docker-compose.yml excerpt
services:
  cosmos-transfer:
    image: ghcr.io/eyalenav/cosmos-transfer:latest
    ports:
      - "8080:8080"
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              device_ids: ["1"]
              capabilities: [gpu]
    volumes:
      - hf_cache:/root/.cache/huggingface
    environment:
      - HUGGINGFACE_TOKEN=${HUGGINGFACE_TOKEN}
```

Full `docker-compose.yml`: [github.com/EyalEnav/VisionAI-Flywheel](https://github.com/EyalEnav/VisionAI-Flywheel)

---

## Example: Full Python client

```python
import requests
import time

def transfer_video(
    input_path: str,
    output_path: str,
    prompt: str = "",
    edge_strength: float = 0.85,
    vis_strength: float = 0.45,
    sigma: int = 100
):
    """Convert synthetic video to photorealistic."""
    with open(input_path, "rb") as f:
        response = requests.post(
            "http://localhost:8080/transfer",
            files={"video": ("input.mp4", f, "video/mp4")},
            data={
                "prompt": prompt,
                "edge_strength": edge_strength,
                "vis_strength": vis_strength,
                "sigma": sigma,
            },
            timeout=600
        )
    response.raise_for_status()
    
    with open(output_path, "wb") as f:
        f.write(response.content)
    print(f"Saved to {output_path}")

# Example usage
transfer_video(
    input_path="soma_render.mp4",
    output_path="photorealistic.mp4",
    prompt="surveillance camera, urban street, daytime, overcast sky"
)
```

---

## License

Apache 2.0

> Cosmos-Transfer2.5 model weights are released under the [NVIDIA Open Model License](https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-license/). Weights are downloaded at runtime and are not bundled in this image.