Steg 9 (R4): unified migrate-corpus.mjs --write over engineering/governance/ infrastructure/security. 327 filer mutert, verified=null, prosa byte-identisk (fra første ## seksjon), advisor urørt (0 endringer). To applier-fixes oppdaget under kjøring (TDD, RED→GREEN): - insertHeaderFields: anker faller nå tilbake når en meta-linje selv passerer 500B (2 filer pakket et avsnitt i **Status:** → Type/Source landet utenfor scan-vinduet, applierens post-write-assertion fanget + restaurerte). - normalizeStaleVerified: fjerner nå ALLE stale non-date **Verified:** i 500B-vinduet, inkl. stray body-dup rett under --- (9 mlops-genaiops-filer var ellers falskt "verified"/fresh, droppet fra worklist). Operatør-godkjent utvidelse av carve-out; kun stray metadata-linjer, aldri prosa. test-transform-criterion: precondition oppdatert til post-migrasjons-sannhet (fila bærer nå Source). Suite 728/728 grønn.
363 lines
13 KiB
Markdown
363 lines
13 KiB
Markdown
# Image Classification and Understanding
|
|
|
|
**Last updated:** 2026-02
|
|
**Status:** GA
|
|
**Category:** Multi-Modal AI
|
|
**Type:** reference
|
|
|
|
---
|
|
|
|
## Innhold
|
|
|
|
- [Introduksjon](#introduksjon)
|
|
- [Kjernekomponentar](#kjernekomponentar)
|
|
- [Pre-trained Model Selection](#pre-trained-model-selection)
|
|
- [Custom Model Training og Evaluation](#custom-model-training-og-evaluation)
|
|
- [Confidence og Uncertainty Quantification](#confidence-og-uncertainty-quantification)
|
|
- [Real-time og Batch Processing](#real-time-og-batch-processing)
|
|
- [Norsk offentleg sektor](#norsk-offentleg-sektor)
|
|
- [Beslutningsrammeverk](#beslutningsrammeverk)
|
|
- [For Cosmo](#for-cosmo)
|
|
|
|
## Introduksjon
|
|
|
|
Bildeklassifisering og -forståing i Microsoft-stakken spenner frå tradisjonelle computer vision-modellar til moderne multimodale LLM-ar. Azure AI Vision 4.0, bygd på Florence foundation-modellen, tilbyr automatisk tagging, captioning, objektdeteksjon og OCR i ein samla API. For scenario som krev tilpassa kategoriar, finst Custom Vision (planlagd pensjonering 2028), Azure Machine Learning AutoML og Azure Content Understanding.
|
|
|
|
GPT-4o og GPT-4o mini representerer den nyaste tilnærminga: generelle multimodale modellar som kan svare på spørsmål om bildeinnhald, klassifisere bilete, og utføre visuelle resonnement utan dedikert modelltrening. Denne tilnærminga er spesielt verdifull for offentleg sektor, der nye klassifiseringsbehov oppstår hyppig og treningsdata ofte er avgrensa.
|
|
|
|
For produksjonssystem anbefalar Microsoft ein hybrid tilnærming: bruk Azure AI Vision 4.0 for standardiserte oppgåver (tagging, OCR, persondeteksjon) og GPT-4o for komplekse, kontekstavhengige klassifiseringar der naturleg språk-instruksjonar erstattar tradisjonell modelltrening.
|
|
|
|
---
|
|
|
|
## Kjernekomponentar
|
|
|
|
| Komponent | Formål | Teknologi |
|
|
|-----------|--------|-----------|
|
|
| Azure AI Vision 4.0 | Generell bildeanalyse (tags, captions, objects) | Florence foundation model |
|
|
| Image Analysis API | REST/SDK for caption, tags, objects, people, OCR | Azure AI Vision |
|
|
| Custom Vision | Tilpassa klassifisering/objektdeteksjon | Custom Vision Service (legacy) |
|
|
| Azure ML AutoML | Custom image classification med AutoML | Azure Machine Learning |
|
|
| Content Understanding | Generativ AI-basert bildeklassifisering | Microsoft Foundry (preview) |
|
|
| GPT-4o Vision | Fleksibel bildeklassifisering via chat | Azure OpenAI Service |
|
|
| Multimodal Embeddings | Bilde-tekst-likskap for retrieval | Azure AI Vision 4.0 |
|
|
|
|
---
|
|
|
|
## Pre-trained Model Selection
|
|
|
|
### Azure AI Vision 4.0 Features
|
|
|
|
```python
|
|
import os
|
|
from azure.ai.vision.imageanalysis import ImageAnalysisClient
|
|
from azure.ai.vision.imageanalysis.models import VisualFeatures
|
|
from azure.core.credentials import AzureKeyCredential
|
|
|
|
client = ImageAnalysisClient(
|
|
endpoint=os.environ["VISION_ENDPOINT"],
|
|
credential=AzureKeyCredential(os.environ["VISION_KEY"])
|
|
)
|
|
|
|
# Analyser bilete med alle tilgjengelege features
|
|
result = client.analyze_from_url(
|
|
image_url="https://example.com/road-damage.jpg",
|
|
visual_features=[
|
|
VisualFeatures.CAPTION,
|
|
VisualFeatures.DENSE_CAPTIONS,
|
|
VisualFeatures.TAGS,
|
|
VisualFeatures.OBJECTS,
|
|
VisualFeatures.PEOPLE,
|
|
VisualFeatures.READ,
|
|
VisualFeatures.SMART_CROPS
|
|
],
|
|
gender_neutral_caption=True
|
|
)
|
|
|
|
# Caption — eitt setning som skildrar heile biletet
|
|
print(f"Caption: {result.caption.text} "
|
|
f"(confidence: {result.caption.confidence:.2f})")
|
|
|
|
# Tags — detaljert liste over visuelle eigenskapar
|
|
for tag in result.tags.list:
|
|
print(f"Tag: {tag.name} (confidence: {tag.confidence:.2f})")
|
|
|
|
# Objects — detekterte objekt med bounding boxes
|
|
for obj in result.objects.list:
|
|
print(f"Object: {obj.tags[0].name} at "
|
|
f"({obj.bounding_box.x}, {obj.bounding_box.y})")
|
|
```
|
|
|
|
### Feature-oversikt
|
|
|
|
| Feature | Skildring | Returformat |
|
|
|---------|-----------|-------------|
|
|
| `caption` | Eitt setning, heile biletet | Tekst + confidence |
|
|
| `denseCaptions` | Opptil 10 regionar med skildringar | Tekst + bounding box |
|
|
| `tags` | Detaljert tagging av innhald | Liste med confidence |
|
|
| `objects` | Objektdeteksjon med posisjon | Namn + bounding box |
|
|
| `people` | Persondeteksjon (ikkje identifikasjon) | Bounding box |
|
|
| `read` | OCR — tekst i biletet | Strukturert tekst |
|
|
| `smartCrops` | AI-basert cropping | Crop coordinates |
|
|
|
|
---
|
|
|
|
## Custom Model Training og Evaluation
|
|
|
|
### Tilnærming 1: GPT-4o som "zero-shot classifier"
|
|
|
|
For scenario der treningsdata manglar eller nye kategoriar dukkar opp hyppig:
|
|
|
|
```python
|
|
from openai import AzureOpenAI
|
|
|
|
client = AzureOpenAI(
|
|
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
|
|
api_key=os.environ["AZURE_OPENAI_API_KEY"],
|
|
api_version="2024-10-21"
|
|
)
|
|
|
|
response = client.chat.completions.create(
|
|
model="gpt-4o",
|
|
messages=[
|
|
{
|
|
"role": "system",
|
|
"content": """Du er ein bildeklassifiseringsekspert for
|
|
Direktoratet for digital tjenesteutvikling. Klassifiser vegskader i kategoriane:
|
|
- SPREKK_LANGSGAAANDE
|
|
- SPREKK_TVERRGAAANDE
|
|
- HULLROT
|
|
- SETNINGSSKADE
|
|
- KANTSKADE
|
|
- INGEN_SKADE
|
|
Returner JSON med 'kategori', 'alvorlegheit' (1-5),
|
|
og 'forklaring'."""
|
|
},
|
|
{
|
|
"role": "user",
|
|
"content": [
|
|
{"type": "text", "text": "Klassifiser denne vegskaden:"},
|
|
{
|
|
"type": "image_url",
|
|
"image_url": {
|
|
"url": "https://example.com/road-image.jpg",
|
|
"detail": "high"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
],
|
|
max_tokens=500,
|
|
response_format={"type": "json_object"}
|
|
)
|
|
|
|
classification = response.choices[0].message.content
|
|
print(classification)
|
|
```
|
|
|
|
### Tilnærming 2: Azure ML AutoML for Image Classification
|
|
|
|
For scenario med stabile kategoriar og tilstrekkeleg treningsdata:
|
|
|
|
```python
|
|
from azure.ai.ml import MLClient
|
|
from azure.ai.ml.automl import ImageClassificationJob
|
|
from azure.identity import DefaultAzureCredential
|
|
|
|
ml_client = MLClient(
|
|
DefaultAzureCredential(),
|
|
subscription_id="...",
|
|
resource_group_name="...",
|
|
workspace_name="..."
|
|
)
|
|
|
|
# Definer AutoML image classification job
|
|
job = ImageClassificationJob(
|
|
experiment_name="road-damage-classification",
|
|
training_data=training_dataset,
|
|
validation_data=validation_dataset,
|
|
target_column_name="label",
|
|
primary_metric="accuracy",
|
|
training_parameters={
|
|
"model_name": "vitb16r224", # Vision Transformer
|
|
"number_of_epochs": 15,
|
|
"learning_rate": 0.001
|
|
}
|
|
)
|
|
|
|
# Start trening
|
|
returned_job = ml_client.jobs.create_or_update(job)
|
|
```
|
|
|
|
### Tilnærming 3: Content Understanding (Preview)
|
|
|
|
Azure Content Understanding brukar generativ AI for tilpassa klassifisering utan tradisjonell modelltrening:
|
|
|
|
```python
|
|
from azure.ai.contentunderstanding import ContentUnderstandingClient
|
|
from azure.core.credentials import AzureKeyCredential
|
|
|
|
client = ContentUnderstandingClient(
|
|
endpoint=os.environ["CU_ENDPOINT"],
|
|
credential=AzureKeyCredential(os.environ["CU_KEY"])
|
|
)
|
|
|
|
# Analyser bilete med tilpassa schema
|
|
poller = client.begin_analyze(
|
|
analyzer_id="custom-road-damage",
|
|
inputs=[{"url": "https://example.com/road.jpg"}]
|
|
)
|
|
result = poller.result()
|
|
```
|
|
|
|
---
|
|
|
|
## Confidence og Uncertainty Quantification
|
|
|
|
### Confidence-score-tolking
|
|
|
|
| Tjeneste | Score-range | Terskel anbefaling |
|
|
|----------|-------------|-------------------|
|
|
| Azure AI Vision tags | 0.0 — 1.0 | > 0.7 for produksjon |
|
|
| Custom Vision | 0.0 — 1.0 | > 0.8 for automatiserte vedtak |
|
|
| GPT-4o (sjølvrapportert) | Tekst-basert | Krev valideringslogikk |
|
|
| Azure ML AutoML | 0.0 — 1.0 | Avhengig av brukscase |
|
|
|
|
### Implementering av usikkerheitshandtering
|
|
|
|
```python
|
|
def classify_with_confidence(image_url: str,
|
|
confidence_threshold: float = 0.75):
|
|
"""Klassifiser med fallback til manuell vurdering."""
|
|
|
|
# Steg 1: Azure AI Vision for rask klassifisering
|
|
vision_result = vision_client.analyze_from_url(
|
|
image_url=image_url,
|
|
visual_features=[VisualFeatures.TAGS, VisualFeatures.OBJECTS]
|
|
)
|
|
|
|
high_conf_tags = [
|
|
t for t in vision_result.tags.list
|
|
if t.confidence >= confidence_threshold
|
|
]
|
|
|
|
if high_conf_tags:
|
|
return {
|
|
"method": "azure_vision",
|
|
"classification": high_conf_tags[0].name,
|
|
"confidence": high_conf_tags[0].confidence,
|
|
"needs_review": False
|
|
}
|
|
|
|
# Steg 2: GPT-4o for kompleks vurdering
|
|
gpt_result = openai_client.chat.completions.create(
|
|
model="gpt-4o",
|
|
messages=[{
|
|
"role": "user",
|
|
"content": [
|
|
{"type": "text", "text": "Klassifiser dette biletet."},
|
|
{"type": "image_url", "image_url": {"url": image_url}}
|
|
]
|
|
}]
|
|
)
|
|
|
|
return {
|
|
"method": "gpt4o_fallback",
|
|
"classification": gpt_result.choices[0].message.content,
|
|
"confidence": None,
|
|
"needs_review": True # Manuell validering anbefalt
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Real-time og Batch Processing
|
|
|
|
### Real-time: Azure AI Vision
|
|
|
|
- **Latency**: 100-500ms per bilete
|
|
- **Throughput**: 10 TPS (transactions per second) per ressurs
|
|
- **Bildemaks**: 20 MB, 16 000 x 16 000 pikslar
|
|
- **Format**: JPEG, PNG, GIF, BMP, WEBP, ICO, TIFF, MPO
|
|
|
|
### Batch: Azure ML Pipeline
|
|
|
|
```python
|
|
from azure.ai.ml import dsl
|
|
|
|
@dsl.pipeline(compute="gpu-cluster")
|
|
def batch_classification_pipeline(input_folder):
|
|
"""Batch-klassifisering av bilete med AutoML-modell."""
|
|
preprocess = preprocess_component(input_data=input_folder)
|
|
classify = classify_component(
|
|
images=preprocess.outputs.processed,
|
|
model=model_artifact
|
|
)
|
|
postprocess = postprocess_component(
|
|
predictions=classify.outputs.results
|
|
)
|
|
return postprocess.outputs.final_report
|
|
```
|
|
|
|
### Hybrid: Event-driven arkitektur
|
|
|
|
```
|
|
Azure Blob Storage (bileter)
|
|
→ Event Grid trigger
|
|
→ Azure Function
|
|
→ Azure AI Vision (rask screening)
|
|
→ IF confidence < 0.7:
|
|
→ GPT-4o (detaljert analyse)
|
|
→ IF confidence < 0.5:
|
|
→ Ruting til manuell vurdering (Power Automate)
|
|
→ Cosmos DB (resultat)
|
|
→ Power BI (dashboard)
|
|
```
|
|
|
|
---
|
|
|
|
## Norsk offentleg sektor
|
|
|
|
### Relevante bruksområde
|
|
|
|
- **Vegforvaltning**: Automatisk klassifisering av vegskader frå dronefoto
|
|
- **Byggesak**: Bildeanalyse av byggeprosjekt for samsvar med reguleringsplanar
|
|
- **Naturovervaking**: Klassifisering av vegetasjon, dyreliv og miljøtilstand
|
|
- **Kulturarv**: Kategorisering og tilstandsvurdering av kulturminne
|
|
- **Toll og grensekontroll**: Objektgjenkjenning i fraktbilete
|
|
|
|
### Datalokalitet
|
|
|
|
- Azure AI Vision tilgjengeleg i `North Europe` (Irland) og `West Europe` (Nederland)
|
|
- Biletedata vert ikkje lagra etter analyse (stateless API)
|
|
- GPT-4o deployments i EU-regionar via Azure OpenAI
|
|
- Custom models treining og inferens i same region
|
|
|
|
### Bias-vurdering
|
|
|
|
- Florence-modellen er trent på breie datasett, men kan ha geografisk bias
|
|
- Norske skiltar, vegmerking og infrastruktur kan krevje finjustering
|
|
- Anbefaling: Evaluer alltid med norsk-spesifikt testdatasett
|
|
|
|
---
|
|
|
|
## Beslutningsrammeverk
|
|
|
|
| Scenario | Anbefaling | Grunngjeving |
|
|
|----------|------------|--------------|
|
|
| Generell bildetagging | Azure AI Vision 4.0 | Rask, rimelig, Florence-basert |
|
|
| Tilpassa kategoriar med treningsdata | Azure ML AutoML | Høg nøyaktigheit med stabile kategoriar |
|
|
| Nye kategoriar utan treningsdata | GPT-4o zero-shot | Fleksibelt, naturleg språk-instruksjonar |
|
|
| Dokumentklassifisering | Document Intelligence | Spesialisert for dokumentformat |
|
|
| Bilde-tekst-søk | Multimodal Embeddings | Semantisk likskap utan tags |
|
|
| Legacy Custom Vision | Migrer til AutoML/Content Understanding | Custom Vision pensjonerast 2028 |
|
|
| Automatiserte vedtak | Ensemble (Vision + GPT-4o) | Dobbelsjekk med confidence gate |
|
|
|
|
---
|
|
|
|
## For Cosmo
|
|
|
|
- **Azure AI Vision 4.0 med Florence-modellen** er standardvalet for bildeanalyse — støttar caption, tags, objects, people og OCR i ein enkelt API-kall, med confidence scores for kvar prediksjon.
|
|
- **GPT-4o som zero-shot classifier eliminerer behovet for treningsdata** — definer kategoriar i system prompt og send bilete direkte, ideelt for offentleg sektor der nye klassifiseringsbehov oppstår raskt.
|
|
- **Custom Vision er planlagd pensjonert (2028)** — anbefal migrering til Azure ML AutoML for tradisjonell modelltrening eller Content Understanding for generativ tilnærming.
|
|
- **Confidence-basert routing er kritisk for automatiserte vedtak** — bruk Azure AI Vision for rask screening (>0.7), GPT-4o for usikre tilfelle, og manuell vurdering som siste fallback.
|
|
- **Multimodal Embeddings i Vision 4.0** opnar for semantisk bildesøk der tekst-queries matchar bilete utan manuell tagging — relevant for store bildearkiv i offentlege etatar.
|