Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

SmartClass Analytics

Hybrid Classroom Behavior Understanding for Long-Form Video

Python FastAPI PyTorch Ultralytics CUDA Status

SmartClass Analytics is a deployment-oriented classroom behavior analysis system built for long surveillance-style academic video, combining GPU-efficient perception, track-level temporal reasoning, and interactive web-based review.


Table of Contents


Project Vision

Classroom video analysis is a deceptively difficult problem.

A real classroom is not a curated benchmark scene. It is a dense, long-duration, partially occluded, behavior-rich environment where multiple people act simultaneously, identities must remain consistent over time, and the same posture may correspond to different semantic meanings depending on context.

This project is designed to make that problem operational.

SmartClass Analytics transforms long classroom recordings into structured behavioral timelines through a hybrid pipeline that emphasizes:

  • speed on local GPU hardware
  • stable multi-person identity tracking
  • interpretable first-pass behavior inference
  • selective semantic refinement for ambiguous cases
  • human-in-the-loop inspection and correction
  • analytics-oriented outputs for later reporting and research

Rather than treating classroom understanding as a pure VLM problem or a pure rule-based pipeline, the system deliberately combines both philosophies in a way that is practical for real deployment.


Why This System Exists

Running a large multimodal model over every frame of a long classroom video is usually impractical.

A one-hour recording can easily contain tens of thousands of frames. If every frame is pushed into a heavy image-text model, the system becomes expensive, slow, and difficult to scale. At the same time, relying only on simple heuristics often produces labels that are too coarse for educational analytics.

This system addresses that trade-off with a two-layer design:

Layer 1 — Fast visual backbone

A GPU-friendly perception stack handles the full video stream:

  • person detection
  • tracking
  • pose estimation
  • movement and posture cues
  • first-pass behavior classification

Layer 2 — Selective semantic refinement

Only selected person crops or representative track snapshots are sent to an optional VL image-to-text model for more expressive descriptions when the first-pass stage is insufficient.

This means the system can remain:

  • fast enough for long-form video
  • expressive enough for meaningful behavior summaries
  • structured enough for analytics dashboards
  • flexible enough for future classroom intelligence tasks

System Architecture

Long classroom video
        │
        ▼
[Frame sampling / stride control]
        │
        ▼
[YOLO person detection]
        │
        ▼
[Multi-object tracking]
        │
        ▼
[Per-person pose estimation]
        │
        ▼
[Lightweight behavior rules]
        │
        ├──► annotated video
        ├──► per-frame CSV
        ├──► per-track CSV
        ├──► per-track JSON
        └──► web live stream + review UI
                    │
                    ▼
        [optional selective visual-language refinement]
                    │
                    ▼
        refined labels + activity reports + teacher analytics

Design principles

1. Full-video coverage

The first stage must be able to process all sampled frames of long classroom videos without collapsing under computational cost.

2. Track-centric reasoning

The system does not only care about frame-wise detections. It is organized around consistent person identities over time, which allows activity summaries, per-ID timelines, and teacher-focused analysis.

3. Selective semantics

Not all frames deserve expensive semantic interpretation. Refinement happens only where it adds value.

4. Human review is part of the design

The web interface is not an afterthought. It is part of the pipeline’s core philosophy: analysts should be able to inspect, verify, and correct outputs interactively.


Core Capabilities

Visual perception backbone

  • Ultralytics YOLO-based person detection
  • GPU-accelerated inference
  • stable track IDs via lightweight multi-object tracking
  • per-person keypoint extraction using YOLO pose

First-pass behavior understanding

The rule-based stage produces coarse but useful actions such as:

  • standing
  • sitting
  • walking
  • raising_hand
  • head_down
  • lying_on_desk
  • unknown

These labels serve as the operational backbone for all downstream analytics.

Temporal structuring

The pipeline produces identity-aware temporal summaries, not just isolated frame predictions. This makes it possible to answer questions such as:

  • what a given student was doing over time
  • when specific activities occurred
  • which students appeared most focused or most distracted
  • how teacher actions correlated with classroom response

Web-based inspection

The platform supports live and post-run analysis through a browser-based interface for:

  • current frame inspection
  • re-tagging
  • ID filtering
  • per-person behavior review
  • track summaries
  • teacher-centered analytics

Optional semantic refinement

A small number of representative crops per track can be passed to an optional VL image-to-text stage to reduce vague labels and improve semantic specificity.


Web Platform

The web application is designed as the operational control center for the pipeline.

It supports both analysis-time visualization and post-analysis review, allowing users to move from raw video to structured classroom insight within one interface.

Main workflow inside the web platform

  1. upload a classroom video or provide an absolute server path
  2. configure stride, device, and person limits
  3. launch analysis
  4. monitor live detections and identity assignments
  5. inspect per-ID behavior over time
  6. optionally run selective refinement
  7. review teacher behavior and classroom response statistics

Technology

  • FastAPI backend
  • SSE streaming for progressive frame delivery
  • browser-based control and visualization
  • structured output persistence for repeated review

Interface Modules

Each interface page is designed for a specific stage of the classroom analysis workflow.


1. Upload, Analyze & Re-Tag

This is the operational landing page of the system. It provides the entry point for the full analysis pipeline, including video ingestion, run configuration, live execution controls, and refinement triggers.

Users can:

  • upload a local classroom video
  • enter a server-side absolute path
  • configure stride, max persons, and device
  • start or stop analysis
  • launch selective refinement
  • enable Focus ID mode for isolated per-person inspection

Why this page matters

This page turns the system from a research prototype into a usable operator-facing tool. Instead of relying on command-line only workflows, it centralizes the critical controls needed for practical classroom video processing.

Main page – Upload, Startup Analysis and Overall Control

Main page – Upload, Startup Analysis and Overall Control


2. Live View

The Live View page streams the currently processed frame together with the detections recognized at that moment.

It includes:

  • current annotated frame
  • bounding boxes and ID labels
  • first-pass or refined behavior labels
  • frame index and current timestamp
  • detection cards on the right panel
  • dropdown-based re-tagging for each visible identity
  • timeline scrubbing support

This page is especially useful for:

  • debugging tracking quality
  • validating current labels
  • checking whether identity switches are happening
  • performing human-in-the-loop correction during review

Focus Mode

A particularly valuable feature is Focus ID mode, which isolates a selected identity and displays only that person’s crop and label panel. This is useful when a classroom is crowded and the analyst needs to inspect a single subject without distraction.

Real-time frame-by-frame inspection page – labeled borders, IDs, and right-side relabeling panel

Real-time frame-by-frame inspection page – labeled borders, IDs, and right-side relabeling panel

Focus Mode Page – View only a portion of the screen for a single ID.

Focus Mode Page – View only a portion of the screen for a single ID.


3. Activity Report

The Activity Report page reorganizes the raw frame-level analysis into a cleaner identity-time representation.

It allows users to:

  • switch between By ID and By Activity
  • filter by activity type
  • search refine tags
  • inspect a compact time-segment timeline for each person
  • click segment chips to inspect corresponding moments

Each ID receives a readable sequence such as:

  • 0:00–0:04 sitting, looking_at_phone
  • 0:05–0:10 sitting, working_on_computer

This makes the output much more interpretable than raw CSV rows.

Why this page matters

The Activity Report is the bridge between algorithmic output and behavioral understanding. It helps transform low-level predictions into a timeline narrative for each student or classroom participant.

Activity Report Page – Displays behavioral snippets by ID and time

Activity Report Page – Displays behavioral snippets by ID and time


4. Refine Summary

The Refine Summary page provides a macro-level view of the semantic results accumulated so far.

It highlights:

  • refined label distribution
  • track overview
  • behavior frequency composition
  • which labels dominate the classroom recording
  • which identities have richer semantic descriptions after refinement

This page is useful for quickly understanding the behavioral composition of the entire session without manually reviewing every frame.

Why this page matters

A good analytics system should not force the user to inspect raw detections only. The refine summary offers a higher-level snapshot of what the classroom looked like behaviorally, which is important for reporting, presentation, and trend discovery.

Refine Summary Page – Tag Distribution and Track Overview

Refine Summary Page – Tag Distribution and Track Overview


5. Teacher Behaviour Analysis

The Teacher Behaviour module is one of the most valuable pages in the system because it elevates the project beyond generic surveillance analytics.

This page focuses on a selected teacher track and correlates teacher-side actions with classroom-side response. It can display:

  • teacher activity timeline
  • teacher activity breakdown
  • student activity breakdown
  • student focus trend over time
  • engagement score
  • focused student list
  • distracted student list
  • correlations between teacher actions and student responses

Typical questions supported by this page include:

  • when was the teacher reading, writing, or lecturing
  • during which teacher actions did student focus rise or fall
  • which students remained most attentive across the session
  • which students were most frequently distracted

Why this page matters

This module turns the system into a classroom insight platform rather than only a detection engine. It supports educational analytics, teaching evaluation, behavioral study, and structured classroom observation.

Teacher Behavior Analysis Page – Statistics on the Correlation between Teacher Actions and Student Status

Teacher Behavior Analysis Page – Statistics on the Correlation between Teacher Actions and Student Status


Project Structure

classroom_behavior_hybrid/
  app.py             # Core single-video processing pipeline
  batch_run.py       # CLI for single and batch processing
  web_server.py      # FastAPI backend + SSE streaming
  templates/
    live_viewer.html # Browser UI
  detector.py        # YOLO detector wrapper
  tracker.py         # Lightweight IOU tracker
  pose.py            # YOLO pose wrapper
  behavior_rules.py  # Pose/motion-based first-pass action logic
  qwen_refiner.py    # Optional visual-language refinement
  draw_utils.py      # Rendering utilities
  io_utils.py        # Video / CSV / JSON utilities
  config.py          # Global configuration dataclass
  requirements.txt
  README.md
  outputs/           # Output videos and structured artifacts

Environment Setup

Recommended target environment:

  • Ubuntu 24.04
  • NVIDIA RTX 4090
  • Python 3.10
  • CUDA-capable PyTorch environment

Installation

cd /home/mmr/smart_classroom/open_model_zoo

conda create -n classroom-hybrid python=3.10 -y
conda activate classroom-hybrid

pip install -r classroom_behavior_hybrid/requirements.txt

If your machine requires a specific CUDA-enabled PyTorch build, install torch and torchvision according to the official PyTorch instructions before or after installing the remaining requirements.


Model Selection

Recommended Ultralytics models for a strong speed/quality balance on RTX 4090:

Person detection

  • yolo11n.pt — fastest option for long video
  • yolo11s.pt — stronger than nano with moderate overhead
  • yolo11m.pt — higher accuracy at higher cost

Pose estimation

  • yolo11n-pose.pt — efficient per-person keypoint extraction

Ultralytics will automatically download these model weights on first use if they are not already available locally.


Quick Start

Run the web server

cd /home/mmr/smart_classroom/open_model_zoo
conda activate classroom-hybrid

uvicorn classroom_behavior_hybrid.web_server:app --host 0.0.0.0 --port 8000

Open in browser:

http://localhost:8000

Typical browser-side workflow

  • choose a video file or provide a server path
  • click Start analysis
  • inspect detections in Live View
  • review semantic distribution in Refine Summary
  • inspect per-ID behavior in Activity Report
  • analyze classroom teaching dynamics in Teacher Behaviour

Single-Video Inference

To run the pipeline from the command line for one video:

cd /home/mmr/smart_classroom/open_model_zoo
conda activate classroom-hybrid

python -m classroom_behavior_hybrid.batch_run \
  --single_video "/home/mmr/Desktop/Видео уроки/01.10.2025 12-40о13-40/B02-R116_01_10_2025 13.42.44.mp4" \
  --device cuda:0 \
  --frame_stride 5 \
  --detector_model yolo11n.pt \
  --pose_model yolo11n-pose.pt \
  --max_persons_per_frame 20

Example outputs

The generated files are typically saved under classroom_behavior_hybrid/outputs/, including:

  • annotated video
  • frame-level CSV
  • track-level CSV
  • track-level JSON

Batch Processing

For recursive processing of a directory of classroom videos:

cd /home/mmr/smart_classroom/open_model_zoo
conda activate classroom-hybrid

python -m classroom_behavior_hybrid.batch_run \
  --input_root "/home/mmr/Desktop/Видео уроки" \
  --output_root "classroom_behavior_hybrid/outputs" \
  --device cuda:0 \
  --frame_stride 5 \
  --detector_model yolo11n.pt \
  --pose_model yolo11n-pose.pt \
  --max_persons_per_frame 20

The file discovery logic supports paths containing spaces and Cyrillic characters.


Output Schema

The structured outputs are designed for both direct inspection and downstream analytics.

Typical fields include:

  • source_video
  • frame_index
  • timestamp_sec
  • track_id
  • bbox_xmin
  • bbox_ymin
  • bbox_xmax
  • bbox_ymax
  • first_pass_action
  • first_pass_confidence
  • qwen_refined_action
  • qwen_confidence

Output types

Annotated video

Provides a visual audit trail of the full inference process.

Per-frame CSV

Suitable for low-level debugging, visualization, and temporal statistics.

Per-track CSV

Useful for track-centric reporting and aggregation.

Per-track JSON

Useful for integration into web dashboards, APIs, and later analytics pipelines.


Performance Philosophy

This project is not designed around benchmark vanity. It is designed around operational value.

Its core philosophy is:

  • do not overuse heavy multimodal inference
  • preserve identity over time
  • keep the first-stage pipeline fast and stable
  • expose the outputs in a way that humans can inspect
  • make the system extensible for real educational environments

For long classroom videos, this matters far more than maximizing complexity on paper.


Practical Use Cases

SmartClass Analytics can support:

Classroom observation

Structured review of student behaviors and teaching dynamics.

Teaching evaluation

Quantifying how teacher actions correlate with student focus and classroom response.

Educational analytics research

Exporting time-resolved structured signals for later analysis.

Human-in-the-loop annotation

Using the interface to accelerate semi-manual dataset building or correction.

Long-video surveillance understanding

Applying the system to environments where persistent identity and behavior timelines matter.


Extensibility

The current design intentionally keeps several modules replaceable.

You can later extend or replace:

  • the tracker with ByteTrack or BoT-SORT
  • the first-pass rules with a learned action head
  • the refinement stage with another image-text reasoning model
  • the analytics layer with richer scoring logic
  • the web frontend with institution-specific reporting needs

Because the pipeline is modular, it can evolve without rewriting the full system.


Roadmap

Potential next directions include:

  • stronger classroom-specific behavior taxonomy
  • better social interaction modeling
  • teacher–student interaction graphs
  • engagement scoring over longer horizons
  • automatic session reports
  • multi-camera classroom fusion
  • deployment integration into larger smart campus systems

Summary

SmartClass Analytics is a hybrid classroom behavior analysis platform built for real long-form educational video.

It combines:

  • fast GPU-based perception
  • track-aware temporal analysis
  • interpretable behavior outputs
  • interactive web review
  • optional selective semantic refinement
  • dedicated teacher behavior analytics

The result is a system that is not only technically capable, but also operationally useful for classroom understanding, educational analytics, and future smart-campus deployment.

About

Smart_Edu_Classroom

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages