Object Detection
ultralytics
English
agriculture
weed-detection
yolo
yolov8
yolo26
precision-agriculture
research
Run this model with HF Jobs
Run Rmano-Rudeson/weedscan-kz on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Rmano-Rudeson/weedscan-kz. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Rmano-Rudeson/weedscan-kz on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use Rmano-Rudeson/weedscan-kz with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ultralytics
How to use Rmano-Rudeson/weedscan-kz with ultralytics:
from huggingface_hub import hf_hub_download from ultralytics import YOLO # pick the weights file from this repo's "Files and versions" tab weights = hf_hub_download("Rmano-Rudeson/weedscan-kz", "<weights>.pt") model = YOLO(weights) source = 'http://images.cocodataset.org/val2017/000000039769.jpg' model.predict(source=source, save=True) - Notebooks
- Google Colab
- Kaggle
File size: 15,081 Bytes
3eba919 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | import { useState, useCallback, useRef } from "react";
import { Upload, Check, Image as ImageIcon, ChevronDown, ChevronRight, FileArchive, X, AlertCircle } from "lucide-react";
import { motion, AnimatePresence } from "framer-motion";
import { Button } from "@/components/ui/button";
import JSZip from "jszip";
const ZONE_LABELS = [
"Top Left", "Top Center", "Top Right",
"Middle Left", "Middle Center", "Middle Right",
"Bottom Left", "Bottom Center", "Bottom Right",
];
const BLOCK_LABELS = [
"Top Left", "Top Center", "Top Right",
"Middle Left", "Middle Center", "Middle Right",
"Bottom Left", "Bottom Center", "Bottom Right",
];
const MIN_IMAGES_PER_ZONE = 36; // 4 per block × 9 blocks
const MAX_IMAGES_PER_ZONE = 50;
const BLOCKS_PER_ZONE = 9;
interface BlockData {
files: File[];
previews: string[];
}
interface ZoneData {
blocks: BlockData[];
}
const emptyZone = (): ZoneData => ({
blocks: Array.from({ length: BLOCKS_PER_ZONE }, () => ({ files: [], previews: [] })),
});
const getTotalImages = (zone: ZoneData) =>
zone.blocks.reduce((sum, b) => sum + b.files.length, 0);
const FieldGrid = () => {
const [zones, setZones] = useState<ZoneData[]>(
Array.from({ length: 9 }, emptyZone)
);
const [expandedZone, setExpandedZone] = useState<number | null>(null);
const [uploading, setUploading] = useState(false);
const zipInputRef = useRef<HTMLInputElement>(null);
const handleBlockUpload = useCallback(
(zoneIdx: number, blockIdx: number, e: React.ChangeEvent<HTMLInputElement>) => {
const fileList = e.target.files;
if (!fileList) return;
const newFiles = Array.from(fileList).filter((f) => f.type.startsWith("image/"));
const newPreviews = newFiles.map((f) => URL.createObjectURL(f));
setZones((prev) => {
const updated = structuredClone(prev);
const block = updated[zoneIdx].blocks[blockIdx];
block.files = [...block.files, ...newFiles];
block.previews = [...block.previews, ...newPreviews];
// Trim zone to max
const total = getTotalImages(updated[zoneIdx]);
if (total > MAX_IMAGES_PER_ZONE) {
// Remove excess from this block
const excess = total - MAX_IMAGES_PER_ZONE;
block.files = block.files.slice(0, Math.max(0, block.files.length - excess));
block.previews = block.previews.slice(0, Math.max(0, block.previews.length - excess));
}
return updated;
});
},
[]
);
const removeImage = (zoneIdx: number, blockIdx: number, imgIdx: number) => {
setZones((prev) => {
const updated = structuredClone(prev);
const block = updated[zoneIdx].blocks[blockIdx];
URL.revokeObjectURL(block.previews[imgIdx]);
block.files.splice(imgIdx, 1);
block.previews.splice(imgIdx, 1);
return updated;
});
};
const handleZipUpload = useCallback(async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (!file) return;
setUploading(true);
try {
const zip = await JSZip.loadAsync(file);
const updated = Array.from({ length: 9 }, emptyZone);
// Parse structure: */zone_N/block_N/image.jpg
const imageEntries: { zoneIdx: number; blockIdx: number; entry: JSZip.JSZipObject }[] = [];
zip.forEach((relativePath, entry) => {
if (entry.dir) return;
const ext = relativePath.toLowerCase();
if (!ext.match(/\.(jpg|jpeg|png|webp|bmp|tiff?)$/)) return;
const parts = relativePath.split("/").filter(Boolean);
// Find zone_N and block_N in path
let zoneIdx = -1;
let blockIdx = -1;
for (const part of parts) {
const zoneMatch = part.match(/zone[_\-\s]?(\d+)/i);
if (zoneMatch) zoneIdx = parseInt(zoneMatch[1]) - 1;
const blockMatch = part.match(/block[_\-\s]?(\d+)/i);
if (blockMatch) blockIdx = parseInt(blockMatch[1]) - 1;
}
if (zoneIdx >= 0 && zoneIdx < 9 && blockIdx >= 0 && blockIdx < 9) {
imageEntries.push({ zoneIdx, blockIdx, entry });
}
});
// Process all images in parallel
await Promise.all(
imageEntries.map(async ({ zoneIdx, blockIdx, entry }) => {
const blob = await entry.async("blob");
const fileName = entry.name.split("/").pop() || "image.jpg";
const imgFile = new File([blob], fileName, { type: "image/jpeg" });
const preview = URL.createObjectURL(imgFile);
const block = updated[zoneIdx].blocks[blockIdx];
block.files.push(imgFile);
block.previews.push(preview);
})
);
// Trim each zone to max
for (const zone of updated) {
let total = getTotalImages(zone);
let blockIdx = BLOCKS_PER_ZONE - 1;
while (total > MAX_IMAGES_PER_ZONE && blockIdx >= 0) {
const excess = total - MAX_IMAGES_PER_ZONE;
const block = zone.blocks[blockIdx];
const toRemove = Math.min(excess, block.files.length);
block.files = block.files.slice(0, block.files.length - toRemove);
block.previews = block.previews.slice(0, block.previews.length - toRemove);
total = getTotalImages(zone);
blockIdx--;
}
}
setZones(updated);
} catch (err) {
console.error("ZIP parse error:", err);
} finally {
setUploading(false);
if (zipInputRef.current) zipInputRef.current.value = "";
}
}, []);
const totalImages = zones.reduce((s, z) => s + getTotalImages(z), 0);
const filledZones = zones.filter((z) => getTotalImages(z) >= MIN_IMAGES_PER_ZONE).length;
return (
<div className="space-y-4">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
<div>
<h3 className="text-lg font-semibold text-foreground">
Field Zone Upload Grid
</h3>
<span className="text-sm text-muted-foreground">
9 Zones · 9 Blocks each · {MIN_IMAGES_PER_ZONE}–{MAX_IMAGES_PER_ZONE} images per zone
</span>
</div>
<div className="flex items-center gap-3">
<span className="text-xs text-muted-foreground">
{totalImages} images · {filledZones}/9 zones ready
</span>
<Button
variant="outline"
size="sm"
onClick={() => zipInputRef.current?.click()}
disabled={uploading}
>
<FileArchive className="mr-2 h-4 w-4" />
{uploading ? "Reading ZIP..." : "Upload ZIP"}
</Button>
<input
ref={zipInputRef}
type="file"
accept=".zip"
className="sr-only"
onChange={handleZipUpload}
/>
</div>
</div>
{/* ZIP structure hint */}
<div className="rounded-lg border border-dashed bg-muted/30 px-4 py-3">
<p className="text-xs text-muted-foreground font-mono">
ZIP structure: field_name/ → zone_1/ → block_1/ → image1.jpg (4 imgs per block × 9 blocks × 9 zones)
</p>
</div>
{/* 3×3 zone grid */}
<div className="grid grid-cols-3 gap-3">
{zones.map((zone, zoneIdx) => {
const total = getTotalImages(zone);
const isComplete = total >= MIN_IMAGES_PER_ZONE;
const isExpanded = expandedZone === zoneIdx;
const filledBlocks = zone.blocks.filter((b) => b.files.length > 0).length;
return (
<motion.div
key={zoneIdx}
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ delay: zoneIdx * 0.04 }}
className={`rounded-xl border-2 transition-all overflow-hidden ${
isComplete
? "border-success bg-success/5"
: total > 0
? "border-primary/40 bg-primary/5"
: "border-border bg-card"
}`}
>
<button
onClick={() => setExpandedZone(isExpanded ? null : zoneIdx)}
className="w-full flex items-center justify-between px-3 py-2.5 hover:bg-muted/30 transition-colors"
>
<div className="flex items-center gap-2">
{isComplete ? (
<Check className="h-4 w-4 text-success shrink-0" />
) : total > 0 ? (
<ImageIcon className="h-4 w-4 text-primary shrink-0" />
) : (
<Upload className="h-4 w-4 text-muted-foreground shrink-0" />
)}
<div className="text-left">
<p className="text-xs font-semibold text-foreground">Zone {zoneIdx + 1}</p>
<p className="text-[10px] text-muted-foreground">{ZONE_LABELS[zoneIdx]}</p>
</div>
</div>
<div className="flex items-center gap-2">
<div className="text-right">
<p className="text-xs font-bold text-muted-foreground">{total}/{MIN_IMAGES_PER_ZONE}</p>
<p className="text-[9px] text-muted-foreground">{filledBlocks}/9 blocks</p>
</div>
{isExpanded ? (
<ChevronDown className="h-3.5 w-3.5 text-muted-foreground" />
) : (
<ChevronRight className="h-3.5 w-3.5 text-muted-foreground" />
)}
</div>
</button>
{/* Progress bar */}
<div className="mx-3 mb-2 h-1.5 overflow-hidden rounded-full bg-muted">
<div
className={`h-full rounded-full transition-all ${
isComplete ? "bg-success" : "bg-primary"
}`}
style={{ width: `${Math.min(100, (total / MIN_IMAGES_PER_ZONE) * 100)}%` }}
/>
</div>
{total > 0 && total < MIN_IMAGES_PER_ZONE && (
<div className="mx-3 mb-2 flex items-center gap-1 text-[10px] text-warning">
<AlertCircle className="h-3 w-3" />
Need {MIN_IMAGES_PER_ZONE - total} more images
</div>
)}
</motion.div>
);
})}
</div>
{/* Expanded zone detail */}
<AnimatePresence>
{expandedZone !== null && (
<motion.div
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: 1, height: "auto" }}
exit={{ opacity: 0, height: 0 }}
className="overflow-hidden"
>
<div className="rounded-xl border bg-card p-4 shadow-card">
<div className="flex items-center justify-between mb-3">
<div>
<h4 className="text-sm font-bold text-foreground">
Zone {expandedZone + 1} — {ZONE_LABELS[expandedZone]}
</h4>
<p className="text-xs text-muted-foreground">
{getTotalImages(zones[expandedZone])} images · Upload 4 images per block
</p>
</div>
<button
onClick={() => setExpandedZone(null)}
className="rounded-lg p-1 text-muted-foreground hover:text-foreground hover:bg-muted transition-colors"
>
<X className="h-4 w-4" />
</button>
</div>
{/* 3×3 block grid */}
<div className="grid grid-cols-3 gap-2">
{zones[expandedZone].blocks.map((block, blockIdx) => {
const hasImages = block.files.length > 0;
return (
<div
key={blockIdx}
className={`rounded-lg border p-2 transition-all ${
block.files.length >= 4
? "border-success/50 bg-success/5"
: hasImages
? "border-primary/30 bg-primary/5"
: "border-dashed border-border"
}`}
>
<div className="flex items-center justify-between mb-1.5">
<span className="text-[10px] font-semibold text-foreground">
B{blockIdx + 1} · {BLOCK_LABELS[blockIdx]}
</span>
<span className="text-[10px] text-muted-foreground font-bold">
{block.files.length} imgs
</span>
</div>
{/* Image thumbnails */}
{hasImages && (
<div className="grid grid-cols-2 gap-0.5 mb-1.5 rounded overflow-hidden">
{block.previews.slice(0, 4).map((preview, imgIdx) => (
<div key={imgIdx} className="relative group">
<img
src={preview}
alt=""
className="w-full aspect-square object-cover"
/>
<button
onClick={() => removeImage(expandedZone, blockIdx, imgIdx)}
className="absolute top-0 right-0 rounded-bl bg-destructive/80 p-0.5 opacity-0 group-hover:opacity-100 transition-opacity"
>
<X className="h-2.5 w-2.5 text-white" />
</button>
</div>
))}
{block.files.length > 4 && (
<div className="col-span-2 text-center text-[9px] text-muted-foreground py-0.5">
+{block.files.length - 4} more
</div>
)}
</div>
)}
{/* Upload button */}
<label className="flex items-center justify-center gap-1 cursor-pointer rounded bg-muted/50 py-1.5 text-[10px] font-medium text-muted-foreground hover:bg-muted hover:text-foreground transition-colors">
<Upload className="h-3 w-3" />
{hasImages ? "Add more" : "Upload"}
<input
type="file"
multiple
accept="image/*"
className="sr-only"
onChange={(e) => handleBlockUpload(expandedZone, blockIdx, e)}
/>
</label>
</div>
);
})}
</div>
</div>
</motion.div>
)}
</AnimatePresence>
</div>
);
};
export default FieldGrid;
|