File size: 9,246 Bytes
2805777
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# JSON API Documentation

This document describes the JSON-structured API endpoints for the Vestiq Fashion Analysis System.

## Overview

The Vestiq API now provides structured JSON responses for fashion analysis, making it easy to integrate with other applications and process results programmatically.

## Base URL

```
http://localhost:7861
```

## Authentication

No authentication required for current version.

## Content Types

- **Request**: `multipart/form-data` (for image uploads)
- **Response**: `application/json`

## API Endpoints

### 1. Health Check

**GET** `/health`

Check the health status of the API and models.

**Response:**
```json
{
  "status": "healthy",
  "models": "loaded", 
  "device": "cpu"
}
```

### 2. Detailed JSON Analysis

**POST** `/analyze-json`

Analyze an uploaded image and return comprehensive structured JSON response.

**Request:**
- Method: `POST`
- Content-Type: `multipart/form-data`
- Body: Form data with `file` field containing the image

**Response:**
```json
{
  "structured_analysis": {
    "upper_garment": {
      "type": "Floral midi dress",
      "color": "Navy blue base with white and pink floral print",
      "material": "Lightweight cotton or cotton blend",
      "features": "Short sleeves, round neckline, fitted bodice with A-line skirt"
    },
    "lower_garment": {
      "type": "Not applicable - dress serves as complete outfit",
      "color": "N/A",
      "material": "N/A",
      "features": "N/A"
    },
    "footwear": {
      "type": "White leather sneakers",
      "color": "Clean white with minimal accent details",
      "material": "Leather upper with rubber sole",
      "features": "Lace-up closure, low-profile design"
    },
    "outfit_summary": {
      "aesthetic": "Casual chic",
      "style_notes": "Floral pattern with modern styling",
      "occasion_suitability": "Versatile for multiple occasions",
      "color_harmony": "Cool-toned palette with neutral accents",
      "overall_assessment": "This outfit demonstrates perfect balance between feminine charm and casual comfort..."
    },
    "confidence_score": 0.847,
    "detected_items": [
      {
        "category": "dress",
        "confidence": 0.892,
        "bbox": [45.2, 78.1, 234.7, 456.3]
      },
      {
        "category": "shoes",
        "confidence": 0.756,
        "bbox": [89.4, 423.8, 187.2, 478.9]
      }
    ]
  },
  "raw_analysis": "UPPER GARMENT:\nType: Floral midi dress\n...",
  "processing_time": 2.347,
  "model_info": {
    "detection_model": "yainage90/fashion-object-detection",
    "feature_model": "yainage90/fashion-image-feature-extractor",
    "device": "cpu"
  }
}
```

### 3. Object Detection Only

**POST** `/detect-objects`

Detect fashion objects in an image and return detection results.

**Request:**
- Method: `POST`
- Content-Type: `multipart/form-data`
- Body: Form data with `file` field containing the image

**Response:**
```json
{
  "detected_items": [
    {
      "category": "top",
      "confidence": 0.892,
      "bbox": [45.2, 78.1, 234.7, 298.5]
    },
    {
      "category": "bottom", 
      "confidence": 0.756,
      "bbox": [52.1, 285.3, 227.8, 423.9]
    },
    {
      "category": "shoes",
      "confidence": 0.634,
      "bbox": [89.4, 423.8, 187.2, 478.9]
    }
  ]
}
```

### 4. Feature Extraction Only

**POST** `/extract-features`

Extract fashion features from an image.

**Request:**
- Method: `POST`
- Content-Type: `multipart/form-data`
- Body: Form data with `file` field containing the image

**Response:**
```json
{
  "feature_vector": [0.123, -0.456, 0.789, ...],
  "feature_dimension": 128,
  "processing_time": 1.234,
  "model_used": "yainage90/fashion-image-feature-extractor"
}
```

### 5. Legacy Text Analysis

**POST** `/analyze-image`

Legacy endpoint returning text-based analysis.

**Response:**
```json
{
  "analysis": "Detailed text-based fashion analysis..."
}
```

**POST** `/analyze-structured`

Legacy endpoint returning structured text analysis.

**Response:**
```json
{
  "analysis": "UPPER GARMENT:\nType: ...\n\nLOWER GARMENT:\n..."
}
```

## Data Models

### GarmentDetails
```json
{
  "type": "string",        // Garment type (e.g., "Floral midi dress")
  "color": "string",       // Color description with analysis
  "material": "string",    // Material type or inference
  "features": "string"     // Detailed features description
}
```

### OutfitSummary
```json
{
  "aesthetic": "string",           // Overall aesthetic style
  "style_notes": "string",         // Pattern and design notes
  "occasion_suitability": "string", // Suitable occasions
  "color_harmony": "string",       // Color analysis
  "overall_assessment": "string"   // Comprehensive summary
}
```

### StructuredAnalysisResponse
```json
{
  "upper_garment": "GarmentDetails",
  "lower_garment": "GarmentDetails", 
  "footwear": "GarmentDetails",
  "outfit_summary": "OutfitSummary",
  "confidence_score": "float",      // 0.0 to 1.0
  "detected_items": "array"         // Array of detection results
}
```

### DetectedItem
```json
{
  "category": "string",    // Fashion category (top, bottom, shoes, etc.)
  "confidence": "float",   // Detection confidence (0.0 to 1.0)
  "bbox": "array"         // Bounding box [x1, y1, x2, y2]
}
```

## Fashion Categories

The system recognizes these fashion categories:
- `top` - Shirts, blouses, t-shirts
- `bottom` - Pants, jeans, skirts
- `dress` - Dresses of all types
- `outer` - Jackets, blazers, coats
- `shoes` - All types of footwear
- `bag` - Bags and purses
- `hat` - Hats and headwear

## Error Responses

All endpoints return error responses in this format:

```json
{
  "detail": "Error message describing what went wrong"
}
```

Common HTTP status codes:
- `400` - Bad Request (invalid input)
- `422` - Unprocessable Entity (validation error)
- `500` - Internal Server Error (processing failed)

## Usage Examples

### cURL Examples

```bash
# Health check
curl -X GET "http://localhost:7861/health"

# Analyze image with JSON response
curl -X POST "http://localhost:7861/analyze-json" \
     -F "file=@your_image.jpg"

# Detect objects only
curl -X POST "http://localhost:7861/detect-objects" \
     -F "file=@your_image.jpg"

# Extract features only
curl -X POST "http://localhost:7861/extract-features" \
     -F "file=@your_image.jpg"
```

### Python Examples

```python
import requests

# Analyze image with structured JSON
with open('fashion_image.jpg', 'rb') as f:
    response = requests.post(
        'http://localhost:7861/analyze-json',
        files={'file': f}
    )
    result = response.json()
    
    # Access structured data
    upper_garment = result['structured_analysis']['upper_garment']
    confidence = result['structured_analysis']['confidence_score']
    processing_time = result['processing_time']

# Object detection only
with open('fashion_image.jpg', 'rb') as f:
    response = requests.post(
        'http://localhost:7861/detect-objects',
        files={'file': f}
    )
    detections = response.json()['detected_items']
    
    for item in detections:
        print(f"Found {item['category']} with {item['confidence']:.3f} confidence")
```

### JavaScript Examples

```javascript
// Analyze image with fetch API
const formData = new FormData();
formData.append('file', fileInput.files[0]);

fetch('/analyze-json', {
    method: 'POST',
    body: formData
})
.then(response => response.json())
.then(data => {
    console.log('Analysis result:', data.structured_analysis);
    console.log('Processing time:', data.processing_time);
});

// Object detection
fetch('/detect-objects', {
    method: 'POST', 
    body: formData
})
.then(response => response.json())
.then(data => {
    data.detected_items.forEach(item => {
        console.log(`${item.category}: ${item.confidence}`);
    });
});
```

## Performance Notes

- **Processing Time**: Typical analysis takes 1-5 seconds depending on image size and hardware
- **Image Formats**: Supports JPEG, PNG, WebP, and other common formats
- **Image Size**: Optimal size is 224x224 to 512x512 pixels
- **Batch Processing**: Currently single image per request
- **Rate Limiting**: No rate limiting implemented in current version

## Integration Tips

1. **Error Handling**: Always check HTTP status codes and handle errors gracefully
2. **Image Preprocessing**: Resize large images before upload for better performance
3. **Confidence Thresholds**: Filter detection results by confidence score (>0.5 recommended)
4. **Caching**: Consider caching results for identical images
5. **Async Processing**: Use async/await patterns for better user experience

## DeepFashion2 Integration

When the DeepFashion2 dataset is available, additional endpoints become active:

- `/deepfashion2/status` - Check dataset availability
- `/deepfashion2/statistics` - Get dataset statistics
- `/deepfashion2/evaluate` - Run model evaluation
- `/deepfashion2/train` - Start model training

See [DEEPFASHION2_INTEGRATION.md](DEEPFASHION2_INTEGRATION.md) for details.

## Support

For issues or questions:
1. Check the server logs for detailed error messages
2. Verify image format and size requirements
3. Test with the `/health` endpoint to ensure models are loaded
4. Review this documentation for correct API usage