Thursday, July 16, 2026

 This article explains how to integrate the two innovative techniques described in the references into DVSA API. These can materially improve both the backend fidelity of multimodal reasoning over aerial imagery and the frontend visualization and exploration of analytic results, and the path to doing so is practical and incremental: 

Begin by treating each flight and each image as a richly annotated multimodal record that pairs high quality visual evidence (bounding boxes, masks, per frame metadata) with human or agent Q&A transcripts and model provenance, then extend the training and inference pipelines to enforce faithfulness constraints during reasoning and to surface those grounded traces in an interactive, GPU accelerated visualization that treats image landmarks as navigable particles. On the backend, adopt the Faithful GRPO philosophy by converting reasoning quality metrics into verifiable constraints rather than soft rewards: instrument one’s pipeline so that every reasoning trace produced by a VLM or multimodal agent is accompanied by two verifiable signals — a logical consistency score (LLM judge) and a visual grounding score (VLM judge or IoU matching against detector outputs) — and feed those signals into a constrained RL loop that uses Lagrangian dual ascent to adaptively enforce thresholds on consistency and grounding during policy updates; this requires adding a training harness to dvsa api that supports supervised fine tuning on curated chain of thought (CoT) examples followed by RL with constraint enforcement, logging batch level constraint satisfaction and Lagrange multipliers, and normalizing advantage signals for task and constraints separately so no single signal cancels another. 

Practically, implement a modular judge service in dvsa api that can run LLM based consistency checks (prompted judges that verify entailment between chain steps and final answer) and VLM based grounding checks (IoU matching between referenced bounding boxes in the reasoning trace and detector outputs), and expose these as deterministic, testable functions so they can be used both in training and in runtime QA. Store the outputs of these judges alongside each run in the database so one can compute per model, per flight metrics and trigger retraining or human review when constraints are violated; the attached document reports that constrained training “reduces inconsistency from 26.1% to 1.7% and boosts semantic grounding scores by 13%,” which demonstrates the practical payoff of enforcing such constraints (from the attached document). To support these capabilities, extend dvsa api’s data model to include structured reasoning traces, per step bounding box references, and judge verdicts; add provenance fields (model_version, agent_id, run_id) and make them mandatory in RunOutput so every analytic claim is auditable. For grounding rewards one would need a reliable object detector producing deterministic bounding boxes and masks; integrate a production detector (or a lightweight YOLO/Detectron adapter) into the pipeline and use its outputs as the visual teacher for IoU scoring and for generating the high quality CoT training data via MCTS or other synthesis techniques described in the document. Implement a data curation pipeline that synthesizes CoT traces with explicit bounding box references (the document’s MCTS approach is a useful pattern) so one’s supervised stage has high quality, grounded examples before RL. Instrument training with metrics and automated curricula: when constraints are violated, increase the Lagrange multipliers to bias learning toward satisfying grounding and consistency, and log these dynamics so one can tune thresholds and multipliers for one’s domain.

On the visualization and UX side, adapt PhotoDance’s dual view and GPU accelerated strategies to present aerial images as collections of landmarks and to let operators fluidly explore both spatial and semantic structure. Treat each aerial image like a “photo collection” where landmarks (parking lots, buildings, trees, vehicles) are first class particles with attributes (class, confidence, timestamp, altitude, provenance). Build a faceted spatial explorer (the Galaxy View analogue) that maps these particles into multiple coordinate systems — geographic layout, semantic axes (object density, anomaly score), and temporal axes — and allow operators to reindex on the fly. Implement a Mosaic View that composes a high resolution canvas from many tiles or thumbnails so operators can zoom from a global corridor view down to pixel level evidence; use WebGL2 shaders and a dynamic GPU sprite atlas to maintain 60fps interactions even with tens of thousands of particles, and implement an LRU texture cache and request throttling so network and memory usage remain bounded during rapid pans. PhotoDance’s approach to GPS interpolation and burst collapse translates directly: when multiple sensors or devices capture overlapping frames, propagate high quality GPS from one device to adjacent frames, collapse near duplicate frames using perceptual hashing, and present a burst review mode for operators to select the best frame for annotation or training. For large datasets, precompute simplified polylines and spatial tiles for flights so the UI can prefilter candidate historical flights quickly; use spatial indexes (PostGIS or SQL Server geography) to find nearby flight corridors and then fetch detailed particle data for the selected corridor.

To connect the backend constraints and the frontend visualization, expose APIs that return not only detections but also the reasoning trace, judge verdicts, and provenance for each analytic claim; in the planner UI surface a compact digest of prior Q&A and the judge scores so operators can see whether a prior claim was consistent and visually grounded. Implement embedding based retrieval over QA transcripts to surface the most relevant prior conversations for a proposed corridor, and combine keyword matching with semantic similarity to rank prior exchanges. For flight planning, compute corridor similarity using a two stage approach: use spatial DB prefiltering (STDistance, bounding box overlap) to find candidate historical flights, then compute a more expensive polyline similarity (Frechet or Hausdorff on simplified polylines) in application code to rank matches; present aggregated analytics (common hazards, typical altitudes, detection confidence distributions) and the most relevant QA snippets with judge scores so operators can make informed decisions. Operationalize the system with background indexing jobs that compute judge scores and embeddings as flights are ingested, a cache of hot location summaries, and governance controls to redact sensitive transcripts or require human approval for automated recommendations. For evaluation, create synthetic datasets and CoT traces, run ablation studies to measure the impact of constraint thresholds on both accuracy and faithfulness, and instrument user studies to validate that the dual view visualization improves operator situational awareness and planning outcomes. By combining constrained multimodal training (Faithful GRPO style) with PhotoDance inspired GPU visualizations and careful provenance and spatial indexing, DVSA API can evolve into a system that not only produces more trustworthy, grounded analytic claims but also presents them in an interactive, scalable interface that treats each aerial image as a navigable collection of landmarks and prior human knowledge, thereby giving drone operators a practical, evidence backed “street map for the sky” to inform safer and more effective flight planning.

References:

1. Technique 1: Reasoning enhancement: Faithful GRPO: https://arxiv.org/pdf/2604.08476

2. Technique 2: Visualization enhancement: PhotoDance by Stephen Drucker: https://tinyurl.com/dvsadance 

3. Drone Video Sensing Analytics: https://github.com/ravibeta/dvsa-api 


Wednesday, July 15, 2026

 DVSA‑API can become an airspace‑aware planner by indexing past flight paths with spatial types, performing nearest‑neighbor and corridor matching around a proposed mission, and surfacing prior analytics and Q&A tied to those historical paths to inform current flight planning.  


To make this practical for drone operators, treat each recorded flight as a first‑class spatial object: store the flight’s polyline (sequence of GPS points) as a geography/geometry column in your database, persist per‑segment metadata (altitude, timestamp, sensor id, model versions used for analytics), and attach a searchable transcript or Q&A log for operator interactions and automated annotations. Using SQL Server’s geography type (or the equivalent in PostGIS) lets you run efficient nearest‑neighbor and distance queries against a candidate origin or corridor; nearest‑neighbor queries that use STDistance() and a spatial index are the canonical way to find the closest historical objects and will leverage spatial indexes when written to the recommended pattern (TOP, ORDER BY STDistance(), and a spatial index on the column). 


Implementation begins with a small schema extension. Add a flights table with columns flightid, operatorid, starttime, endtime, path geography (SRID set consistently, e.g., 4326), bbox geography (optional precomputed envelope), summary jsonb (or NVARCHAR(MAX) for structured metadata), and qalog referencing a flightqa table that stores timestamped question/answer pairs, agent ids, and model versions. Index path with a spatial index and consider a secondary index on starttime and operatorid for temporal/operator filtering. When ingesting a new flight, compute and store a simplified polyline (e.g., Douglas‑Peucker) for fast matching and a higher‑resolution polyline for replay and analytics provenance.


For matching a proposed mission, compute a candidate origin point or proposed corridor (a buffered polyline) and run a nearest‑neighbor query against flights.path.STDistance(@candidate) ordering by distance and limiting results to the top N. Use additional predicates to filter by altitude bands, time of day, or sensor type. If you need corridor similarity rather than point proximity, compute Hausdorff or Frechet‑like similarity on simplified polylines in application code and use the database to prefilter by bounding boxes and STDistance thresholds. Ensure SRIDs match to avoid NULLs from spatial methods. 


Once matches are found, enrich the planner UI or API response with aggregated analytics: common hazards observed, object‑detection summaries, typical wind/altitude behaviors, and the Q&A transcripts tied to those flights. Present provenance (which model version produced each analytic) and confidence metrics so operators can weigh historical evidence. Provide an API endpoint /planning/suggest that accepts a proposed origin and optional corridor, returns ranked historical flights with distance scores, aggregated analytics, and a compact digest of prior Q&A relevant to the corridor (use simple keyword matching plus embedding similarity over the QA text to surface the most relevant prior exchanges).


Operational extensions include background jobs to index new flights, a cache of nearest‑neighbor results for hot locations, and a privacy layer to redact or anonymize sensitive transcripts. For scale, shard or partition flight data by geographic tiles or time windows and maintain a materialized summary table of popular corridors. For testing and validation, create synthetic flight datasets and unit tests that assert nearest‑neighbor queries return expected flights and that merge logic for overlapping segments is deterministic.


By combining spatial database primitives, careful schema design, provenance‑aware analytics, and a QA index tied to flights, DVSA‑API can provide drone operators with a “street‑map for the sky” experience: contextual, evidence‑backed suggestions for routing and risk mitigation drawn from the operator’s own historical flights and conversations.

Reference: https://github.com/ravibeta/dvsa-api 

Tuesday, July 14, 2026

 This is a summary of the book titled “AI Engineering” written by “Chip Huyen” and published by O’Reilly in 2025. AI Engineering is about applications not just models. We could learn how to develop models and navigate challenges that might arise during the process, but we must also learn how to adapt a model to a specific need especially when there are choices of models available for download from those skilled at building these. Datasets are another area of emphasis because most models are as good as the data that they operate on. These are some ways in which AI engineering differs from machine learning engineering. AI models require both instructions and information. Enhancing instructions requires “prompt engineering” and enhancing information requires “retrieval-augmented generation” and “agents”. Prompt engineering is human-to-AI communication that is most effective for certain types of tasks. Retrieval-augmented generation aka RAG is primarily used for constructing contexts. Autonomous agents are more versatile. These enhancements reduce errors from “bias” and “hallucinations” which result from incomplete or inaccurate responses. 


AI engineering is a rapidly growing field that focuses on building applications on top of readily available models. Applications like ChatGPT and Google's Gemini and Midjourney require significant amounts of data and electricity to make them powerful and efficient. AI engineering has become one of the fastest-growing engineering disciplines, as demand for AI applications has increased while the barrier to entry for building AI applications has decreased. Training large language model (LLM) AIs requires huge amounts of data and computational power, and self-supervision allows models to infer how to label data based on input data. Foundation AI models, which are trained on enormous amounts of data, can handle a wide range of tasks, such as generating product descriptions or refining descriptions based on customer reviews. AI engineering involves developing applications on top of these foundation models, which are versatile and attract billions in investment. However, evaluating an AI model is challenging, and training foundation models is a complex and expensive endeavor. 


AI models are only as good as the data they were trained on. Poor data quality, such as misinformation and conspiracy theories, can lead to questionable outputs. Training data is limited in language terms, with English being the most common language. Many languages are not even included in the data, making some models more likely to have performance problems when operating in non-English languages. To choose the right foundation model, evaluate applications and determine how to measure their success. Assessing an application's effectiveness in domain-specific capability, generation capability, instruction-following capability, and cost and latency is crucial. Evaluating the moral or ethical status of an application is also important. Finally, there must be distinction between what is wanted and what is needed when assessing models. 


Prompt engineering is the process of creating instructions to achieve desired outputs from an AI model. It involves giving instructions to the model to elicit desired outputs, which can be optimized through statistics and practices like dataset curation. A good prompt should have three features: a broad description of the desired output, relevant examples, and a task to examine a specific text and extract all instances of that type of language. The amount of prompt engineering needed depends on the model's quality and robustness. Context and context length are crucial, with the space available for context length increasing dramatically in recent years. However, good prompt engineering practices are still essential for complex outputs. AI models require instructions and adequate contextual information to complete tasks. Context can be built through retrieval-augmented generation (RAG) and agents, with RAG facilitating information retrieval from independent data sources and agents enabling internet searches for relevant information. 


RAG and agentic patterns are powerful AI models that have captured the collective imagination, leading to incredible demos and products. RAG accesses relevant information from various sources, allowing for detailed and informed query responses and reducing hallucinations. Agents, or intelligent agents, are AI's ultimate aim and can perceive and interact with their environment. RAG and agent systems require prompts and vast amounts of information, sometimes overwhelming a system's memory capacity. However, models can be adapted for specific tasks or industries through additional training. Fine-tuning can enhance domain-specific capabilities and strengthen safety. Customized foundation models often require more up-front investment due to memory demands. Parameter-efficient fine-tuning (PEFT) is a popular method to optimize memory. Transfer learning is an important concept in adapting foundation models in memory-efficient ways, allowing models to learn and be customized with fewer examples, leveraging a good base model. 


A model's performance relies on its training data, and dataset engineering aims to create a customized model within budget constraints. As models become more complex, investment in data and skilled personnel is increasing. AI is becoming more data-centric, focusing on improving performance by enhancing data processing techniques and creating high-quality datasets. Quality data enhances model performance, speed, and contexts, while low-quality data increases errors and biases. Data selection should involve understanding the model's workings and working closely with model and application developers. Minimal amounts of high-quality data are better than massive amounts.


 Using DroneNLP/dataset with dvsa-api

The DroneNLP dataset provides a strong foundation for rising up the operatiors stack with safety, and forensic analysis. It is a curated collection of drone flight log messages that includes raw, cleansed, and annotated data, along with task-specific splits for problem identification and event recognition. In practical terms, this means the dataset can support models that classify whether a flight log indicates a problem, identify what kind of problem is present, detect events in a flight timeline, and label those events in a structured way. The broader DroneNLP ecosystem also includes related tools such as DFLER, a drone flight log entity recognizer for components, parameters, functions, actions, issues, and states; ADFLER, which supports automated drone flight log event recognition; and LogNexus, which extracts meaningful sentences from noisy logs. Together, these assets create a transparent data preparation and modeling pipeline that moves from raw drone logs to processed, annotated, and operationally useful intelligence.

Although the dvsa-api repository is not directly indexed here, it can reasonably be treated as a programmable interface to DVSA-related data, such as vehicle records, test outcomes, defects, incidents, and transport safety events. Under that assumption, the integration opportunity is to use dvsa-api as a controlled service or library that exposes structured safety data while DroneNLP contributes the unstructured and semi-structured intelligence extracted from drone flight logs. The result is a realistic technical foundation for connecting drone operational evidence with broader safety, inspection, and compliance records.

Cross-modal safety intelligence is the first choice for use cases. DroneNLP can identify problems, entities, anomalies, and events in flight logs, while dvsa-api can provide structured records about vehicles, defects, test outcomes, and incident histories. Combining these sources would make it possible to build richer risk and incident models than either dataset could support alone. A drone log might reveal repeated GPS drift, battery degradation, sensor anomalies, or loss-of-control events, while DVSA records might show related patterns of vehicle defects, operational failures, or inspection outcomes. When these signals are linked across time, location, operator, and asset type, they can support stronger incident reconstruction, more proactive safety management, and better compliance planning.

One could position the combined system as an operational flight planning assistant rather than merely an analytics backend. The inspiration is similar to ForeFlight in aviation, where weather, navigation, route planning, compliance checks, and pilot workflow are integrated into a single trusted environment. In the drone context, DroneNLP and dvsa-api could be combined to create a workflow-native planning layer for drone and fleet operators. Instead of using log analysis only after incidents occur, the system would use historical log intelligence, current operational data, and structured safety records to help operators plan safer and more efficient missions before takeoff.

Such a Drone Operations Planning Assistant would begin with pre-flight risk assessment. Historical DroneNLP logs could be analyzed for recurring issues such as GPS drift in particular zones, repeated battery constraints, or sensor anomalies under certain operating conditions. DVSA-api data could then contribute structured safety context, such as defect patterns, inspection histories, or location-linked operational risk. These signals could be fused into a consolidated risk score that operators can review before launching a mission. The same platform could also support route optimization by identifying critical coverage areas, accounting for log-derived constraints such as battery limits or sensor reliability, and recommending flight paths that balance coverage, safety, and mission objectives.

Continuity planning would be another important capability. DroneNLP event recognition can detect gaps, interruptions, or incomplete mission segments in prior logs, while dvsa-api or related geospatial services can help index affected locations and mission areas. The assistant could recommend re-flight segments, overlapping passes, or additional inspection coverage where prior evidence is weak. This would make the system more than a reporting tool; it would become a mission continuity layer that helps operators understand what has already been covered, where uncertainty remains, and how to complete the operational picture.

The architecture for this use case can be described as a sequence of connected layers. A data ingestion layer would collect historical and real-time DroneNLP logs together with DVSA-api records, video streams, geospatial indexes, or other operational data. An analysis layer would run DroneNLP models to extract anomalies, components, issues, and constraints, while dvsa-api services would compute or retrieve structured safety and compliance signals. A fusion layer would align log-derived constraints with geospatial and structured safety data to produce consolidated risk and coverage maps. A planning layer would use those maps to support route optimization, continuity planning, and risk-aware mission recommendations. Finally, an interface layer would present the results in operator-native language, using concepts such as coverage gaps, risk zones, mission continuity, and human-in-the-loop overrides rather than purely technical model outputs.

The underlying schema could center on a small number of reusable entities. A Drone Log Event would capture timestamp, component, anomaly type, issue type, and severity. A Video Anomaly or geospatial observation would capture frame or segment identifiers, coordinates, anomaly type, and confidence. A Risk Zone would represent a geospatial area with a risk score and a source signal, whether from logs, video, DVSA records, or a combination of sources. A Flight Plan would contain route segments, coverage score, risk score, and continuity flags. These entities would be connected through relationships that map drone events to risk zones, geospatial observations to risk zones, and flight plans to the risks and constraints they must account for. This structure would make the system extensible while preserving explainability.

A second promising direction is a forensic correlation engine for incidents. DroneNLP already has a natural forensic orientation because it can extract entities, identify events, and reconstruct timelines from messy operational logs. When paired with dvsa-api, this capability could help investigators connect drone incidents with related vehicle records, test results, defects, and safety events. The system would ingest a drone incident case, retrieve relevant DVSA records for the appropriate time, location, operator, or asset, enrich the drone logs using DFLER and event recognition models, and then apply temporal, spatial, and semantic correlation logic. Temporal alignment would identify events that occurred within relevant time windows. Spatial alignment would connect incidents or observations that occurred within proximity thresholds. Semantic alignment would use an ontology to relate differently worded but conceptually similar issues, such as a deceleration anomaly and a braking-related defect.

The forensic interface could present a combined timeline of drone events and DVSA records, an entity graph linking drones, vehicles, operators, locations, issues, and components, and an evidence summary that explains why the system believes certain events are related. This would be useful for regulators, insurers, safety teams, and operators because it would reduce the manual burden of reconstructing complex multi-asset incidents. It also creates a strong research agenda around explainable AI in safety investigations. The system should be careful not to overstate causality, however. Correlations should be presented with uncertainty, confidence levels, and supporting evidence so that investigators can make informed judgments rather than accepting automated conclusions uncritically.

The modeling approach for risk scoring could include time-series methods, survival analysis, hazard models, graph-based models, or embedding-based fusion. Drone logs could be represented as text embeddings or structured event sequences, while DVSA records could be represented as structured embeddings derived from defects, outcomes, and asset histories. A joint model could then learn patterns that predict elevated risk. This direction has clear operational value because it shifts the platform from reactive analysis to proactive safety management. It also offers a strong research angle in multi-source risk modeling and can be evaluated quantitatively using historical data. The main limitations are the need for sufficient historical data, careful handling of overfitting, and responsible communication of risk scores so that users understand uncertainty and do not treat scores as deterministic judgments.

Maintenance and compliance analytics provide another practical extension. DroneNLP can infer maintenance needs from flight logs by identifying recurring issues, affected components, and abnormal states. These signals can be compared with DVSA defect categories and inspection outcomes to build a cross-domain defect taxonomy. For example, a drone motor overheating pattern might be mapped to a broader powertrain or propulsion-related defect category, while repeated GPS or sensor issues might be mapped to reliability or control-system concerns. Once this taxonomy exists, the system could recommend maintenance actions, track whether those actions are performed, and measure whether they reduce recurrence. It could also compute maintenance effectiveness, defect recurrence patterns, and mean time between defects.

This maintenance-oriented approach would bridge drone operations with established inspection and compliance practices. It would also fit naturally into observability dashboards because the outputs are operationally meaningful: recurring defects, maintenance recommendations, compliance status, and post-intervention improvement. The principal challenge is that mapping between drone issues and DVSA-style defect categories may be partly subjective, and drone-side maintenance data may be sparse or inconsistent. Even so, the approach is valuable because it creates a practical pathway from raw log intelligence to maintenance planning and compliance improvement.

A final research-oriented direction is to use DVSA data as an external benchmark for DroneNLP models. The central question is whether DroneNLP’s event and problem labels are consistent with broader safety patterns found in structured inspection, defect, or incident records. For example, if certain regions or operators show elevated defect rates in DVSA data, researchers could examine whether DroneNLP models also detect more frequent or severe drone log issues in corresponding contexts. This would not prove causality, but it could support cross-domain consistency checks and help validate whether the models capture meaningful safety signals.

The benchmarking framework could also support robustness testing and transfer learning. Synthetic noise or domain shifts could be introduced into drone logs to evaluate how well DroneNLP models maintain performance, especially when augmented with contextual signals from DVSA records. If DVSA defect descriptions include textual data, they could also be used to pretrain or augment models for safety-related language understanding. Evaluation scripts would pull DVSA data for selected cohorts, run DroneNLP models on corresponding logs, and compute cross-domain metrics such as correlation, mutual information, or consistency between predicted problems and observed safety outcomes. This direction is especially well suited for academic publishing because it strengthens the scientific rigor of DroneNLP work and frames the integration as a broader contribution to multi-domain validation of safety NLP systems.

Among these proposals, the highest-priority path is to begin with the operational flight planning assistant because it aligns strongly with observability, inflection detection, importance sampling, and operator-facing decision support. It also creates a broad platform on which the other ideas can build. Once the planning assistant can ingest logs, retrieve structured safety data, identify risk zones, and support route or mission decisions, the same data foundation can support forensic correlation and predictive risk scoring. The forensic engine would add investigative depth, while predictive scoring would extend the system toward proactive safety management. Maintenance and compliance analytics, along with benchmarking and evaluation, can then become complementary modules or follow-on research projects.

The strategic value of this integration is that it moves dvsa-api from being a data access layer into becoming part of an operational intelligence platform. DroneNLP contributes domain-specific textual intelligence from flight logs; dvsa-api contributes structured safety, inspection, and incident context; and the combined system can support planning, investigation, prediction, maintenance, and evaluation. The strongest narrative is not simply that two datasets can be joined, but that unstructured drone operational experience can be converted into actionable safety intelligence when fused with structured regulatory and inspection data. This positions the platform as operator-empowering AI: practical, workflow-native, explainable, and grounded in real safety evidence.



Monday, July 13, 2026

 Sample code to query Qwen2.5VL-7B VLM model in chat mode


#! /usr/bin/python

# filename: vlm_scene_query.py

"""

Download an aerial image from an Azure SAS URL, extract XFIF/GPS metadata,

and query a vision-language model (e.g., Qwen2.5VL-7B VLM) to answer a

scene-level question such as estimating area based on parking spot counts.


Usage:

    export MODEL_ID="your-qwen-model-id-or-hf-repo"

    export HF_API_TOKEN="..." # if required by the model host

    python vlm_scene_query.py --sas-url "<SAS_URL>" --question "Estimate area in square meters"


Notes:

- This script uses the Hugging Face transformers pipeline as a generic interface.

  Qwen VLM may require a provider-specific SDK or a different pipeline name.

  Replace the model loading section with the provider-specific code if needed.

- The script extracts GPS EXIF if present and returns it with the model response.

"""


import os

import sys

import argparse

import tempfile

import json

import math

import logging

from typing import Optional, Dict, Any, Tuple


import requests

from PIL import Image

import exifread


# Optional: transformers pipeline for vision-language models

try:

    from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM

    HF_AVAILABLE = True

except Exception:

    HF_AVAILABLE = False


logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")

logger = logging.getLogger("vlm_scene_query")



def download_image_from_sas(sas_url: str, dest_path: str, timeout: int = 30) -> None:

    """Download an image from an Azure SAS URL to dest_path."""

    logger.info("Downloading image from SAS URL")

    resp = requests.get(sas_url, stream=True, timeout=timeout)

    resp.raise_for_status()

    with open(dest_path, "wb") as f:

        for chunk in resp.iter_content(chunk_size=8192):

            if chunk:

                f.write(chunk)

    logger.info("Downloaded image to %s", dest_path)



def extract_gps_from_exif(image_path: str) -> Dict[str, Any]:

    """Extract GPS EXIF data (if present) using exifread and return a dict."""

    logger.info("Extracting EXIF metadata")

    with open(image_path, "rb") as f:

        tags = exifread.process_file(f, details=False)

    gps = {}

    def _get(tag):

        return tags.get(tag)

    # Common EXIF GPS tags

    lat_ref = _get("GPS GPSLatitudeRef")

    lat = _get("GPS GPSLatitude")

    lon_ref = _get("GPS GPSLongitudeRef")

    lon = _get("GPS GPSLongitude")

    alt = _get("GPS GPSAltitude")

    if lat and lon and lat_ref and lon_ref:

        def _to_deg(value):

            # value is like [Rational(37,1), Rational(46,1), Rational(0,1)]

            try:

                parts = [float(x.num) / float(x.den) for x in value.values]

                deg = parts[0] + parts[1] / 60.0 + parts[2] / 3600.0

                return deg

            except Exception:

                return None

        lat_deg = _to_deg(lat)

        lon_deg = _to_deg(lon)

        if lat_deg is not None and lon_deg is not None:

            if str(lat_ref).upper().startswith("S"):

                lat_deg = -lat_deg

            if str(lon_ref).upper().startswith("W"):

                lon_deg = -lon_deg

            gps["latitude"] = lat_deg

            gps["longitude"] = lon_deg

    if alt:

        try:

            gps["altitude"] = float(alt.values[0].num) / float(alt.values[0].den)

        except Exception:

            pass

    # XFIF or other tags may be present; include raw tags for inspection

    gps["raw_tags"] = {k: str(v) for k, v in tags.items() if k.startswith("GPS")}

    return gps



def default_area_estimate_from_parking_count(parking_count: int,

                                             spot_length_m: float = 4.5,

                                             spot_width_m: float = 1.8,

                                             spacing_factor: float = 1.2) -> Tuple[float, float]:

    """

    Estimate area in square meters and square feet given a count of parking spots.

    Default sedan footprint: 4.5m x 1.8m = 8.1 m^2. spacing_factor accounts for drive lanes and spacing.

    Returns (area_m2, area_ft2).

    """

    single_spot_area = spot_length_m * spot_width_m * spacing_factor

    total_m2 = parking_count * single_spot_area

    total_ft2 = total_m2 * 10.7639

    return total_m2, total_ft2



def build_prompt_for_vlm(question: str, guidance: Optional[str] = None) -> str:

    """

    Build a clear prompt for the vision-language model. Guidance can include

    assumptions to make (e.g., sedan footprint).

    """

    base = (

        "You are given an aerial image. Answer the user's question precisely. "

        "If you need to make reasonable assumptions, state them explicitly. "

        "Return a JSON object with keys: 'answer_text', 'parking_spot_count' (int or null), "

        "'assumptions' (list of strings), and 'computed' (object with numeric fields). "

    )

    if guidance:

        base += guidance + " "

    base += "User question: " + question

    return base



def query_vlm_with_image(model_id: str, image_path: str, prompt: str, hf_token: Optional[str] = None) -> Dict[str, Any]:

    """

    Query a vision-language model with the image and prompt.

    This uses the Hugging Face pipeline interface as a generic example.

    Replace with provider-specific SDK if required by the model.

    """

    if not HF_AVAILABLE:

        raise RuntimeError("transformers not available in this environment; cannot load VLM pipeline")


    # If the model requires authentication, set the token in the environment for HF

    if hf_token:

        os.environ["HUGGINGFACEHUB_API_TOKEN"] = hf_token


    # Attempt to use a generic image-to-text pipeline. Some VLMs require custom loading.

    logger.info("Loading VLM model pipeline (model_id=%s)", model_id)

    try:

        # Many VLMs use a "vision-text" or "image-to-text" pipeline; this is a best-effort example.

        vlm = pipeline(task="image-to-text", model=model_id, device=0 if torch_cuda_available() else -1)

    except Exception:

        # Fallback: try seq2seq with processor + model (provider-specific)

        # Provide a helpful error message to the user

        raise RuntimeError(

            "Failed to instantiate a generic image-to-text pipeline for model_id=%s. "

            "Qwen VLMs often require provider-specific SDKs or a custom pipeline. "

            "Replace this function with the provider's recommended loading code." % model_id

        )


    logger.info("Running VLM inference")

    # Many pipelines accept a list of images and optional prompt; adapt as needed

    with open(image_path, "rb") as f:

        image_bytes = f.read()

    # The pipeline may accept a PIL Image or bytes; try PIL first

    pil_img = Image.open(image_path).convert("RGB")

    # Some pipelines accept a 'prompt' kwarg; others require concatenating prompt to input.

    try:

        result = vlm(pil_img, prompt=prompt, max_new_tokens=512)

    except TypeError:

        # If pipeline doesn't accept prompt kwarg, pass prompt as first argument

        result = vlm(prompt + "\n", pil_img, max_new_tokens=512)

    # result is often a list of dicts or a string

    logger.debug("Raw VLM result: %s", result)

    # Normalize to dict

    if isinstance(result, list) and len(result) > 0:

        raw_text = result[0].get("generated_text") or result[0].get("text") or str(result[0])

    elif isinstance(result, dict):

        raw_text = result.get("generated_text") or result.get("text") or json.dumps(result)

    else:

        raw_text = str(result)

    # Try to parse JSON from the model output; if not JSON, return text in answer_text

    try:

        parsed = json.loads(raw_text)

        return parsed

    except Exception:

        return {"answer_text": raw_text, "raw": raw_text}



def torch_cuda_available() -> bool:

    try:

        import torch

        return torch.cuda.is_available()

    except Exception:

        return False



def parse_parking_count_from_vlm_response(vlm_resp: Dict[str, Any]) -> Optional[int]:

    """

    Extract parking_spot_count if present in the VLM response dict.

    """

    try:

        count = vlm_resp.get("parking_spot_count")

        if count is None:

            # Try to parse from answer_text heuristically

            text = vlm_resp.get("answer_text", "")

            # naive heuristic: find first integer in text

            import re

            m = re.search(r"\b(\d{1,4})\b", text)

            if m:

                return int(m.group(1))

            return None

        return int(count)

    except Exception:

        return None



def main():

    parser = argparse.ArgumentParser(description="Query a VLM about an aerial image from an Azure SAS URL")

    parser.add_argument("--sas-url", required=True, help="Azure SAS URL to the JPEG image")

    parser.add_argument("--question", required=True, help="Natural language question to ask the VLM")

    parser.add_argument("--model-id", default=os.environ.get("MODEL_ID", "Qwen/Qwen-2.5V-L-7B"), help="VLM model id or repo")

    parser.add_argument("--hf-token", default=os.environ.get("HF_API_TOKEN"), help="Hugging Face API token if required")

    parser.add_argument("--assume-spot-length-m", type=float, default=4.5, help="Assumed parking spot length in meters")

    parser.add_argument("--assume-spot-width-m", type=float, default=1.8, help="Assumed parking spot width in meters")

    parser.add_argument("--spacing-factor", type=float, default=1.2, help="Factor to account for drive lanes and spacing")

    parser.add_argument("--no-vlm", action="store_true", help="Skip VLM and use deterministic heuristic only")

    args = parser.parse_args()


    with tempfile.TemporaryDirectory() as tmpdir:

        img_path = os.path.join(tmpdir, "scene.jpg")

        try:

            download_image_from_sas(args.sas_url, img_path)

        except Exception as e:

            logger.error("Failed to download image: %s", e)

            sys.exit(1)


        gps = extract_gps_from_exif(img_path)

        logger.info("Extracted GPS metadata: %s", gps)


        # Build prompt

        guidance = (

            f"Assume a typical U.S. sedan footprint of {args.assume_spot_length_m}m x {args.assume_spot_width_m}m "

            f"and a spacing factor of {args.spacing_factor} to account for drive lanes. "

            "Count visible parking spots if possible and compute total area in square meters and square feet."

        )

        prompt = build_prompt_for_vlm(args.question, guidance=guidance)


        vlm_response = None

        parking_count = None

        if not args.no_vlm:

            try:

                vlm_response = query_vlm_with_image(args.model_id, img_path, prompt, hf_token=args.hf_token)

                logger.info("VLM response received")

                parking_count = parse_parking_count_from_vlm_response(vlm_response)

            except Exception as e:

                logger.warning("VLM query failed or not available: %s", e)

                vlm_response = {"error": str(e)}

                parking_count = None


        # If VLM didn't provide a parking count, fall back to asking user assumption or using a heuristic

        if parking_count is None:

            # Heuristic fallback: try to detect cars using a very small, dependency-free heuristic is not reliable.

            # Instead, we will ask the model's textual output for a number if available; otherwise, default to 10 spots.

            if vlm_response and isinstance(vlm_response, dict):

                parking_count = parse_parking_count_from_vlm_response(vlm_response)

            if parking_count is None:

                logger.info("No parking count from VLM; using fallback default of 10 spots for estimation")

                parking_count = 10 # conservative default; in production, prefer human-in-the-loop


        area_m2, area_ft2 = default_area_estimate_from_parking_count(

            parking_count,

            spot_length_m=args.assume_spot_length_m,

            spot_width_m=args.assume_spot_width_m,

            spacing_factor=args.spacing_factor

        )


        # Build final structured response

        response = {

            "run_id": f"run-{os.urandom(6).hex()}",

            "agent_id": "qwen-vlm-estimator",

            "start_time": None,

            "end_time": None,

            "model_version": args.model_id,

            "gps": gps,

            "question": args.question,

            "vlm_raw_response": vlm_response,

            "parking_spot_count_used": parking_count,

            "assumptions": [

                f"sedan footprint {args.assume_spot_length_m}m x {args.assume_spot_width_m}m",

                f"spacing factor {args.spacing_factor}"

            ],

            "computed": {

                "area_m2": round(area_m2, 2),

                "area_ft2": round(area_ft2, 2),

                "spot_area_m2": round(args.assume_spot_length_m * args.assume_spot_width_m * args.spacing_factor, 2)

            },

            "answer_text": (

                f"Estimated total area ≈ {round(area_m2,2)} m² ({round(area_ft2,2)} ft²) "

                f"based on {parking_count} parking spots and assumed sedan footprint "

                f"{args.assume_spot_length_m}m x {args.assume_spot_width_m}m with spacing factor {args.spacing_factor}."

            )

        }


        # Print JSON response

        print(json.dumps(response, indent=2))



if __name__ == "__main__":

    main()


"""

Sample output:

 python Qwen.py --sas-url "https://tinyurl.com/carlot01" --question "what is the size of the parking lot shown in terms of square feet assuming usual size of a sedan in the united states and counting at most 1 occupancy per parking spot" --hf-token "<your-token>"

2026-07-12 19:16:35,444 INFO Downloading image from SAS URL

2026-07-12 19:16:36,468 INFO Downloaded image to C:\Users\ravib\AppData\Local\Temp\tmp6sle4o5d\scene.jpg

2026-07-12 19:16:36,470 INFO Extracting EXIF metadata

2026-07-12 19:16:36,491 INFO Extracted GPS metadata: {'raw_tags': {}}

2026-07-12 19:16:36,492 INFO Loading VLM model pipeline (model_id=Qwen/Qwen-2.5V-L-7B)

2026-07-12 19:16:37,065 INFO HTTP Request: GET https://huggingface.co/api/agent-harnesses "HTTP/1.1 200 OK"

2026-07-12 19:16:37,176 INFO HTTP Request: HEAD https://huggingface.co/Qwen/Qwen-2.5V-L-7B/resolve/main/config.json "HTTP/1.1 401 Unauthorized"

2026-07-12 19:16:37,178 WARNING VLM query failed or not available: Failed to instantiate a generic image-to-text pipeline for model_id=Qwen/Qwen-2.5V-L-7B. Qwen VLMs often require provider-specific SDKs or a custom pipeline. Replace this function with the provider's recommended loading code.

2026-07-12 19:16:37,179 INFO No parking count from VLM; using fallback default of 10 spots for estimation

{

  "run_id": "run-70391241b7e3",

  "agent_id": "qwen-vlm-estimator",

  "start_time": null,

  "end_time": null,

  "model_version": "Qwen/Qwen-2.5V-L-7B",

  "gps": {

    "raw_tags": {}

  },

  "question": "what is the size of the parking lot shown in terms of square feet assuming usual size of a sedan in the united states and counting at most 1 occupancy per parking spot",

  "vlm_raw_response": {

    "error": "Failed to instantiate a generic image-to-text pipeline for model_id=Qwen/Qwen-2.5V-L-7B. Qwen VLMs often require provider-specific SDKs or a custom pipeline. Replace this function with the provider's recommended loading code."

  },

  "parking_spot_count_used": 10,

  "assumptions": [

    "sedan footprint 4.5m x 1.8m",

    "spacing factor 1.2"

  ],

  "computed": {

    "area_m2": 97.2,

    "area_ft2": 1046.25,

    "spot_area_m2": 9.72

  },

  "answer_text": "Estimated total area \u2248 97.2 m\u00b2 (1046.25 ft\u00b2) based on 10 parking spots and assumed sedan footprint 4.5m x 1.8m with spacing factor 1.2."

}

"""


 


Sunday, July 12, 2026

 Generative Artificial Intelligence and the Importance of Data

Generative artificial intelligence is one of the most important developments in modern technology because it changes what computers can do. Traditional artificial intelligence usually focuses on recognizing patterns, classifying information, or predicting outcomes. Generative artificial intelligence goes further by creating new content, such as text, images, computer code, audio, and summaries. This shift from prediction to creation gives people and organizations new ways to solve problems, communicate ideas, and make work more efficient.

Large language models are a major part of this change. These models are trained on enormous amounts of text so they can understand language patterns and produce responses that sound natural. They can answer questions, translate languages, summarize long documents, write first drafts, assist with coding, and help people search for information. Some models are general-purpose, meaning they can help with many different kinds of tasks. Others are designed for a specific subject or job, such as medicine, law, cybersecurity, research, or software development. The most useful model depends on the problem being solved, the kind of data available, and the level of accuracy, speed, and cost required.

Data is the foundation of successful artificial intelligence projects. A model is only as useful as the information it can learn from or retrieve. Pu¹blic information can help a model understand language and general knowledge, but many real-world tasks require private, specialized, or up-to-date information. Organizations often have valuable data stored in documents, databases, emails, images, audio files, and other sources. To make generative artificial intelligence more accurate and useful, that information needs to be organized, protected, and made available in responsible ways.

There are several ways to adapt language models for particular needs. Prompt engineering means writing clear instructions so the model produces a better answer. In-context learning gives the model helpful background information during a task. Retrieval-augmented generation allows a system to search trusted information sources and bring relevant facts into the model’s response. Fine-tuning changes a pretrained model so it performs better for a specific subject or task. Human feedback can also be used to guide a model toward more helpful, honest, and safe responses. These techniques show that artificial intelligence is not simply a tool that works automatically; it must be carefully guided and improved.

Generative artificial intelligence applications require strong technical support. Data pipelines are needed to collect, clean, organize, and deliver information to models. Vector representations help computers compare meaning rather than only matching exact words, which makes search and retrieval faster and more useful. Specialized hardware can speed up training and inference, especially for large models. User interfaces, such as web apps, chat windows, mobile apps, and developer tools, make these systems easier for people to use. In production settings, teams must also think about latency, cost, scalability, and how different systems will connect to each other.

Security, governance, and ethics are just as important as technical performance. Generative artificial intelligence systems may handle sensitive information, so organizations need clear rules about who can access data, how data is stored, and how it is used. There are also risks involving bias, privacy, misinformation, hallucinations, and copyright. A model can produce incorrect information with confidence, repeat unfair patterns found in training data, or create content that raises legal and ethical concerns. Because of these risks, human oversight, regular monitoring, careful data management, and responsible policies are necessary.

This is a practical path for using generative artificial intelligence successfully. Organizations should begin by identifying meaningful problems rather than adopting the technology just because it is popular. They should build a strong data foundation, choose appropriate models, encourage collaboration among technical and nontechnical workers, and measure results over time. Starting small, learning from experiments, and sharing best practices can help people use these tools wisely. Overall, the main message is that generative artificial intelligence can be powerful, but its value depends on high-quality data, thoughtful design, secure systems, and responsible human judgment.


 Nine Ten Drones has built its reputation on helping organizations unlock the promise of UAVs through training, consulting, and operational deployment. Yet as the industry shifts from experimentation to scaled autonomy, the next frontier is not simply flying drones—it’s making sense of the data they capture in real time. This is where our drone vision analytics, can transform Nine Ten Drones’ mission from enabling flight to enabling intelligence.

Nine Ten Drones is about empowering operators to use UAVs safely and effectively across industries like public safety, infrastructure, and agriculture. A contextual DVSA adds a new dimension: it becomes the bridge between raw aerial footage and actionable insight. By fusing centimeter-level geolocation from networks like GEODNET with semantic video analytics, the DVSA can annotate every frame with meaning. A drone surveying a highway isn’t just recording asphalt—it’s identifying lane markings, traffic density, and potential hazards. A drone flying over farmland isn’t just capturing crops—it detects stress zones, irrigation anomalies, and pest activity. For Nine Ten Drones’ clients, this means training programs and operational workflows can evolve from “how to fly” into “how to interpret and act.”

The synergy with Nine Ten Drones’ consulting practice is particularly powerful. Their teams already advise municipalities, utilities, and enterprises on how to integrate UAVs into daily operations. With a contextual DVSA, those recommendations can be backed by live, annotated datasets. A police department could review drone footage not just for situational awareness but for automated detection of crowd movement patterns. A utility company could receive alerts when vegetation encroaches on power lines, flagged directly in the video stream. The DVSA becomes a trusted assistant, guiding operators toward decisions that are faster, safer, and more defensible.

Training is another area where the DVSA amplifies Nine Ten Drones’ impact. Instead of teaching students to interpret raw imagery, instructors can use the DVSA to demonstrate how analytics enrich the picture. A trainee flying a mission over a construction site could see real-time overlays of equipment usage, safety compliance, or material stockpiles. This accelerates learning curves and prepares operators for data-driven workflows that modern autonomy demands. It also positions Nine Ten Drones as not just a training provider but a gateway to advanced geospatial intelligence.

Operationally, the contextual DVSA enhances resilience. Nine Ten Drones emphasizes safe, repeatable missions, but GNSS signals and coverage can be inconsistent. By combining GEODNET’s decentralized RTK corrections with our analytics, the DVSA can validate positional accuracy against visual cues, flagging anomalies when signals drift. This feedback loop strengthens trust in the data, ensuring that every mission produces results that are both precise and reliable. For industries like emergency response or environmental monitoring, reliability is not optional—it’s mission-critical.

Most importantly, the DVSA aligns with Nine Ten Drones’ philosophy of democratizing UAV adoption. Their vision is to make drones accessible to organizations that may lack deep technical expertise. A contextual DVSA embodies that ethos by lowering the barrier to insight. Operators don’t need to be data scientists to benefit from semantic overlays, predictive alerts, or geospatial indexing. They simply fly their missions, and the DVSA translates video into meaning. This accessibility expands use cases—from small-town public works departments to large-scale agricultural cooperatives—without requiring specialized analytics teams.

Nine Ten Drones equips people to fly drones; our contextual DVSA equips those drones to think. Together, they create an ecosystem where UAVs are not just airborne cameras but intelligent agents of autonomy. The result is a future where every mission—whether for safety, infrastructure, or agriculture—produces not just imagery but insight, not just data but decisions. And that is how Nine Ten Drones, with the help of our analytics, can lead the industry into the autonomy era.