farm-segmentation / README.md
Dhiryashil's picture
Upload 3 files
01ef086 verified

A newer version of the Gradio SDK is available: 5.49.1

Upgrade
metadata
title: Farm Segmentation API
emoji: 🏞️
colorFrom: green
colorTo: blue
sdk: gradio
sdk_version: 4.28.3
app_file: app.py
pinned: false
license: apache-2.0
short_description: AI-powered agricultural image segmentation and land analysis

🏞️ Farm Segmentation API

Advanced agricultural image segmentation using SegFormer models for precise field and crop analysis.

🎯 Capabilities

  • Semantic Segmentation: Pixel-level classification of agricultural scenes
  • Agricultural Categories: Soil, vegetation, water, buildings, equipment
  • Composition Analysis: Percentage breakdown of field components
  • Multi-Resolution: Support for different accuracy/speed tradeoffs

πŸ€– Models

  • SegFormer B0: Fastest processing, basic accuracy
  • SegFormer B1: Balanced performance (recommended)
  • SegFormer B2: Highest accuracy, slower processing

πŸ“‘ API Usage

Python

import requests
import base64

def segment_farm_image(image_path, model="segformer_b1"):
    with open(image_path, "rb") as f:
        image_b64 = base64.b64encode(f.read()).decode()
    
    response = requests.post(
        "https://YOUR-USERNAME-farm-segmentation.hf.space/api/predict",
        json={"data": [image_b64, model]}
    )
    return response.json()

result = segment_farm_image("field_image.jpg")
print(result)

πŸ“Š Response Format

{
  "segments_detected": 8,
  "segments": [
    {
      "class": "grass",
      "agricultural_category": "vegetation",
      "pixel_count": 145632,
      "percentage": 35.2,
      "label_id": 9
    },
    {
      "class": "soil",
      "agricultural_category": "soil", 
      "pixel_count": 98234,
      "percentage": 23.7,
      "label_id": 12
    }
  ],
  "processing_time": 2.1
}

🌾 Agricultural Categories

  • soil: Ground, dirt, earth, mud
  • vegetation: Crops, grass, trees, plants
  • water: Irrigation channels, ponds, rivers
  • building: Barns, greenhouses, structures
  • equipment: Tractors, machinery, tools
  • other: Roads, sky, uncategorized objects