"use client" import { useState } from "react" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Progress } from "@/components/ui/progress" import { Slider } from "@/components/ui/slider" import { Switch } from "@/components/ui/switch" import { Label } from "@/components/ui/label" import { RotateCw, FlipVerticalIcon as Flip, Contrast, Sun, Crop, Palette, Info, Play, Pause, SkipForward, CheckCircle, AlertCircle, } from "lucide-react" interface PreprocessingSettings { resize: boolean targetSize: number normalize: boolean augmentation: boolean rotation: number brightness: number contrast: number flip: boolean crop: boolean } interface ProcessingStep { id: string name: string description: string icon: any status: "pending" | "processing" | "completed" | "error" progress: number } const defaultSampleImages = [ { id: "1", name: "风景画1.jpg", url: "/mountain-lake-painting.png" }, { id: "2", name: "抽象艺术.jpg", url: "/colorful-geometric-abstract.png" }, { id: "3", name: "人物肖像.jpg", url: "/artistic-portrait.png" }, { id: "4", name: "花卉静物.jpg", url: "/floral-still-life.png" }, ] interface DataPreprocessingStepProps { onNext?: () => void selectedImages?: string[] } export default function DataPreprocessingStep({ onNext, selectedImages = [] }: DataPreprocessingStepProps) { const [settings, setSettings] = useState({ resize: true, targetSize: 512, normalize: true, augmentation: true, rotation: 15, brightness: 10, contrast: 10, flip: true, crop: false, }) const [processingSteps, setProcessingSteps] = useState([ { id: "quality-check", name: "质量检查", description: "检查图像分辨率、格式和完整性", icon: AlertCircle, status: "pending", progress: 0, }, { id: "resize", name: "尺寸标准化", description: "将所有图像调整为统一尺寸", icon: Crop, status: "pending", progress: 0, }, { id: "normalize", name: "数值归一化", description: "将像素值标准化到0-1范围", icon: Palette, status: "pending", progress: 0, }, { id: "augmentation", name: "数据增强", description: "通过旋转、翻转等方式增加数据多样性", icon: RotateCw, status: "pending", progress: 0, }, ]) const [isProcessing, setIsProcessing] = useState(false) const [currentProcessingStep, setCurrentProcessingStep] = useState(0) const sampleImages = selectedImages.length > 0 ? selectedImages.slice(0, 4).map((url, index) => ({ id: `selected-${index}`, name: `选中图像${index + 1}.jpg`, url: url, })) : defaultSampleImages const [selectedImage, setSelectedImage] = useState(sampleImages[0]) const updateSetting = (key: keyof PreprocessingSettings, value: any) => { setSettings((prev) => ({ ...prev, [key]: value })) } const startProcessing = async () => { setIsProcessing(true) setCurrentProcessingStep(0) // Reset all steps setProcessingSteps((prev) => prev.map((step) => ({ ...step, status: "pending" as const, progress: 0, })), ) // Simulate processing each step for (let i = 0; i < processingSteps.length; i++) { setCurrentProcessingStep(i) // Update current step to processing setProcessingSteps((prev) => prev.map((step, index) => (index === i ? { ...step, status: "processing" as const } : step)), ) // Simulate progress for (let progress = 0; progress <= 100; progress += 10) { await new Promise((resolve) => setTimeout(resolve, 100)) setProcessingSteps((prev) => prev.map((step, index) => (index === i ? { ...step, progress } : step))) } // Mark as completed setProcessingSteps((prev) => prev.map((step, index) => (index === i ? { ...step, status: "completed" as const, progress: 100 } : step)), ) } setIsProcessing(false) } const getImageTransform = () => { let transform = "" if (settings.rotation > 0) { transform += `rotate(${settings.rotation}deg) ` } if (settings.flip) { transform += "scaleX(-1) " } return transform } const getImageFilter = () => { let filter = "" if (settings.brightness !== 0) { filter += `brightness(${100 + settings.brightness}%) ` } if (settings.contrast !== 0) { filter += `contrast(${100 + settings.contrast}%) ` } return filter } const completedSteps = processingSteps.filter((step) => step.status === "completed").length const totalSteps = processingSteps.length const handleNext = () => { if (onNext && completedSteps >= totalSteps) { onNext() } } return (
{/* Introduction */}
什么是数据预处理?

数据预处理是确保AI模型能够有效学习的关键步骤。就像厨师在烹饪前需要清洗和切配食材一样, 我们需要对图像数据进行标准化处理,包括调整尺寸、增强数据多样性、检查质量等, 以提高模型训练的效果和稳定性。

{/* Settings Panel */} 预处理设置 调整预处理参数,观察对图像的影响 {/* Image Resize */}
updateSetting("resize", checked)} />
{settings.resize && (
updateSetting("targetSize", value)} min={256} max={1024} step={64} className="w-full" />
)}
{/* Normalization */}

将像素值标准化到0-1范围

updateSetting("normalize", checked)} />
{/* Data Augmentation */}
updateSetting("augmentation", checked)} />
{settings.augmentation && (
{/* Rotation */}
updateSetting("rotation", value)} min={0} max={45} step={5} className="w-full" />
{/* Brightness */}
updateSetting("brightness", value)} min={0} max={30} step={5} className="w-full" />
{/* Contrast */}
updateSetting("contrast", value)} min={0} max={30} step={5} className="w-full" />
{/* Flip */}
updateSetting("flip", checked)} />
)}
{/* Preview Panel */} 预处理预览 {selectedImages.length > 0 ? "使用你选择的图像进行预处理预览" : "使用示例图像进行预处理预览"}
{/* Image Selector */}
{sampleImages.map((image) => ( ))}
{/* Before/After Comparison */}
原始图像
预处理后
{/* Processing Info */}

预处理信息

{settings.resize && (

• 尺寸: {settings.targetSize}×{settings.targetSize}px

)} {settings.normalize &&

• 像素值归一化: 0-1范围

} {settings.augmentation && ( <> {settings.rotation > 0 &&

• 随机旋转: ±{settings.rotation}°

} {settings.brightness > 0 &&

• 亮度变化: ±{settings.brightness}%

} {settings.contrast > 0 &&

• 对比度变化: ±{settings.contrast}%

} {settings.flip &&

• 随机水平翻转

} )}
{/* Processing Pipeline */}
预处理流水线 模拟数据预处理的完整流程
{/* Overall Progress */}
总体进度 {completedSteps}/{totalSteps} 步骤完成
{/* Processing Steps */}
{processingSteps.map((step, index) => { const Icon = step.icon return (
{step.status === "completed" ? : }

{step.name}

{step.description}

{step.status === "processing" && (
)}
{step.status === "completed" ? "已完成" : step.status === "processing" ? "处理中" : "等待中"}
) })}
{/* Next Step Button */}
) }