johnwesley756/instance-segmentation
0
π¦· Tooth Decay Detection and Severity Analysis Using Deep Learning
A computer vision project that uses YOLOv8 to detect dental conditions like tooth, caries, and cavity from images. The application features a FastAPI backend for API-based inference and a Streamlit frontend for interactive testing.
π Features
- β‘ Real-time detection of tooth, caries, and cavity
- π Severity classification (Tooth β Caries β Cavity)
- π Natural language summary for each detection
- π REST API for integration with other applications
- π Streamlit UI for easy testing and visualization
- π³ Docker support for easy deployment
- βοΈ Hugging Face Spaces ready
ποΈ Architecture
βββββββββββββββββββ ββββββββββββββββββββ
β Streamlit UI β ββHTTPβββΆβ FastAPI Server β
β (Frontend) β β (Backend) β
β Port: 7860 β β Port: 8000 β
βββββββββββββββββββ ββββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β YOLOv8 Model β
β (best.pt) β
βββββββββββββββββββπ§ Technologies Used
- Python 3.11+
- YOLOv8 / Ultralytics - Object detection model
- FastAPI - REST API backend
- Streamlit - Interactive frontend
- OpenCV - Image processing
- Docker - Containerization
π Project Structure
π¦ Instance-segmentation
β£ π api.py # FastAPI backend server
β£ π app.py # Streamlit frontend
β£ π train_model.py # Original Streamlit app (legacy)
β£ π best.pt # YOLOv8 trained model
β£ π requirements.txt # Python dependencies
β£ π Dockerfile # Docker configuration
β£ π start.sh # Linux/Mac startup script
β£ π start.bat # Windows startup script
β π README.md # This fileπ Quick Start
Option 1: Local Development
- Install dependencies
pip install -r requirements.txt- Start the FastAPI backend
uvicorn api:app --host 0.0.0.0 --port 8000- Start the Streamlit frontend (in a new terminal)
streamlit run app.py --server.port 7860- Access the application
- Streamlit UI: http://localhost:7860
- FastAPI Docs: http://localhost:8000/docs
Option 2: Using Startup Scripts
Windows:
start.batLinux/Mac:
chmod +x start.sh
./start.shOption 3: Docker
- Build the Docker image
docker build -t tooth-detection .- Run the container
docker run -p 7860:7860 -p 8000:8000 tooth-detectionπ API Endpoints
GET /
Root endpoint with API information
GET /health
Health check endpoint
{
"status": "healthy",
"model_loaded": true,
"model_path": "best.pt"
}POST /predict
Upload an image for tooth decay detection
Request:
- Method:
POST - Content-Type:
multipart/form-data - Body:
file(image file)
Response:
{
"success": true,
"severity": "Caries",
"summary": "Caries (initial decay) detected...",
"detections": [
{
"class": "caries",
"confidence": 0.856,
"bbox": [120.5, 45.2, 280.3, 190.7]
}
],
"total_detections": 1,
"annotated_image": "base64_encoded_image..."
}Example using cURL:
curl -X POST "http://localhost:8000/predict" \
-F "file=@dental_image.jpg"Example using Python:
import requests
url = "http://localhost:8000/predict"
files = {"file": open("dental_image.jpg", "rb")}
response = requests.post(url, files=files)
print(response.json())β Severity Logic
π Deploying to Hugging Face Spaces
- Create a new Space on Hugging Face
- Choose "Docker" as the SDK
- Upload files:
api.pyapp.pybest.ptrequirements.txtDockerfilestart.sh
- The Space will automatically build and deploy
- Access your deployed app at:
https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
π§ͺ Testing the Model
- Upload a dental X-ray or intraoral image
- The model will detect and classify:
- Tooth: Healthy teeth
- Caries: Early-stage decay
- Cavity: Advanced decay
- View the annotated image with bounding boxes
- Read the severity level and summary
π§ Future Enhancements
- Add authentication for API access
- Implement batch processing for multiple images
- Add model versioning and A/B testing
- Create mobile app using the API
- Add real-time webcam detection
- Integrate with dental clinic management systems
π License
This project is for educational and research purposes.
π¨βπ» Developer
Built with β€οΈ using YOLOv8, FastAPI, and Streamlit
