Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,116 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Scene Graph Generator API
|
| 2 |
+
|
| 3 |
+
This repository provides an API endpoint for generating scene graphs from images. Upload an image, and the API returns the annotated image, a visual graph representation, and the detected relationships between objects.
|
| 4 |
+
|
| 5 |
+
## API Usage
|
| 6 |
+
|
| 7 |
+
### Endpoint
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
POST https://dixisouls-scene-graph-generator.hf.space/generate
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
### Parameters
|
| 14 |
+
|
| 15 |
+
- `image`: The image file to analyze (multipart/form-data)
|
| 16 |
+
- `confidence_threshold`: A value between 0 and 1 (default: 0.5)
|
| 17 |
+
- `use_fixed_boxes`: Boolean value (default: false)
|
| 18 |
+
|
| 19 |
+
### Response
|
| 20 |
+
|
| 21 |
+
The API returns a JSON response with:
|
| 22 |
+
|
| 23 |
+
```json
|
| 24 |
+
{
|
| 25 |
+
"objects": [
|
| 26 |
+
{
|
| 27 |
+
"label": "person",
|
| 28 |
+
"label_id": 1,
|
| 29 |
+
"score": 0.91,
|
| 30 |
+
"bbox": [0.3, 0.4, 0.1, 0.3]
|
| 31 |
+
},
|
| 32 |
+
...
|
| 33 |
+
],
|
| 34 |
+
"relationships": [
|
| 35 |
+
{
|
| 36 |
+
"subject": "person",
|
| 37 |
+
"predicate": "riding",
|
| 38 |
+
"object": "bicycle",
|
| 39 |
+
"score": 0.82,
|
| 40 |
+
"subject_id": 0,
|
| 41 |
+
"object_id": 1,
|
| 42 |
+
"predicate_id": 5
|
| 43 |
+
},
|
| 44 |
+
...
|
| 45 |
+
],
|
| 46 |
+
"annotated_image": "base64_encoded_image_data",
|
| 47 |
+
"graph_image": "base64_encoded_image_data"
|
| 48 |
+
}
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
## Example Usage
|
| 52 |
+
|
| 53 |
+
### Python
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
import requests
|
| 57 |
+
import base64
|
| 58 |
+
from PIL import Image
|
| 59 |
+
import io
|
| 60 |
+
|
| 61 |
+
# Prepare the image
|
| 62 |
+
image_path = "your_image.jpg"
|
| 63 |
+
files = {'image': open(image_path, 'rb')}
|
| 64 |
+
|
| 65 |
+
# Set parameters
|
| 66 |
+
data = {
|
| 67 |
+
'confidence_threshold': 0.5,
|
| 68 |
+
'use_fixed_boxes': False
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
# Make the API call
|
| 72 |
+
api_url = "https://dixisouls-scene-graph-generator.hf.space/generate"
|
| 73 |
+
response = requests.post(api_url, files=files, data=data)
|
| 74 |
+
|
| 75 |
+
# Process the results
|
| 76 |
+
if response.status_code == 200:
|
| 77 |
+
result = response.json()
|
| 78 |
+
|
| 79 |
+
# Decode and save the images
|
| 80 |
+
annotated_image = Image.open(io.BytesIO(base64.b64decode(result['annotated_image'])))
|
| 81 |
+
annotated_image.save("annotated_image.jpg")
|
| 82 |
+
|
| 83 |
+
graph_image = Image.open(io.BytesIO(base64.b64decode(result['graph_image'])))
|
| 84 |
+
graph_image.save("graph_image.jpg")
|
| 85 |
+
|
| 86 |
+
# Print information about objects and relationships
|
| 87 |
+
print(f"Found {len(result['objects'])} objects and {len(result['relationships'])} relationships")
|
| 88 |
+
else:
|
| 89 |
+
print(f"Error: {response.text}")
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
### cURL
|
| 93 |
+
|
| 94 |
+
```bash
|
| 95 |
+
curl -X POST \
|
| 96 |
+
-F "image=@your_image.jpg" \
|
| 97 |
+
-F "confidence_threshold=0.5" \
|
| 98 |
+
-F "use_fixed_boxes=false" \
|
| 99 |
+
https://dixisouls-scene-graph-generator.hf.space/generate
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
## Model Information
|
| 103 |
+
|
| 104 |
+
This API uses:
|
| 105 |
+
|
| 106 |
+
- YOLOv8 for object detection
|
| 107 |
+
- A custom neural network for relationship prediction
|
| 108 |
+
- PyTorch as the deep learning framework
|
| 109 |
+
|
| 110 |
+
## License
|
| 111 |
+
|
| 112 |
+
This project is licensed under the MIT License.
|
| 113 |
+
|
| 114 |
+
## Author
|
| 115 |
+
|
| 116 |
+
Created by [dixisouls](https://github.com/dixisouls)
|