CoolFace
Apppublic

kalpkanungo/SceneGraphNet

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

🧠 Scene Graph Generator (Multimodal AI System)

A multimodal computer vision system that takes an input image, detects objects, predicts relationships between them, constructs a structured scene graph, and generates a natural language description of the scene.

πŸ”— Live Demo (Hugging Face Spaces): https://huggingface.co/spaces/<your-username>/scene-graph-generator


πŸš€ Features

  • β€”πŸ–ΌοΈ Object Detection using DETR (ResNet-50)
  • β€”πŸ”— Relationship Prediction (Custom Trained Model)
  • β€”πŸ“ Spatial Reasoning (Hybrid AI with Geometry Rules)
  • β€”πŸ§© Scene Graph Construction (Directed Graph)
  • β€”πŸ“Š Graph Visualization (NetworkX + Matplotlib)
  • β€”πŸ§  Graph-to-Text Generation (FLAN-T5)
  • β€”πŸŒ Interactive UI (Gradio)
  • β€”β˜οΈ Deployed on Hugging Face Spaces (CPU)

🧠 How It Works (End-to-End Pipeline)

1. Input

  • β€”User uploads an image (JPG/PNG) via Gradio UI
  • β€”Image is converted from PIL β†’ OpenCV format

2. Object Detection

  • β€”Uses facebook/detr-resnet-50 from Hugging Face
  • β€”Outputs:
  • β€”Object labels (COCO classes)
  • β€”Bounding boxes
  • β€”Confidence scores
  • β€”Applies threshold (β‰₯ 0.7) to filter noise

3. Pairwise Object Processing

  • β€”Generates object pairs using itertools.combinations
  • β€”Extracts bounding boxes for each pair
  • β€”Creates union region for relation inference
  • β€”Filters duplicate object pairs

4. Relationship Prediction

  • β€”Custom-trained classifier on Visual Genome subset (~10K samples)
  • β€”Predicts semantic relations:
  • β€”on, holding, behind, etc.
  • β€”Trained using PyTorch (10 epochs)

5. Spatial Reasoning (Hybrid AI)

  • β€”Uses bounding box geometry to compute:
  • β€”left_of, right_of, above, below, near
  • β€”Hybrid logic:
  • β€”Semantic relations from model (if confident)
  • β€”Otherwise fallback to spatial rules
  • β€”Reduces bias (e.g., β€œeverything = on”)

6. Graph Construction

  • β€”Builds a directed graph (NetworkX DiGraph)
  • β€”Nodes β†’ objects
  • β€”Edges β†’ relationships
  • β€”Removes duplicates and limits edges for clarity

7. Graph Visualization

  • β€”Uses NetworkX + Matplotlib
  • β€”Displays:
  • β€”Directed edges with labels
  • β€”Clean layout for readability

8. Graph β†’ Text (NLP)

  • β€”Uses google/flan-t5-small
  • β€”Converts structured triples into natural language

Example: laptop β†’ on β†’ table mouse β†’ next_to β†’ laptop

Output: "A laptop is placed on a table with a mouse next to it."


9. UI (Gradio)

  • β€”Upload image
  • β€”View:
  • β€”Scene graph
  • β€”Generated description
  • β€”Fully interactive and browser-based

πŸ—οΈ Tech Stack


- **Computer Vision:** DETR (Hugging Face Transformers)
- **Deep Learning:** PyTorch
- **Graph Processing:** NetworkX
- **NLP:** FLAN-T5
- **Image Processing:** OpenCV
- **Frontend/UI:** Gradio
- **Deployment:** Hugging Face Spaces

πŸ“ Project Structure

scene-graph-generator/ β”‚ β”œβ”€β”€ app.py β”œβ”€β”€ requirements.txt β”œβ”€β”€ README.md β”‚ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ pipeline.py β”‚ β”œβ”€β”€ detection.py β”‚ β”œβ”€β”€ spatialrules.py β”‚ β”œβ”€β”€ relationshipinfer.py β”‚ β”œβ”€β”€ scenegraph.py β”‚ β”œβ”€β”€ visualization.py β”‚ β”œβ”€β”€ textgeneration.py


βš™οΈ Installation (Local Setup)

bash
git clone https://github.com/<your-username>/scene-graph-generator.git
cd scene-graph-generator

pip install -r requirements.txt
python app.py