diff --git a/Albert_Project/core/yolo_extractor.py b/Albert_Project/core/yolo_extractor.py index 88964be..476a1f0 100644 --- a/Albert_Project/core/yolo_extractor.py +++ b/Albert_Project/core/yolo_extractor.py @@ -51,30 +51,21 @@ DETECTION_CONF = 0.40 # ── YOLO class names for each model ────────────────────────────────────── -# Floor plan model classes (must match data.yaml used during training) +# Floor plan model classes — MUST match data.yaml used during training exactly. +# Order is alphabetical as exported by Roboflow (YOLOv11 format). FLOOR_PLAN_CLASSES = [ - "kitchen_region", # 0 - "bath_region", # 1 - "sink_symbol", # 2 kitchen sink - "range_symbol", # 3 stove/cooktop - "dw_symbol", # 4 dishwasher - "fridge_symbol", # 5 refrigerator - "oven_symbol", # 6 wall oven - "microwave_symbol", # 7 - "hood_symbol", # 8 - "pantry_symbol", # 9 - "vanity_sink_symbol", # 10 bathroom vanity sink - "toilet_symbol", # 11 - "bathtub_symbol", # 12 - "shower_symbol", # 13 - "shower_door_symbol", # 14 - "medicine_cabinet_symbol", # 15 - "linen_closet_symbol", # 16 - "bidet_symbol", # 17 - "door_swing", # 18 - "window_symbol", # 19 - "structural_column", # 20 - "soffit_hatch", # 21 + "Legends_Symbols", # 0 — legend/title block region (123 instances in dataset) + "bath_region", # 1 — full bathroom bounding region + "bathtub_symbol", # 2 + "dw_symbol", # 3 — dishwasher + "fridge_symbol", # 4 — refrigerator + "kitchen_region", # 5 — full kitchen bounding region + "microwave_symbol", # 6 — NOTE: only 13 training instances; use conf >= 0.65 + "pantry_symbol", # 7 — NOTE: only 1 training instance; use conf >= 0.75 + "range_symbol", # 8 — stove/cooktop + "sink_symbol", # 9 — kitchen sink + "toilet_symbol", # 10 + "vanity_sink_symbol", # 11 — bathroom vanity sink ] # Elevation model classes @@ -171,19 +162,21 @@ class YOLOExtractor: """ Detect kitchen/bath room regions and all fixture symbols from a floor plan image. - Returns a dict compatible with the existing pipeline: + Returns a dict with the following keys: { "kitchen_regions": [YOLODetection, ...], "bath_regions": [YOLODetection, ...], - "appliances": [{"type": "RANGE"|"REF"|"SINK"|"DW"|"OVEN"|"MIC", + "legend_regions": [YOLODetection, ...], # title block / legend areas + "appliances": [{"type": "RANGE"|"REF"|"SINK"|"DW"|"MIC"|"PANTRY", "x_in": float, "width_in": float, "confidence": float}], - "fixtures": [{"type": "TOILET"|"BATHTUB"|"SHOWER"|"VANITY_SINK"|"BIDET", + "fixtures": [{"type": "TOILET"|"BATHTUB"|"VANITY_SINK", "x_in": float, "width_in": float, "confidence": float}], - "doors": [{"x_in": float, "width_in": float, "height_in": 80.0, "notes": str}], - "windows": [{"x_in": float, "width_in": float, "sill_height_in": 36.0, "notes": str}], - "columns": [{"x_in": float, "width_in": float, "notes": str}], "yolo_used": True | False } + + NOTE: doors, windows, and structural_column are NOT in the trained dataset + (12-class Roboflow export). The pipeline's existing OpeningExtractor heuristic + handles those instead. Do not add dead keys for them here. """ model = self._load_model(FLOOR_PLAN_MODEL_PATH, "_floor_model") if model is None: @@ -192,28 +185,32 @@ class YOLOExtractor: img = _bytes_to_array(page_image_bytes) results = model(img, conf=DETECTION_CONF, verbose=False)[0] + # Classes present in the 12-class trained dataset (data.yaml order) KITCHEN_APPLIANCE_MAP = { "sink_symbol": "SINK", "range_symbol": "RANGE", "dw_symbol": "DW", "fridge_symbol": "REF", - "oven_symbol": "OVEN", - "microwave_symbol": "MIC", + "microwave_symbol": "MIC", # 13 training instances — use higher threshold + "pantry_symbol": "PANTRY", # 1 training instance — use higher threshold } BATH_FIXTURE_MAP = { - "vanity_sink_symbol": "VANITY_SINK", - "toilet_symbol": "TOILET", - "bathtub_symbol": "BATHTUB", - "shower_symbol": "SHOWER", - "bidet_symbol": "BIDET", - "medicine_cabinet_symbol": "MED_CAB", - "linen_closet_symbol": "LINEN", + "vanity_sink_symbol": "VANITY_SINK", + "toilet_symbol": "TOILET", + "bathtub_symbol": "BATHTUB", + } + # Higher confidence threshold for classes with very few training examples + LOW_DATA_CLASSES = { + "microwave_symbol": 0.65, + "pantry_symbol": 0.75, } out: dict = { - "kitchen_regions": [], "bath_regions": [], - "appliances": [], "fixtures": [], - "doors": [], "windows": [], "columns": [], + "kitchen_regions": [], + "bath_regions": [], + "legend_regions": [], + "appliances": [], + "fixtures": [], "yolo_used": True, } @@ -242,47 +239,33 @@ class YOLOExtractor: out["kitchen_regions"].append(det) elif cls == "bath_region": out["bath_regions"].append(det) + elif cls == "Legends_Symbols": + # Detected legend/title block — logged but not wired into cabinets + out["legend_regions"].append(det) elif cls in KITCHEN_APPLIANCE_MAP: + # Skip underrepresented classes below their raised confidence threshold + min_conf = LOW_DATA_CLASSES.get(cls, DETECTION_CONF) + if conf < min_conf: + continue out["appliances"].append({ - "type": KITCHEN_APPLIANCE_MAP[cls], - "x_in": x_in, - "width_in": width_in, + "type": KITCHEN_APPLIANCE_MAP[cls], + "x_in": x_in, + "width_in": width_in, "confidence": conf, - "notes": f"YOLO {cls} conf={conf:.2f}", + "notes": f"YOLO {cls} conf={conf:.2f}", }) elif cls in BATH_FIXTURE_MAP: out["fixtures"].append({ - "type": BATH_FIXTURE_MAP[cls], - "x_in": x_in, - "width_in": width_in, - "height_in": height_in, + "type": BATH_FIXTURE_MAP[cls], + "x_in": x_in, + "width_in": width_in, + "height_in": height_in, "confidence": conf, - "notes": f"YOLO {cls} conf={conf:.2f}", - }) - elif cls == "door_swing": - out["doors"].append({ - "type": "door", - "width_in": width_in, - "x_in": x_in, - "height_in": 80.0, - "notes": f"YOLO door swing conf={conf:.2f}", - }) - elif cls == "window_symbol": - out["windows"].append({ - "type": "window", - "width_in": width_in, - "x_in": x_in, - "sill_height_in": 36.0, - "height_in": 48.0, - "notes": f"YOLO window conf={conf:.2f}", - }) - elif cls == "structural_column": - out["columns"].append({ - "type": "column", - "width_in": width_in, - "x_in": x_in, - "notes": f"YOLO column conf={conf:.2f}", + "notes": f"YOLO {cls} conf={conf:.2f}", }) + # All other classes (if any future model adds them) are silently ignored here. + # Do NOT add branches for door_swing / window_symbol / structural_column — + # those are not in the trained 12-class dataset. return out diff --git a/Albert_Project/datasets/floor_plan.yaml b/Albert_Project/datasets/floor_plan.yaml index ab0aba1..3b07fa4 100644 --- a/Albert_Project/datasets/floor_plan.yaml +++ b/Albert_Project/datasets/floor_plan.yaml @@ -3,25 +3,15 @@ train: images val: images names: - 0: kitchen_region + 0: Legends_Symbols 1: bath_region - 2: sink_symbol - 3: range_symbol - 4: dw_symbol - 5: fridge_symbol - 6: oven_symbol - 7: microwave_symbol - 8: hood_symbol - 9: pantry_symbol - 10: vanity_sink_symbol - 11: toilet_symbol - 12: bathtub_symbol - 13: shower_symbol - 14: shower_door_symbol - 15: medicine_cabinet_symbol - 16: linen_closet_symbol - 17: bidet_symbol - 18: door_swing - 19: window_symbol - 20: structural_column - 21: soffit_hatch + 2: bathtub_symbol + 3: dw_symbol + 4: fridge_symbol + 5: kitchen_region + 6: microwave_symbol + 7: pantry_symbol + 8: range_symbol + 9: sink_symbol + 10: toilet_symbol + 11: vanity_sink_symbol diff --git a/Albert_Project/models/yolo_floor_plan/weights/best.pt b/Albert_Project/models/yolo_floor_plan/weights/best.pt new file mode 100644 index 0000000..1e02e04 Binary files /dev/null and b/Albert_Project/models/yolo_floor_plan/weights/best.pt differ diff --git a/Albert_Project/pipeline.py b/Albert_Project/pipeline.py index f869138..a0f5a60 100644 --- a/Albert_Project/pipeline.py +++ b/Albert_Project/pipeline.py @@ -65,9 +65,11 @@ class UnitSchedule: review_flags: list[str] = field(default_factory=list) legend_map: dict[str, str] = field(default_factory=dict) appliance_anchors: list[dict] = field(default_factory=list) - floor_plan_doors: list[dict] = field(default_factory=list) - floor_plan_windows: list[dict] = field(default_factory=list) + fixture_anchors: list[dict] = field(default_factory=list) # YOLO bath fixtures kitchen_bbox: list[dict] = field(default_factory=list) + legend_bbox: list[dict] = field(default_factory=list) # YOLO legend regions + # NOTE: floor_plan_doors / floor_plan_windows removed — not in the 12-class trained + # dataset. The OpeningExtractor heuristic remains the source of truth for doors/windows. @property def all_cabinets(self): @@ -207,10 +209,12 @@ def process_unit( yolo_result = yolo.detect_floor_plan(ex.render_full_page(page_idx, dpi=200), dpi=200) if yolo_result.get("yolo_used"): schedule.appliance_anchors = yolo_result.get("appliances", []) - schedule.floor_plan_doors = yolo_result.get("doors", []) - schedule.floor_plan_windows = yolo_result.get("windows", []) + schedule.fixture_anchors = yolo_result.get("fixtures", []) schedule.kitchen_bbox = yolo_result.get("kitchen_regions", []) - print(f" [YOLO] Extracted {len(schedule.appliance_anchors)} appliances") + schedule.legend_bbox = yolo_result.get("legend_regions", []) + n_app = len(schedule.appliance_anchors) + n_fix = len(schedule.fixture_anchors) + print(f" [YOLO] {n_app} appliances, {n_fix} fixtures detected") # Extract legend mapping if not already done if not schedule.legend_map: diff --git a/Albert_Project/requirements.txt b/Albert_Project/requirements.txt index d818756..f19f336 100644 --- a/Albert_Project/requirements.txt +++ b/Albert_Project/requirements.txt @@ -9,3 +9,5 @@ openai>=1.30.0 shapely>=2.0.0 python-dotenv>=1.0.0 Pillow>=10.0.0 +numpy>=1.24.0 +ultralytics>=8.4.0