caozhaoqi/anime_role_detect

The Character Classification System is an AI-based image recognition tool specifically designed to identify characters from games and anime.

1

stars

597

commits

Python

primary language

Aug 21, 2026

updated

caozhaoqi.github.io

README

Character Classification System

Python Version License

An AI-powered image recognition system designed to identify characters from games and anime.

โœจ Features

  • Multi-format Recognition: Supports images and videos
  • Multi-role Detection: Identify multiple characters in single image (YOLOv8/v10 integration)
  • High Accuracy: Powered by MobileNetV2, EfficientNet-B0/B3, ResNet50
  • DeepDanbooru Integration: Enhanced tagging capabilities
  • Attribute Prediction: Hair color, eye color, clothing attributes
  • RESTful API: Batch processing support
  • Log Fusion: Build new models from classification logs
  • Layered Architecture: Distributed deployment ready
  • Model Warm-up: Reduced first-request latency
  • Request Debouncing/Throttling: Prevent duplicate submissions
  • Image Compression: Optimized upload bandwidth
  • Redis Cache: Reduce redundant computations
  • Feishu Notifications: Real-time progress updates
  • Token Auto-refresh: Seamless authentication

๐Ÿ“ System Architecture

System Architecture

Layered topology: Access (API Gateway) โ†’ Business services (API / Model / Multimedia / Search) โ†’ Async workers (Inference / Search Worker) โ†’ Core AI (Classification / Detection / Recognition / Tagging / Keypoint) โ†’ Infrastructure (Redis / MySQL / RabbitMQ / Fluent-bit / Grafana) โ†’ Deployment (Supervisord / Docker Compose / Kubernetes).

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.9+
  • 16GB+ RAM (required for model loading)
  • NVIDIA GPU (recommended for inference speed)
  • Redis Server (for caching)
  • Docker & Docker Compose (for containerized deployment)

Installation

# Clone the repository
git clone https://github.com/ard-team/anime_role_detect.git
cd anime_role_detect

# Create virtual environment
python -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements-base.txt
pip install -r requirements-ml.txt  # For model training/inference
pip install -r requirements-dev.txt  # For development
pip install supervisor  # For process management

# Configure environment
cp .env.example .env
# Edit .env with your configuration
# Start Redis (required for caching)
redis-server &

# Start all services using supervisord
supervisord -c supervisord.conf

# Check service status
supervisorctl status

# Stop all services
supervisorctl stop all

# linux
nohup ./src/run/sh/run_with_supervisor.sh start >/dev/null 2>&1 &

Docker Deployment

# Build and start all services
docker-compose up --build -d

# Check container status
docker-compose ps

# View logs
docker-compose logs -f <service_name>

# Stop services
docker-compose down

# k8s deployment

# 1. ๆž„ๅปบๆ‰€ๆœ‰้•œๅƒ
./scripts/k8s/build_k8s_images.sh

# 2. ้ƒจ็ฝฒๅˆฐ K8s๏ผˆๆƒๅจๆบ๏ผšk8s/base/๏ผŒ่ฏฆ่ง k8s/README.md๏ผ‰
kubectl apply -k k8s/base/

# 3. ๆŸฅ็œ‹้ƒจ็ฝฒ็Šถๆ€
kubectl get pods -n anime-role-detect

Service Access

ServiceURLPort
Frontendhttp://localhost:30003000
API Gatewayhttp://localhost:80808080
Model Servicehttp://localhost:80008000
API Servicehttp://localhost:80018001
Multimedia Servicehttp://localhost:80028002
Search Servicehttp://localhost:80038003
Monitoringhttp://localhost:88888888
Supervisor Dashboardhttp://localhost:90019001
RabbitMQ Managementhttp://localhost:1567215672

Infrastructure ports: Redis 6379, MySQL 3306, RabbitMQ 5672, fluent-bit 2020 (Docker Compose only).

API Documentation

  • Swagger Docs: http://localhost:8080/docs
  • Redoc Docs: http://localhost:8080/redoc

Default Credentials

  • Username: admin / user
  • Password: Set via environment variables ADMIN_PASSWORD and USER_PASSWORD
  • Note: Default passwords are auto-generated on first startup if not set

๐Ÿ“ Project Structure

anime_role_detect/
โ”œโ”€โ”€ src/                    # Source code (editable install: pip install -e .)
โ”‚   โ”œโ”€โ”€ api/                # Backend API service (FastAPI, port 8001)
โ”‚   โ”‚   โ””โ”€โ”€ routes/         # API routes (classification, auth, collector, search, video,
โ”‚   โ”‚                       #   cleaning, history, models, onnx_inference, async_inference,
โ”‚   โ”‚                       #   tracing, version, health, misc)
โ”‚   โ”œโ”€โ”€ services/           # Microservices
โ”‚   โ”‚   โ”œโ”€โ”€ api_gateway/    # API Gateway (port 8080, aggregates Swagger docs)
โ”‚   โ”‚   โ”œโ”€โ”€ model_service/  # Model Service (port 8000, includes keypoint_worker)
โ”‚   โ”‚   โ”œโ”€โ”€ multimedia_service/  # Multimedia Service (port 8002, video rendering)
โ”‚   โ”‚   โ”œโ”€โ”€ search_service/ # Search Service + worker (port 8003, CLIP+FAISS)
โ”‚   โ”‚   โ”œโ”€โ”€ inference_worker/   # CLIP inference worker
โ”‚   โ”‚   โ”œโ”€โ”€ inference_queue/    # Inference queue manager (Redis/Memory fallback)
โ”‚   โ”‚   โ”œโ”€โ”€ cache_service/  # Redis Cache Service
โ”‚   โ”‚   โ”œโ”€โ”€ model/          # Business model services (classify/recognize/NSFW/multi-model/version)
โ”‚   โ”‚   โ”œโ”€โ”€ processor/      # Model loaders / image processors / preprocessors
โ”‚   โ”‚   โ”œโ”€โ”€ support/        # Database service and support layer
โ”‚   โ”‚   โ”œโ”€โ”€ training/       # Training-related services
โ”‚   โ”‚   โ””โ”€โ”€ notification_service.py  # Feishu notifications
โ”‚   โ”œโ”€โ”€ core/               # Core capabilities
โ”‚   โ”‚   โ”œโ”€โ”€ classification/ # EfficientNet/MobileNet/DeepDanbooru classification
โ”‚   โ”‚   โ”œโ”€โ”€ detection/      # YOLO multi-role detection + anime_face_detector
โ”‚   โ”‚   โ”œโ”€โ”€ recognition/    # CLIP/ArcFace open-set recognition + feature store
โ”‚   โ”‚   โ”œโ”€โ”€ tagging/        # WD-ViT-Tagger + DeepDanbooru tagging
โ”‚   โ”‚   โ”œโ”€โ”€ keypoint/       # MediaPipe keypoints
โ”‚   โ”‚   โ”œโ”€โ”€ ocr/            # EasyOCR
โ”‚   โ”‚   โ”œโ”€โ”€ feature_extraction/  # Feature extraction (incl. CoreML)
โ”‚   โ”‚   โ”œโ”€โ”€ log_fusion/     # Log fusion
โ”‚   โ”‚   โ”œโ”€โ”€ preprocessing/  # Image/data preprocessors
โ”‚   โ”‚   โ”œโ”€โ”€ config/         # Configuration (ServiceConfig / DeviceManager)
โ”‚   โ”‚   โ”œโ”€โ”€ cache/          # Cache abstractions
โ”‚   โ”‚   โ”œโ”€โ”€ logging/        # Structured logging (loguru JSON)
โ”‚   โ”‚   โ””โ”€โ”€ ...             # error / exception / feedback / version / utils
โ”‚   โ”œโ”€โ”€ data/               # Data collection / cleaning / augmentation / search index
โ”‚   โ”œโ”€โ”€ data_pipeline/      # Data cleaning pipeline + active_learning + Streamlit webui
โ”‚   โ”œโ”€โ”€ data_collection/    # (Legacy) keyword-based collector entry
โ”‚   โ”œโ”€โ”€ models/             # Database models + training / evaluation / prediction / deployment
โ”‚   โ”œโ”€โ”€ tasks/              # Celery tasks (classify/image/video/model/cleanup)
โ”‚   โ”œโ”€โ”€ utils/              # Shared utilities (image, http, concurrency, memory, monitoring, config)
โ”‚   โ”œโ”€โ”€ middleware/         # HTTP middleware (auth_enhanced / monitoring / tracing)
โ”‚   โ”œโ”€โ”€ frontend/           # Frontend (Next.js 15 + React 18 + TypeScript App Router)
โ”‚   โ”œโ”€โ”€ run/                # Service management / monitor dashboard / launch scripts
โ”‚   โ”œโ”€โ”€ cache/              # HuggingFace / Keras model cache directories
โ”‚   โ””โ”€โ”€ static/             # Static assets
โ”œโ”€โ”€ models/                 # Model weights (git-ignored)
โ”œโ”€โ”€ tests/                  # Test suites (unit / integration / model / workflow / regression / performance / benchmark)
โ”œโ”€โ”€ docs/                   # Documentation (architecture / deployment / training / blog / testing / technical_challenges)
โ”œโ”€โ”€ scripts/                # Utility scripts (k8s, monitoring, data_*, model_evaluation, coreml, detection, ...)
โ”‚   โ””โ”€โ”€ skillhub/           # โš ๏ธ Archived experiment sub-project (88MB, not referenced)
โ”œโ”€โ”€ archived/               # Historical / broken modules (spider_image_system, arona, ...)
โ”œโ”€โ”€ deployment/             # Docker deployment files (11 Dockerfile.* + nginx + grafana)
โ”œโ”€โ”€ k8s/                    # Kustomize (base/ + overlays/ci/)
โ”œโ”€โ”€ config/                 # Config templates (config.ini / config.py)
โ”œโ”€โ”€ supervisord.conf        # Process manager configuration (12 programs)
โ”œโ”€โ”€ docker-compose.yml      # Docker Compose configuration (13 services)
โ”œโ”€โ”€ Dockerfile              # Backend Dockerfile (root)
โ”œโ”€โ”€ Dockerfile.model        # Model Service Dockerfile (root)
โ”œโ”€โ”€ requirements.txt        # Full dependencies
โ”œโ”€โ”€ requirements-base.txt   # Base dependencies (for base image)
โ”œโ”€โ”€ requirements-ml.txt     # ML dependencies
โ”œโ”€โ”€ requirements-model-service.txt
โ”œโ”€โ”€ requirements-scripts.txt
โ”œโ”€โ”€ requirements-dev.txt    # Development dependencies
โ”œโ”€โ”€ pyproject.toml          # Project configuration (v2.3.0, authoritative version source)
โ””โ”€โ”€ .env.example            # Environment template

๐ŸŒ API Endpoints

EndpointMethodDescription
/api/classifyPOSTImage classification
/api/classify/multi-rolePOSTMulti-character detection (YOLO)
/api/classify/asyncPOSTAsync classification (task queue)
/api/search/imagePOSTReverse image search (CLIP+FAISS)
/api/video/recognizePOSTVideo recognition
/api/collectPOSTData collection task
/api/cleaningPOSTData cleaning task
/api/historyGETRecognition history
/api/modelsGETModel info & version
/api/onnx/inferPOSTONNX inference
/api/healthGETHealth check
/api/servicesGETService status
/api/auth/loginPOSTUser login
/api/auth/refreshPOSTRefresh token
/api/versionGETVersion info
/metricsGETPrometheus metrics

Full route definitions in src/api/routes/. Gateway aggregated docs: http://localhost:8080/docs.

๐Ÿ”ง Configuration

Environment Variables

VariableDescriptionDefault
REDIS_URLRedis connection URLredis://localhost:6379
JWT_SECRETJWT secret key(required)
JWT_EXPIRE_MINUTESToken expiration1440 (24h)
MAX_IMAGE_SIZEMax upload size (MB)10
DEVICECompute device (cpu/cuda/mps)auto

Docker Configuration

The project includes comprehensive Docker support:

  • docker-compose.yml: Multi-service orchestration (13 services) with Redis, MySQL, RabbitMQ, fluent-bit, and all application services
  • Root Dockerfile: Backend service image
  • Root Dockerfile.model: Model service image
  • deployment/: 11 Dockerfiles (base / ml-base / api-service / api-gateway / model-service / multimedia-service / search-service / search-worker / inference-worker / monitoring / frontend) + nginx.conf + grafana dashboard
  • Resource limits: model-service 4G/4cpu, others 256M-1.5G (compressed in compose file)

๐Ÿ“Š Model Performance

Current Classification Model (v9, EfficientNet-B3)

efficientnet_b3_v9 โ€” EfficientNet-B3 backbone, 167 character classes, canonical preprocessing Resize(288)โ†’CenterCrop(256), evaluated on the held-out test split (post_id-grouped, no train/test overlap). Trained 2026-08-12.

MetricValue
Top-1 Accuracy (held-out TEST, honest)61.19%
Top-5 Accuracy78.48%
Macro-F1 (167 classes)0.5633
Weighted-F10.6071
Balanced Accuracy0.5741
Validation Best Macro-F1 (model-selection metric)0.5875 (Val Top-1 63.15%)

Deployment note: the running backend currently loads efficientnet_b3_v4 (174 classes) by default; v9 is the latest honestly-evaluated checkpoint and is pending promotion to default. Full per-class report: deliverables/gstack/model-baseline-v9-honest-2026-08-12.md.

Deprecated metrics (do not use)

Earlier documentation reported efficientnet_b3 at 51 classes with Top-1 84.00% / 82.65% and Macro-F1 0.8401. These came from a train/test leakage (same images used for both training and testing) and were superseded by the honest 167-class evaluation above. See docs/training/DATA_LEAKAGE_STATUS.md for the leakage analysis.

Multi-role Detection (YOLOv8n)

yolov8n.pt is the COCO-pretrained baseline (6.25 MB, 3.15M params). It is not fine-tuned on anime characters โ€” avg confidence 0.444, ~4 FPS on MPS. Fine-tuning is pending.

Model Comparison (reference)

ModelClassesTop-1 (honest TEST)Note
EfficientNet-B3 v9 (latest)16761.19%Honest held-out TEST; Macro-F1 0.5633
EfficientNet-B3 v4 (serving default)174โ€”Currently loaded by backend
EfficientNet-B0 / MobileNetV2 / ResNet50โ€”โ€”Earlier experiments, see docs/blog/10_training_and_evaluation.md

๐Ÿ”’ Security

  • JWT authentication with secret key rotation
  • Password hashing with bcrypt/sha256
  • Rate limiting to prevent abuse
  • Input validation and sanitization
  • HttpOnly Cookie storage
  • Content Security Policy (CSP) for XSS protection
  • Automatic token refresh mechanism

๐Ÿงช Testing

Automated Testing

# Run unit tests
python -m pytest tests/ -v

# Run integration tests
python -m pytest tests/integration/ -v

# Run model benchmark (produces scripts/model_evaluation/benchmark_results.json)
python scripts/model_evaluation/run_benchmark.py

๐Ÿ“š Documentation

For detailed documentation:

  • docs/architecture/ - Project structure & architecture design
  • docs/deployment/ - Deployment guides (Kubernetes, Ubuntu)
  • docs/training/ - Model training guides + data leakage analysis
  • docs/blog/ - Technical blog posts
  • docs/testing/ - Testing guides
  • docs/technical_challenges/ - Technical challenges & solutions
  • docs/system_design.md / docs/system_design_perf.md - System design & performance optimization plan

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for details on:

  • How to submit bug reports and feature requests
  • Code style guidelines
  • Pull request process

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Version: v2.4.0 | Last Updated: 2026-08-12 | Maintainer: ARD Team


Topics: anime, character-recognition, image-classification, deep-learning, python-api, computer-vision, yolov8, nextjs, docker, microservices

Contributors

caozhaoqi

588 commits

caozhaoqi/anime_role_detect

The Character Classification System is an AI-based image recognition tool specifically designed to identify characters from games and anime.

1

stars

597

commits

Python

primary language

Aug 21, 2026

updated

caozhaoqi.github.io

README

Character Classification System

Python Version License

An AI-powered image recognition system designed to identify characters from games and anime.

โœจ Features

  • Multi-format Recognition: Supports images and videos
  • Multi-role Detection: Identify multiple characters in single image (YOLOv8/v10 integration)
  • High Accuracy: Powered by MobileNetV2, EfficientNet-B0/B3, ResNet50
  • DeepDanbooru Integration: Enhanced tagging capabilities
  • Attribute Prediction: Hair color, eye color, clothing attributes
  • RESTful API: Batch processing support
  • Log Fusion: Build new models from classification logs
  • Layered Architecture: Distributed deployment ready
  • Model Warm-up: Reduced first-request latency
  • Request Debouncing/Throttling: Prevent duplicate submissions
  • Image Compression: Optimized upload bandwidth
  • Redis Cache: Reduce redundant computations
  • Feishu Notifications: Real-time progress updates
  • Token Auto-refresh: Seamless authentication

๐Ÿ“ System Architecture

System Architecture

Layered topology: Access (API Gateway) โ†’ Business services (API / Model / Multimedia / Search) โ†’ Async workers (Inference / Search Worker) โ†’ Core AI (Classification / Detection / Recognition / Tagging / Keypoint) โ†’ Infrastructure (Redis / MySQL / RabbitMQ / Fluent-bit / Grafana) โ†’ Deployment (Supervisord / Docker Compose / Kubernetes).

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.9+
  • 16GB+ RAM (required for model loading)
  • NVIDIA GPU (recommended for inference speed)
  • Redis Server (for caching)
  • Docker & Docker Compose (for containerized deployment)

Installation

# Clone the repository
git clone https://github.com/ard-team/anime_role_detect.git
cd anime_role_detect

# Create virtual environment
python -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements-base.txt
pip install -r requirements-ml.txt  # For model training/inference
pip install -r requirements-dev.txt  # For development
pip install supervisor  # For process management

# Configure environment
cp .env.example .env
# Edit .env with your configuration
# Start Redis (required for caching)
redis-server &

# Start all services using supervisord
supervisord -c supervisord.conf

# Check service status
supervisorctl status

# Stop all services
supervisorctl stop all

# linux
nohup ./src/run/sh/run_with_supervisor.sh start >/dev/null 2>&1 &

Docker Deployment

# Build and start all services
docker-compose up --build -d

# Check container status
docker-compose ps

# View logs
docker-compose logs -f <service_name>

# Stop services
docker-compose down

# k8s deployment

# 1. ๆž„ๅปบๆ‰€ๆœ‰้•œๅƒ
./scripts/k8s/build_k8s_images.sh

# 2. ้ƒจ็ฝฒๅˆฐ K8s๏ผˆๆƒๅจๆบ๏ผšk8s/base/๏ผŒ่ฏฆ่ง k8s/README.md๏ผ‰
kubectl apply -k k8s/base/

# 3. ๆŸฅ็œ‹้ƒจ็ฝฒ็Šถๆ€
kubectl get pods -n anime-role-detect

Service Access

ServiceURLPort
Frontendhttp://localhost:30003000
API Gatewayhttp://localhost:80808080
Model Servicehttp://localhost:80008000
API Servicehttp://localhost:80018001
Multimedia Servicehttp://localhost:80028002
Search Servicehttp://localhost:80038003
Monitoringhttp://localhost:88888888
Supervisor Dashboardhttp://localhost:90019001
RabbitMQ Managementhttp://localhost:1567215672

Infrastructure ports: Redis 6379, MySQL 3306, RabbitMQ 5672, fluent-bit 2020 (Docker Compose only).

API Documentation

  • Swagger Docs: http://localhost:8080/docs
  • Redoc Docs: http://localhost:8080/redoc

Default Credentials

  • Username: admin / user
  • Password: Set via environment variables ADMIN_PASSWORD and USER_PASSWORD
  • Note: Default passwords are auto-generated on first startup if not set

๐Ÿ“ Project Structure

anime_role_detect/
โ”œโ”€โ”€ src/                    # Source code (editable install: pip install -e .)
โ”‚   โ”œโ”€โ”€ api/                # Backend API service (FastAPI, port 8001)
โ”‚   โ”‚   โ””โ”€โ”€ routes/         # API routes (classification, auth, collector, search, video,
โ”‚   โ”‚                       #   cleaning, history, models, onnx_inference, async_inference,
โ”‚   โ”‚                       #   tracing, version, health, misc)
โ”‚   โ”œโ”€โ”€ services/           # Microservices
โ”‚   โ”‚   โ”œโ”€โ”€ api_gateway/    # API Gateway (port 8080, aggregates Swagger docs)
โ”‚   โ”‚   โ”œโ”€โ”€ model_service/  # Model Service (port 8000, includes keypoint_worker)
โ”‚   โ”‚   โ”œโ”€โ”€ multimedia_service/  # Multimedia Service (port 8002, video rendering)
โ”‚   โ”‚   โ”œโ”€โ”€ search_service/ # Search Service + worker (port 8003, CLIP+FAISS)
โ”‚   โ”‚   โ”œโ”€โ”€ inference_worker/   # CLIP inference worker
โ”‚   โ”‚   โ”œโ”€โ”€ inference_queue/    # Inference queue manager (Redis/Memory fallback)
โ”‚   โ”‚   โ”œโ”€โ”€ cache_service/  # Redis Cache Service
โ”‚   โ”‚   โ”œโ”€โ”€ model/          # Business model services (classify/recognize/NSFW/multi-model/version)
โ”‚   โ”‚   โ”œโ”€โ”€ processor/      # Model loaders / image processors / preprocessors
โ”‚   โ”‚   โ”œโ”€โ”€ support/        # Database service and support layer
โ”‚   โ”‚   โ”œโ”€โ”€ training/       # Training-related services
โ”‚   โ”‚   โ””โ”€โ”€ notification_service.py  # Feishu notifications
โ”‚   โ”œโ”€โ”€ core/               # Core capabilities
โ”‚   โ”‚   โ”œโ”€โ”€ classification/ # EfficientNet/MobileNet/DeepDanbooru classification
โ”‚   โ”‚   โ”œโ”€โ”€ detection/      # YOLO multi-role detection + anime_face_detector
โ”‚   โ”‚   โ”œโ”€โ”€ recognition/    # CLIP/ArcFace open-set recognition + feature store
โ”‚   โ”‚   โ”œโ”€โ”€ tagging/        # WD-ViT-Tagger + DeepDanbooru tagging
โ”‚   โ”‚   โ”œโ”€โ”€ keypoint/       # MediaPipe keypoints
โ”‚   โ”‚   โ”œโ”€โ”€ ocr/            # EasyOCR
โ”‚   โ”‚   โ”œโ”€โ”€ feature_extraction/  # Feature extraction (incl. CoreML)
โ”‚   โ”‚   โ”œโ”€โ”€ log_fusion/     # Log fusion
โ”‚   โ”‚   โ”œโ”€โ”€ preprocessing/  # Image/data preprocessors
โ”‚   โ”‚   โ”œโ”€โ”€ config/         # Configuration (ServiceConfig / DeviceManager)
โ”‚   โ”‚   โ”œโ”€โ”€ cache/          # Cache abstractions
โ”‚   โ”‚   โ”œโ”€โ”€ logging/        # Structured logging (loguru JSON)
โ”‚   โ”‚   โ””โ”€โ”€ ...             # error / exception / feedback / version / utils
โ”‚   โ”œโ”€โ”€ data/               # Data collection / cleaning / augmentation / search index
โ”‚   โ”œโ”€โ”€ data_pipeline/      # Data cleaning pipeline + active_learning + Streamlit webui
โ”‚   โ”œโ”€โ”€ data_collection/    # (Legacy) keyword-based collector entry
โ”‚   โ”œโ”€โ”€ models/             # Database models + training / evaluation / prediction / deployment
โ”‚   โ”œโ”€โ”€ tasks/              # Celery tasks (classify/image/video/model/cleanup)
โ”‚   โ”œโ”€โ”€ utils/              # Shared utilities (image, http, concurrency, memory, monitoring, config)
โ”‚   โ”œโ”€โ”€ middleware/         # HTTP middleware (auth_enhanced / monitoring / tracing)
โ”‚   โ”œโ”€โ”€ frontend/           # Frontend (Next.js 15 + React 18 + TypeScript App Router)
โ”‚   โ”œโ”€โ”€ run/                # Service management / monitor dashboard / launch scripts
โ”‚   โ”œโ”€โ”€ cache/              # HuggingFace / Keras model cache directories
โ”‚   โ””โ”€โ”€ static/             # Static assets
โ”œโ”€โ”€ models/                 # Model weights (git-ignored)
โ”œโ”€โ”€ tests/                  # Test suites (unit / integration / model / workflow / regression / performance / benchmark)
โ”œโ”€โ”€ docs/                   # Documentation (architecture / deployment / training / blog / testing / technical_challenges)
โ”œโ”€โ”€ scripts/                # Utility scripts (k8s, monitoring, data_*, model_evaluation, coreml, detection, ...)
โ”‚   โ””โ”€โ”€ skillhub/           # โš ๏ธ Archived experiment sub-project (88MB, not referenced)
โ”œโ”€โ”€ archived/               # Historical / broken modules (spider_image_system, arona, ...)
โ”œโ”€โ”€ deployment/             # Docker deployment files (11 Dockerfile.* + nginx + grafana)
โ”œโ”€โ”€ k8s/                    # Kustomize (base/ + overlays/ci/)
โ”œโ”€โ”€ config/                 # Config templates (config.ini / config.py)
โ”œโ”€โ”€ supervisord.conf        # Process manager configuration (12 programs)
โ”œโ”€โ”€ docker-compose.yml      # Docker Compose configuration (13 services)
โ”œโ”€โ”€ Dockerfile              # Backend Dockerfile (root)
โ”œโ”€โ”€ Dockerfile.model        # Model Service Dockerfile (root)
โ”œโ”€โ”€ requirements.txt        # Full dependencies
โ”œโ”€โ”€ requirements-base.txt   # Base dependencies (for base image)
โ”œโ”€โ”€ requirements-ml.txt     # ML dependencies
โ”œโ”€โ”€ requirements-model-service.txt
โ”œโ”€โ”€ requirements-scripts.txt
โ”œโ”€โ”€ requirements-dev.txt    # Development dependencies
โ”œโ”€โ”€ pyproject.toml          # Project configuration (v2.3.0, authoritative version source)
โ””โ”€โ”€ .env.example            # Environment template

๐ŸŒ API Endpoints

EndpointMethodDescription
/api/classifyPOSTImage classification
/api/classify/multi-rolePOSTMulti-character detection (YOLO)
/api/classify/asyncPOSTAsync classification (task queue)
/api/search/imagePOSTReverse image search (CLIP+FAISS)
/api/video/recognizePOSTVideo recognition
/api/collectPOSTData collection task
/api/cleaningPOSTData cleaning task
/api/historyGETRecognition history
/api/modelsGETModel info & version
/api/onnx/inferPOSTONNX inference
/api/healthGETHealth check
/api/servicesGETService status
/api/auth/loginPOSTUser login
/api/auth/refreshPOSTRefresh token
/api/versionGETVersion info
/metricsGETPrometheus metrics

Full route definitions in src/api/routes/. Gateway aggregated docs: http://localhost:8080/docs.

๐Ÿ”ง Configuration

Environment Variables

VariableDescriptionDefault
REDIS_URLRedis connection URLredis://localhost:6379
JWT_SECRETJWT secret key(required)
JWT_EXPIRE_MINUTESToken expiration1440 (24h)
MAX_IMAGE_SIZEMax upload size (MB)10
DEVICECompute device (cpu/cuda/mps)auto

Docker Configuration

The project includes comprehensive Docker support:

  • docker-compose.yml: Multi-service orchestration (13 services) with Redis, MySQL, RabbitMQ, fluent-bit, and all application services
  • Root Dockerfile: Backend service image
  • Root Dockerfile.model: Model service image
  • deployment/: 11 Dockerfiles (base / ml-base / api-service / api-gateway / model-service / multimedia-service / search-service / search-worker / inference-worker / monitoring / frontend) + nginx.conf + grafana dashboard
  • Resource limits: model-service 4G/4cpu, others 256M-1.5G (compressed in compose file)

๐Ÿ“Š Model Performance

Current Classification Model (v9, EfficientNet-B3)

efficientnet_b3_v9 โ€” EfficientNet-B3 backbone, 167 character classes, canonical preprocessing Resize(288)โ†’CenterCrop(256), evaluated on the held-out test split (post_id-grouped, no train/test overlap). Trained 2026-08-12.

MetricValue
Top-1 Accuracy (held-out TEST, honest)61.19%
Top-5 Accuracy78.48%
Macro-F1 (167 classes)0.5633
Weighted-F10.6071
Balanced Accuracy0.5741
Validation Best Macro-F1 (model-selection metric)0.5875 (Val Top-1 63.15%)

Deployment note: the running backend currently loads efficientnet_b3_v4 (174 classes) by default; v9 is the latest honestly-evaluated checkpoint and is pending promotion to default. Full per-class report: deliverables/gstack/model-baseline-v9-honest-2026-08-12.md.

Deprecated metrics (do not use)

Earlier documentation reported efficientnet_b3 at 51 classes with Top-1 84.00% / 82.65% and Macro-F1 0.8401. These came from a train/test leakage (same images used for both training and testing) and were superseded by the honest 167-class evaluation above. See docs/training/DATA_LEAKAGE_STATUS.md for the leakage analysis.

Multi-role Detection (YOLOv8n)

yolov8n.pt is the COCO-pretrained baseline (6.25 MB, 3.15M params). It is not fine-tuned on anime characters โ€” avg confidence 0.444, ~4 FPS on MPS. Fine-tuning is pending.

Model Comparison (reference)

ModelClassesTop-1 (honest TEST)Note
EfficientNet-B3 v9 (latest)16761.19%Honest held-out TEST; Macro-F1 0.5633
EfficientNet-B3 v4 (serving default)174โ€”Currently loaded by backend
EfficientNet-B0 / MobileNetV2 / ResNet50โ€”โ€”Earlier experiments, see docs/blog/10_training_and_evaluation.md

๐Ÿ”’ Security

  • JWT authentication with secret key rotation
  • Password hashing with bcrypt/sha256
  • Rate limiting to prevent abuse
  • Input validation and sanitization
  • HttpOnly Cookie storage
  • Content Security Policy (CSP) for XSS protection
  • Automatic token refresh mechanism

๐Ÿงช Testing

Automated Testing

# Run unit tests
python -m pytest tests/ -v

# Run integration tests
python -m pytest tests/integration/ -v

# Run model benchmark (produces scripts/model_evaluation/benchmark_results.json)
python scripts/model_evaluation/run_benchmark.py

๐Ÿ“š Documentation

For detailed documentation:

  • docs/architecture/ - Project structure & architecture design
  • docs/deployment/ - Deployment guides (Kubernetes, Ubuntu)
  • docs/training/ - Model training guides + data leakage analysis
  • docs/blog/ - Technical blog posts
  • docs/testing/ - Testing guides
  • docs/technical_challenges/ - Technical challenges & solutions
  • docs/system_design.md / docs/system_design_perf.md - System design & performance optimization plan

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for details on:

  • How to submit bug reports and feature requests
  • Code style guidelines
  • Pull request process

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Version: v2.4.0 | Last Updated: 2026-08-12 | Maintainer: ARD Team


Topics: anime, character-recognition, image-classification, deep-learning, python-api, computer-vision, yolov8, nextjs, docker, microservices

Contributors

caozhaoqi

588 commits

Languages

Python

87.8%

TypeScript

5.2%

Shell

2.6%

Vue

1.9%

HTML

1.7%