Fire and Smoke Detection

Property Value
Category Vision-Language Alerting (Fire & Smoke / Safety)
Base Model Qwen3.5-2B (Alibaba, Apache-2.0)
Source Framework PyTorch (Transformers)
Supported Precisions INT4
Inference Engine OpenVINO GenAI
Hardware CPU, GPU
Detected Class(es) fire, smoke (via natural-language prompt)

Overview

Supported devices are CPU and GPU only; NPU is not supported.

Fire and Smoke Detection is a Metro Analytics use case that detects open flames and smoke plumes in images and video streams and raises an on-screen alert whenever fire or smoke is present. The samples use Qwen3.5-2B INT4, a pre-quantized vision-language model (VLM) that runs locally through OpenVINO GenAI. This prompt-based demo is not a substitute for certified fire detection or emergency alerting.

The VLM answers the prompt "Is there fire or smoke in this image?" Both samples overlay the answer and show NO MODEL DECISION when a response is not available or does not match the expected yes/no format.

Because the model is a general vision-language model, the same use case can be re-targeted to related hazards (for example steam, sparks, or heavy haze) simply by editing the prompt -- no retraining is required.

Typical Metro deployments include:

  • Depot and Tunnel Safety -- raise an early alarm when open flame or smoke appears in a rail depot, tunnel, or maintenance bay.
  • Trackside Vegetation Fires -- detect brush and wildfire near the right of way before it spreads to infrastructure.
  • Facility Fire Watch -- continuous monitoring of substations, storage yards, and platforms for ignition and smoke events.
  • Automated Incident Escalation -- trigger alerts and video capture the moment a fire or smoke detection is confirmed.

Prerequisites

See the released runtime setup and device support matrix before choosing a runtime. Use standalone OpenVINO 2026.4.1 with GenAI and Tokenizers 2026.4.1.0, or native DLStreamer 2026.2.0 linked to that OpenVINO and GenAI stack. The official DLStreamer 2026.2.0 image bundles older libraries and is not supported for this model.

  • Python 3.11+
  • FFmpeg (used to transcode the sample video for the DLStreamer pipeline)

Create and activate a Python virtual environment before running the scripts:

python3 -m venv .venv --system-site-packages
source .venv/bin/activate

Note: The --system-site-packages flag is required so the virtual environment can access the system-installed OpenVINO and DLStreamer Python packages.


Getting Started

Download and Quantize Model

Run the script to download the pre-quantized Qwen3.5-2B OpenVINO IR and sample wildfire clip:

wget https://huggingface.co/Intel/fire-and-smoke-detection/resolve/main/export_and_quantize.sh
chmod +x export_and_quantize.sh
./export_and_quantize.sh

The script accepts only INT4 (the default) and does not export weights, quantize locally, or install a runtime.

Output files:

  • qwen3_5_2b_int4_ov/ -- Pre-quantized OpenVINO model and tokenizer files.
  • test_video.mp4 -- transcoded sample clip.

OpenVINO Sample

The sample below runs Qwen3.5-2B INT4 on the sample video with OpenVINO GenAI. To keep inference responsive, one frame is sampled every FRAME_STRIDE frames and sent to the VLM with a short fire/smoke prompt; the yes/no answer is held between samples and overlaid as an alert banner across the top of each frame -- no bounding boxes are drawn. The annotated result is written to output_openvino.mp4. Change the DEVICE string to run on CPU or GPU.

The full sample is in openvino_sample.py; run it with python3 openvino_sample.py or copy the code below.

# SPDX-License-Identifier: MIT
# Copyright (C) Intel Corporation
#
# Fire and Smoke Detection: OpenVINO Runtime sample.
# See README.md for prerequisites and inputs. Run: python3 openvino_sample.py

import cv2
import numpy as np
import openvino as ov
import openvino_genai

# Change DEVICE to "GPU" to run on integrated GPU.
DEVICE = "CPU"
MODEL_DIR = "qwen3_5_2b_int4_ov"
PROMPT = (
    "Is there fire or smoke in this image? "
    "Answer with a single word: yes or no."
)
# Run the VLM every FRAME_STRIDE frames; the alert is held between inferences.
FRAME_STRIDE = 15

properties = {}
if DEVICE == "GPU":
    properties["CACHE_DIR"] = "vlm_cache"
pipe = openvino_genai.VLMPipeline(MODEL_DIR, DEVICE, **properties)

config = openvino_genai.GenerationConfig()
config.max_new_tokens = 8

cap = cv2.VideoCapture("test_video.mp4")
fps = cap.get(cv2.CAP_PROP_FPS) or 30.0
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
writer = cv2.VideoWriter(
    "output_openvino.mp4", cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height)
)


def ask_vlm(frame_bgr: np.ndarray) -> bool | None:
    """Return None if the VLM does not provide a yes/no answer."""
    rgb = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
    image = ov.Tensor(np.ascontiguousarray(rgb))
    result = pipe.generate(PROMPT, images=[image], generation_config=config)
    answer = str(result).strip().lower().rstrip(".!")
    if answer not in {"yes", "no"}:
        print(f"Unexpected fire/smoke response: {str(result)!r}", flush=True)
        return None
    return answer == "yes"


frame_idx = 0
detected = False
while True:
    ok, frame = cap.read()
    if not ok:
        break
    frame_idx += 1

    if (frame_idx - 1) % FRAME_STRIDE == 0:
        detected = ask_vlm(frame)

    if detected is None:
        text = "NO MODEL DECISION"
        color = (0, 165, 255)
    elif detected:
        text = "FIRE / SMOKE DETECTED"
        color = (0, 0, 255)  # red alert
    else:
        text = "NO FIRE / SMOKE"
        color = (0, 180, 0)  # green

    # Draw the alert banner across the top of the frame (no bounding boxes).
    cv2.rectangle(frame, (0, 0), (width, 60), (0, 0, 0), -1)
    cv2.putText(frame, text, (20, 42),
                cv2.FONT_HERSHEY_SIMPLEX, 1.2, color, 3)

    if frame_idx % 30 == 0:
        print(f"frame {frame_idx}: {text}", flush=True)

    writer.write(frame)

cap.release()
writer.release()
print("Saved: output_openvino.mp4")

Device targets:

  • "CPU" -- default, works on all Intel platforms.
  • "GPU" -- Intel integrated or discrete GPU.

Try It on a Sample Video

The export_and_quantize.sh script downloads and transcodes test_video.mp4 automatically. Re-run the OpenVINO sample above. The script reads test_video.mp4, prints a periodic alert status to the console, and writes the annotated video to output_openvino.mp4.

Expected console output (representative):

frame 30: FIRE / SMOKE DETECTED
frame 60: FIRE / SMOKE DETECTED
frame 90: FIRE / SMOKE DETECTED

Expected Output

OpenVINO expected output showing a FIRE / SMOKE DETECTED alert banner across the top of a wildfire frame

DLStreamer Sample

The pipeline below runs the same Qwen3.5-2B INT4 model on the sample video via the DLStreamer 2026 gvagenai element, which performs vision-language inference through OpenVINO GenAI. Frames are decoded, grouped into short chunks, and summarized by the VLM using a fire/smoke prompt; gvagenai attaches the answer to the buffer as JSON metadata. Frames are pulled through an appsink; for each frame a callback reads the latest VLM answer and, instead of drawing bounding boxes, overlays an alert banner across the top of the frame reporting whether fire or smoke is detected. The annotated result is written to output_dlstreamer.mp4.

Notes on running this sample:

  • Use the OpenVINO model directory produced by export_and_quantize.sh (qwen3_5_2b_int4_ov); gvagenai reads it via its model-path property.

  • gvagenai requires an RGB input, so the decode chain converts to RGB before inference; the appsink then converts back to BGR and the banner is drawn with OpenCV, so no additional GStreamer overlay plugin is required.

  • frame-rate controls how many frames per second are sampled for the VLM and chunk-size how many sampled frames form one inference call; keep both small to stay responsive on Core Ultra.

  • The VLM answer is attached to the buffer as a GstGVAJSONMeta message and read in Python with gstgva.VideoFrame(buffer).messages().

  • Export PYTHONPATH so the DLStreamer Python modules (gi, gstgva) are importable:

    source /opt/intel/openvino_2026/setupvars.sh
    source /opt/intel/dlstreamer/scripts/setup_dls_env.sh
    export PYTHONPATH=/opt/intel/dlstreamer/python:\
    /opt/intel/dlstreamer/gstreamer/lib/python3/dist-packages:${PYTHONPATH:-}
    

The full sample is in dlstreamer_sample.py; run it with python3 dlstreamer_sample.py or copy the code below.

# SPDX-License-Identifier: MIT
# Copyright (C) Intel Corporation
#
# Fire and Smoke Detection: DLStreamer pipeline sample.
# See README.md for prerequisites and inputs. Run: python3 dlstreamer_sample.py

import json

import gi

gi.require_version("Gst", "1.0")
from gi.repository import Gst

Gst.init([])

# Import cv2 and gstgva after Gst.init to avoid a re-initialization conflict.
import cv2
import numpy as np
from gstgva import VideoFrame

MODEL_DIR = "qwen3_5_2b_int4_ov"
INPUT_VIDEO = "test_video.mp4"
PROMPT = "Is there fire or smoke in this image? Answer with a single word: yes or no."

# For CPU: change device=GPU to device=CPU.
# Supported devices: CPU and GPU only.
pipeline_str = (
    f"filesrc location={INPUT_VIDEO} ! decodebin3 ! "
    f"videoconvert ! video/x-raw,format=RGB ! "
    f"gvagenai name=genai model-path={MODEL_DIR} device=GPU "
    f'prompt="{PROMPT}" generation-config="max_new_tokens=8" '
    f"frame-rate=2 chunk-size=2 ! queue ! "
    f"videoconvert ! video/x-raw,format=BGR ! "
    f"appsink name=sink emit-signals=true sync=false max-buffers=4 drop=false"
)
pipeline = Gst.parse_launch(pipeline_str)
appsink = pipeline.get_by_name("sink")

state = {"writer": None, "frame": 0, "detected": None}


def on_sample(sink):
    sample = sink.emit("pull-sample")
    if sample is None:
        return Gst.FlowReturn.OK

    buf = sample.get_buffer()
    caps = sample.get_caps().get_structure(0)
    width = caps.get_value("width")
    height = caps.get_value("height")

    # Read the latest VLM answer from the gvagenai JSON metadata (if present).
    for message in VideoFrame(buf).messages():
        try:
            answer = str(json.loads(message).get("result", "")).strip().lower().rstrip(".!")
        except (ValueError, TypeError):
            continue
        if answer in {"yes", "no"}:
            state["detected"] = answer == "yes"
        elif answer:
            print(f"Unexpected fire/smoke response: {answer!r}", flush=True)
            state["detected"] = None

    ok, mapinfo = buf.map(Gst.MapFlags.READ)
    if not ok:
        return Gst.FlowReturn.OK
    frame = np.frombuffer(mapinfo.data, np.uint8).reshape(height, width, 3).copy()
    buf.unmap(mapinfo)

    if state["detected"] is None:
        text = "NO MODEL DECISION"
        color = (0, 165, 255)
    elif state["detected"]:
        text = "FIRE / SMOKE DETECTED"
        color = (0, 0, 255)  # red alert
    else:
        text = "NO FIRE / SMOKE"
        color = (0, 180, 0)  # green

    # Draw the alert banner across the top of the frame (no bounding boxes).
    cv2.rectangle(frame, (0, 0), (width, 60), (0, 0, 0), -1)
    cv2.putText(frame, text, (20, 42),
                cv2.FONT_HERSHEY_SIMPLEX, 1.2, color, 3)

    if state["writer"] is None:
        state["writer"] = cv2.VideoWriter(
            "output_dlstreamer.mp4",
            cv2.VideoWriter_fourcc(*"mp4v"), 30.0, (width, height),
        )
    state["writer"].write(frame)

    state["frame"] += 1
    if state["frame"] % 30 == 0:
        print(f"frame {state['frame']}: {text}", flush=True)
    return Gst.FlowReturn.OK


appsink.connect("new-sample", on_sample)

pipeline.set_state(Gst.State.PLAYING)
bus = pipeline.get_bus()
bus.timed_pop_filtered(
    Gst.CLOCK_TIME_NONE,
    Gst.MessageType.EOS | Gst.MessageType.ERROR,
)
pipeline.set_state(Gst.State.NULL)

if state["writer"] is not None:
    state["writer"].release()
print("Saved: output_dlstreamer.mp4")

Try It on a Sample Video

The export_and_quantize.sh script downloads and transcodes test_video.mp4 automatically. Run the DLStreamer sample above. The callback prints a periodic alert status and writes the annotated video.

Expected console output (representative):

frame 30: FIRE / SMOKE DETECTED
frame 60: FIRE / SMOKE DETECTED
frame 90: FIRE / SMOKE DETECTED

The annotated video is saved to output_dlstreamer.mp4 with the alert banner drawn across the top by OpenCV -- no bounding boxes are drawn.

Expected Output

DLStreamer expected output showing a fire and smoke alert banner across the top of an aerial wildfire video

Device targets:

  • device=GPU -- default in the sample code.
  • device=CPU -- change device=GPU to device=CPU.

License

Licensed under the MIT License. See LICENSE for details.

References

Downloads last month
125
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Collection including Intel/fire-and-smoke-detection