Barath commited on
Commit
1389cd5
·
verified ·
1 Parent(s): 946f57f

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +89 -0
  2. adapter_config.json +36 -0
  3. adapter_model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: openbmb/MiniCPM-V-4
4
+ tags:
5
+ - lora
6
+ - peft
7
+ - vision-language
8
+ - floorplan
9
+ - object-detection
10
+ - minicpm-v
11
+ datasets:
12
+ - Voxel51/FloorPlanCAD
13
+ library_name: peft
14
+ ---
15
+
16
+ # MiniCPM-V-4 Floor-Plan Element Detection (LoRA + vision tuning)
17
+
18
+ Fine-tune of **MiniCPM-V-4 (4B)** for structured extraction from CAD floor
19
+ plans: walls, doors, windows, stairs, fixtures, and furniture as JSON with
20
+ bounding boxes normalized to `[0, 1000]`.
21
+
22
+ ```json
23
+ {"elements": [{"type": "double_door", "bbox": [623, 730, 710, 763]}, ...]}
24
+ ```
25
+
26
+ ## Results (held-out FloorPlanCAD, detection F1 @ IoU 0.5, greedy decoding)
27
+
28
+ | | JSON valid | Precision | Recall | F1 |
29
+ |---|---|---|---|---|
30
+ | MiniCPM-V-4 zero-shot | 32% | 0.027 | 0.010 | 0.015 |
31
+ | LoRA, LLM-only (300 steps, 800 samples) | 16% | 0.0 | 0.0 | 0.0 |
32
+ | **LoRA + vision tuning (800 steps, 3.3k samples)** | **40%** | **0.439** | 0.060 | **0.105** |
33
+
34
+ The decisive factor was **unfreezing the vision tower**: LLM-only LoRA
35
+ learned the output format but stayed image-blind (high-confidence repetition
36
+ of dataset priors). With vision tuning, precision rose 16x over zero-shot —
37
+ the model genuinely grounds boxes in the drawing. Recall remains the open
38
+ weakness (long element lists; outputs sometimes truncate before the JSON
39
+ closes).
40
+
41
+ ## Training
42
+
43
+ - Base: `openbmb/MiniCPM-V-4`, official MiniCPM-V finetune harness
44
+ (`llm_type` ChatML; note: the harness's qwen2 target-span detection needs a
45
+ patch for V-4's tokenizer — spans located by token-id lookup of
46
+ `'<|im_start|>'`/`'assistant'` only exist in Qwen2's vocab)
47
+ - LoRA on LLM attention projections (q/k/v/o) + full vision-tower tuning
48
+ - 3,281 train / held-out eval from
49
+ [FloorPlanCAD](https://huggingface.co/datasets/Voxel51/FloorPlanCAD)
50
+ (FiftyOne detections converted to conversation JSON)
51
+ - 800 steps, effective batch 8, lr 1e-5 cosine, bf16, single NVIDIA L4
52
+ (Modal), ~3.5 h
53
+
54
+ ## Usage
55
+
56
+ ```python
57
+ import torch
58
+ from transformers import AutoModel, AutoTokenizer
59
+ from peft import PeftModel
60
+
61
+ base = "openbmb/MiniCPM-V-4"
62
+ tokenizer = AutoTokenizer.from_pretrained(base, trust_remote_code=True)
63
+ model = AutoModel.from_pretrained(base, trust_remote_code=True,
64
+ torch_dtype=torch.bfloat16, device_map="cuda")
65
+ model = PeftModel.from_pretrained(model, "Barath/minicpmv4-floorplan-lora")
66
+ model = model.merge_and_unload().eval()
67
+
68
+ from PIL import Image
69
+ img = Image.open("floorplan.png").convert("RGB")
70
+ prompt = ('Detect the architectural elements in this floor plan (walls, doors, '
71
+ 'windows, stairs, fixtures, furniture). Return only JSON: '
72
+ '{"elements": [{"type": str, "bbox": [x1, y1, x2, y2]}]} with integer '
73
+ 'coordinates normalized to [0, 1000].')
74
+ out = model.chat(msgs=[{"role": "user", "content": [img, prompt]}],
75
+ tokenizer=tokenizer, sampling=False,
76
+ max_new_tokens=1500, repetition_penalty=1.1)
77
+ print(out)
78
+ ```
79
+
80
+ ## Limitations
81
+
82
+ - Recall is low (0.06): dense plans with dozens of elements are only
83
+ partially enumerated, and long outputs may truncate mid-JSON. Use a
84
+ truncation-tolerant parser in production.
85
+ - Trained on CAD-style monochrome drawings (FloorPlanCAD); photographed or
86
+ hand-drawn plans are out of distribution.
87
+ - Coordinates are model estimates, not measurements.
88
+
89
+ Trained for the Hugging Face **Build Small Hackathon 2026**.
adapter_config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": {
4
+ "base_model_class": "MiniCPMV",
5
+ "parent_library": "transformers_modules.openbmb.MiniCPM-V-4.0968cf95dd0ed5584b5a50d0ded4ce29421674f7.modeling_minicpmv"
6
+ },
7
+ "base_model_name_or_path": "openbmb/MiniCPM-V-4",
8
+ "bias": "none",
9
+ "eva_config": null,
10
+ "exclude_modules": null,
11
+ "fan_in_fan_out": false,
12
+ "inference_mode": true,
13
+ "init_lora_weights": true,
14
+ "layer_replication": null,
15
+ "layers_pattern": null,
16
+ "layers_to_transform": null,
17
+ "loftq_config": {},
18
+ "lora_alpha": 64,
19
+ "lora_bias": false,
20
+ "lora_dropout": 0.05,
21
+ "megatron_config": null,
22
+ "megatron_core": "megatron.core",
23
+ "modules_to_save": [
24
+ "embed_tokens",
25
+ "resampler",
26
+ "vpm"
27
+ ],
28
+ "peft_type": "LORA",
29
+ "r": 64,
30
+ "rank_pattern": {},
31
+ "revision": null,
32
+ "target_modules": "llm\\..*layers\\.\\d+\\.self_attn\\.(q_proj|k_proj|v_proj|o_proj)",
33
+ "task_type": null,
34
+ "use_dora": false,
35
+ "use_rslora": false
36
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b66e9c80baecc45e4b3cb72f834c4ed672bc539bae21b043f34b3c67bb3faf49
3
+ size 1438735616