Commit ·
cc71572
1
Parent(s): 189463a
Refactor output schema creation to define features before processing dataset
Browse files327 unmodified lines3283293303313323333347 unmodified lines342343344345346347348349350351352353354355356357358359360361362363364327 unmodified lineslogger.error("Ensure the model exists and you have access permissions")sys.exit(1)# Process datasetlogger.info("🔍 Processing images...")processed_dataset = dataset.map(lambda batch: process_batch(7 unmodified lines),batched=True,batch_size=args.batch_size,desc="Detecting objects",)# Create dynamic features with ClassLabellogger.info("📊 Creating output schema...")new_features = processed_dataset.features.copy()new_features["objects"] = Sequence({"bbox": Sequence(Value("float32"), length=4),"category": ClassLabel(names=[class_name]),"score": Value("float32"),})# Cast to proper typesprocessed_dataset = processed_dataset.cast(new_features)# Calculate statisticstotal_detections = sum(len(objs) for objs in processed_dataset["objects"])images_with_detections = sum(len(objs) > 0 for objs in processed_dataset["objects"])327 unmodified lines3283293303313323333343353363373383393403413423433443457 unmodified lines353354355356357358359360361362327 unmodified lineslogger.error("Ensure the model exists and you have access permissions")sys.exit(1)# Define output schema before processinglogger.info("📊 Creating output schema...")new_features = dataset.features.copy()new_features["objects"] = Sequence({"bbox": Sequence(Value("float32"), length=4),"category": ClassLabel(names=[class_name]),"score": Value("float32"),})# Process dataset with explicit output featureslogger.info("🔍 Processing images...")processed_dataset = dataset.map(lambda batch: process_batch(7 unmodified lines),batched=True,batch_size=args.batch_size,features=new_features,desc="Detecting objects",)# Calculate statisticstotal_detections = sum(len(objs) for objs in processed_dataset["objects"])images_with_detections = sum(len(objs) > 0 for objs in processed_dataset["objects"])
detect-objects.py+13-15