
AI-Powered Image Classification
EvalCommunity Academy Practical Tutorial
AI-Powered Image Classification for M&E: Validate Field Data & Create New Indicators
A practical, no-code tutorial for Monitoring & Evaluation professionals. Learn to use AI to classify field photographs, validate survey data, and construct additional covariates and outcome measures for agriculture, aquaculture, and natural resource interventions.
What this tutorial helps you do
AI-based image classification makes it faster and more consistent to identify and measure farm, fishpond, or infrastructure characteristics at scale — whether from satellite imagery or ground-level field photographs. This tutorial adapts real-world applications from 3ie’s impact evaluation work (source: Making AI work: Practical applications in impact evaluation).
Specifically, you will learn to use AI for two critical M&E tasks:
- Validate or ground truth intervention design — Confirm whether a reported pond, garden, or structure actually exists and appears active.
- Construct additional covariates and outcome measures — Generate structured indicators (e.g., water presence, pond structure, vegetation cover) from images to enrich your analysis.
This approach helps evaluations go beyond survey responses, using AI to systematically verify program implementation and generate richer, more objective measures across many sites.
Learning objectives
1. Set up AI image classification
Use a pre-trained AI model (OpenAI GPT-4 with vision) with no machine learning expertise required.
2. Validate survey data
Compare AI classifications with reported data to measure agreement, overreporting, or underreporting.
3. Create new M&E indicators
Transform image-based classifications (e.g., water size, pond structure) into analysis-ready covariates and outcome variables.
Real-world application: Fishpond evaluation (3ie)
In a real impact evaluation, 3ie needed reliable baseline statistics and outcome measures for an aquaculture intervention. The team required detailed information on fishpond characteristics: whether ponds exist, contain water, are formally constructed, and appear in use. Manually reviewing thousands of field photographs would be time-consuming and inconsistent.
How they used AI:
They wrote code calling the OpenAI API to analyze ground-level field photographs of fishponds, prompting the model to classify each image across structured dimensions: water visibility, water size, water color, pond structure, and surrounding land conditions. This served two purposes: (1) validating survey data (e.g., confirming a reported pond exists and appears active), and (2) constructing new covariates and outcome measures from observed pond characteristics. (Source: 3ie blog)
The same method can be applied to kitchen gardens, irrigation infrastructure, livestock shelters, reforestation plots, or any visible intervention feature.
Step-by-step AI image classification workflow for M&E
This workflow turns a folder of field photos into structured validation data and new M&E indicators.
Step 1
Set up your AI tool (no ML training required)
We will use OpenAI’s API with a pre-trained vision model (GPT-4 Turbo or GPT-4o).
- Create an account at platform.openai.com and add a small credit (e.g., $10 — enough for hundreds or thousands of images).
- Navigate to API keys → Create new secret key → Copy and save it.
Alternative for non-technical users:
If coding is not your preference, use Google Colab (free, browser-based) with the provided template, or try no-code tools like AI Image Classifier by Hive or Claude 3 Vision interface for small batches.
Step 2
Prepare your images and survey data
Organize your files with a clear naming convention that matches survey IDs.
/images
pond_001.jpg
pond_002.jpg
survey_data.csv (farmer ID, reported_water_yesno, reported_active_yesno)
Important: Name each image so it matches a unique ID in your survey data (e.g., pond_001.jpg matches id=001).
Step 3
Run the AI classification using our Google Colab template (No installation required)
Copy and paste this code into Google Colab. No local installation needed.
💰 Cost estimate: OpenAI charges approximately $0.01-0.03 per 1,000 images for GPT-4 Turbo. Test on 5-10 images first to gauge cost for your specific use case.
# Install and import libraries
!pip install openai pandas -q
import openai
import pandas as pd
import base64
import os
from google.colab import files, userdata
# SECURITY: Use Colab Secrets (Recommended)
# 1. Click on the 🔑 "Secrets" tab in the left panel
# 2. Add a new secret named "OPENAI_API_KEY" and paste your key
# 3. Uncomment the line below and comment out the insecure method
try:
openai.api_key = userdata.get('OPENAI_API_KEY')
print("✅ API key loaded from Colab Secrets.")
except:
# INSECURE FALLBACK - Remove this after testing
openai.api_key = "your-api-key-here" # Replace, but for testing only
print("⚠️ WARNING: Using hardcoded API key. Do not share this notebook.")
# Initialize the OpenAI client (new v1.0+ syntax)
client = openai.OpenAI(api_key=openai.api_key)
# Upload images
print("📤 Please upload your image files (JPEG or PNG):")
uploaded = files.upload()
# Define the enhanced prompt for M&E classification
prompt_text = """
You are an M&E assistant. Analyze the fishpond image carefully.
First, provide a 1-sentence plain-language description of what you see.
Then, classify using these exact categories. Return ONLY valid JSON with no extra text.
{
"image_description": "Your 1-sentence description here.",
"pond_exists": "yes/no",
"water_visible": "yes/no",
"water_size": "small/medium/large/not_applicable",
"water_color": "clear/green/brown/murky/not_applicable",
"pond_structure": "formal/informal/not_visible",
"surrounding_land": "vegetation/bare_rock/mixed/not_visible"
}
"""
# Function to encode image
def encode_image(image_path):
with open(image_path, "rb") as img_file:
return base64.b64encode(img_file.read()).decode('utf-8')
# Process each image with error handling
results = []
for image_name in uploaded.keys():
print(f"🖼️ Processing: {image_name}")
try:
base64_image = encode_image(image_name)
response = client.chat.completions.create(
model="gpt-4-turbo", # or "gpt-4o" for newer model
messages=[
{"role": "system", "content": "You are an expert M&E assistant. Respond only with valid JSON."},
{"role": "user", "content": [
{"type": "text", "text": prompt_text},
{"type": "image_url", "image_url": f"data:image/jpeg;base64,{base64_image}"}
]}
],
max_tokens=500,
temperature=0.2 # Lower temperature for more consistent, deterministic outputs
)
ai_output = response.choices[0].message.content
results.append({
"image_id": image_name.split('.')[0], # Remove file extension
"ai_classification_json": ai_output
})
print(f" ✅ Success")
except Exception as e:
print(f" ❌ Error: {e}")
results.append({
"image_id": image_name.split('.')[0],
"ai_classification_json": f'{{"error": "{str(e)}"}}'
})
# Save results
df = pd.DataFrame(results)
csv_file = "ai_classifications.csv"
df.to_csv(csv_file, index=False)
print(f"\n🎉 Done! Download '{csv_file}' from the file browser on the left.")
💡 Pro tip: Run the code, upload your photos, and download the resulting CSV. The output includes both a plain-language description and structured JSON for easy merging with survey data.
Step 4
Validate survey data using AI outputs
Merge your survey data with AI classifications. Calculate agreement rates and identify potential misreporting.
| ID | Survey: water? | AI: water_visible? | Match? |
|---|---|---|---|
| 001 | Yes | Yes | ✅ Match |
| 002 | Yes | No | ❌ Mismatch (False Negative – AI missed it) |
| 003 | No | Yes | ❌ Mismatch (False Positive – AI saw it, survey didn’t) |
Validation metrics to calculate (corrected formulas):
- % agreement = (matches / total rows) × 100
- False Positive Rate (Type I error): survey No but AI Yes / total survey No (AI says it exists, survey says it doesn’t)
- False Negative Rate (Type II error): survey Yes but AI No / total survey Yes (Survey says it exists, AI says it doesn’t)
Step 5
Construct new covariates and outcome measures
AI gives you more than validation. It creates new variables for richer analysis.
| New variable | Possible values | How to use in M&E |
|---|---|---|
water_size | 1=small, 2=medium, 3=large | Covariate in regression or matching |
pond_quality | 0=informal, 1=formal | Treatment fidelity check |
pond_condition_score | Sum of (water_visible + formal_structure + clear_water) | Composite outcome measure |
surrounding_land | vegetation / bare / mixed | Control for environmental context |
Example analysis question: “Do households with formally constructed ponds (AI-classified) report higher food consumption scores, controlling for water size and surrounding land?”
Critical quality checks (from 3ie’s experience)
As highlighted in the original 3ie blog, AI outputs are not deterministic and mistakes will occur. Build in these safeguards:
- Human review sample: Review 10–15% of AI classifications manually to assess measurement error.
- Ask AI for a plain-language description: In addition to classification, ask the model to describe the image. This helps catch edge cases (e.g., photos taken in the dark classified as “black” water). (Note: Our template above already includes this!)
- Establish ground truth benchmarks: For a small subset (e.g., 50 images), have two human coders classify independently and compare with AI.
- Document everything: Keep records of prompts, model versions, and error rates.
“The lesson across all these use cases is the same: AI can dramatically expand what’s possible in evaluation, but it demands the same rigor, and arguably more critical thinking than any other method.” – 3ie
Prompt pack for image classification in M&E
Adapt these prompts to your own intervention context.
1. Fishpond or aquaculture structure
Classify: pond_exists (yes/no), water_visible (yes/no), water_size (small/medium/large), water_color (clear/green/brown/murky), pond_structure (formal/informal/not_visible), surrounding_land (vegetation/barerock/mixed). Return JSON.
2. Kitchen garden or small-scale agriculture
Classify: garden_exists (yes/no), crop_density (low/medium/high), irrigation_visible (yes/no), crop_health (poor/fair/good/excellent), soil_condition (dry/moist/wet). Return JSON.
3. Water infrastructure (well, borehole, irrigation ditch)
Classify: infrastructure_exists (yes/no), functioning (yes/no), water_accessible (yes/no), construction_material (concrete/brick/earth/other), last_maintenance_visible (recent/old/not_visible). Return JSON.
4. Livestock shelter or housing
Classify: shelter_exists (yes/no), animals_present (yes/no), roof_condition (good/fair/poor/damaged), flooring (concrete/earth/wood/other), ventilation (adequate/inadequate). Return JSON.
Recommended tools for AI image classification
OpenAI GPT-4 Vision
Best for custom prompts and JSON-structured outputs. Pay-as-you-go API.
Google Colab (free)
Run Python code in browser. No setup. Great for the template above.
Related EvalCommunity Academy tutorials
AI for Literature Reviews in M&E
Use AI to synthesize evaluation reports and identify evidence gaps.
Building an M&E Evidence Dashboard
Turn AI-assisted classifications into interactive dashboards.
Final checklist before using AI image classification in M&E
- ✅ Have you defined the specific classification variables needed for validation or outcomes?
- ✅ Are your images clearly named to match survey IDs?
- ✅ Have you tested the prompt on a small sample (20–30 images) and reviewed outputs?
- ✅ Have you built in human review of at least 10–15% of classifications?
- ✅ Have you calculated validation metrics (agreement, false positive rate, false negative rate)?
- ✅ Are you storing raw AI outputs separately from cleaned data?
- ✅ Have you documented your prompt, model version, and error checks?
- ✅ Have you planned how to use the new covariates in your analysis?
Turn field photos into structured M&E evidence
EvalCommunity Academy helps M&E professionals use AI tools with structure, transparency, and methodological rigor.
