Views
No views yet
unslothFloorPlanVisionAIAdaptor model is a state-of-the-art Vision-Language Model (VLM) designed for analyzing floor plan images. The model leverages a deep neural architecture optimized for tasks requiring detailed visual understanding combined with textual reasoning. It can infer the layout, room counts, key features, and other architectural details from images of floor plans.torch, unsloth, and transformers are installed:pip install torch unsloth transformers1import os
2from unsloth import FastVisionModel # Import FastVisionModel for Vision-Language tasks
3import torch
4
5# Load the pre-trained model and tokenizer
6model, tokenizer = FastVisionModel.from_pretrained(
7 "sabaridsnfuji/FloorPlanVisionAIAdaptor",
8 load_in_4bit=True, # Use 4-bit precision to save memory if needed
9 use_gradient_checkpointing="unsloth" # Enable gradient checkpointing for efficiency
10)
11
12FastVisionModel.for_inference(model) # Enable inference mode
13
14
15from PIL import Image
16
17# Function to load image using PIL and return image object
18def load_image(image_path):
19 try:
20 image = Image.open(image_path)
21 return image
22 except Exception as e:
23 print(f"Error loading image {image_path}: {e}")
24 return None
25
26# Define the instruction and input
27instruction = """You are an expert in architecture and interior design. Analyze the floor plan image and describe accurately the key features, room count, layout, and any other important details you observe."""
28
29image = load_image("/content/sample_images/5_2.jpg") # converted_dataset[0]["image"]
30
31
32# Format input message
33messages = [
34 {"role": "user", "content": [
35 {"type": "image"},
36 {"type": "text", "text": instruction}
37 ]}
38]
39
40input_text = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
41
42# Prepare inputs
43inputs = tokenizer(
44 image, # Replace with the actual image tensor
45 input_text,
46 add_special_tokens=False,
47 return_tensors="pt",
48).to("cuda")
49
50# Perform inference
51from transformers import TextStreamer
52text_streamer = TextStreamer(tokenizer, skip_prompt=True)
53
54output = model.generate(
55 **inputs,
56 streamer=text_streamer,
57 max_new_tokens=2048,
58 use_cache=True,
59 temperature=1.5,
60 min_p=0.1
61)
**Room Count:**
1 bedroom, 1 study/office, 1 bathroom, kitchen, living room, dining room, verandah.
**Room Types and Labels:**
Bedroom, kitchen, living room, dining room, study/office, bathroom, verandah.
**Room Sizes:**
- Bedroom: 9'8" x 9'10"
- Kitchen: 22'8" x 13'0"
- Dining Room: 10'0" x 13'0"
- Living Room: 13'8" x 15'6"
- Study/Office: 9'8" x 9'10"
**Primary Features:**
Stairs, verandah, windows along perimeter, kitchen island.
**Functional Areas:**
Bathroom adjacent to kitchen; no pantry or mudroom. Kitchen island provides functional space.
**Layout Overview:**
Central stairs with rooms radiating off. Kitchen near bathroom; living and dining areas open-plan.
**Flooring and Attributes:**
Tile in bathroom, verandah, and main living spaces. Likely standard ceiling height.
**Summary:**
Compact, single-floor layout with essential living spaces and utility rooms. Open-plan living areas provide fluid movement; stairs likely provide additional storage.<|eot_id|>unsloth and transformers libraries.