acd20000 commited on
Commit
ad7a20d
·
verified ·
1 Parent(s): dae751f

Upload FloorplanValidator model

Browse files
Files changed (2) hide show
  1. README.md +29 -12
  2. best_floorplan_classifier.pt +3 -0
README.md CHANGED
@@ -27,36 +27,53 @@ This model distinguishes between floorplan images and non-floorplan images in re
27
  ## Usage
28
 
29
  ```python
30
- from huggingface_hub import hf_hub_download
31
  import torch
 
 
 
32
  from PIL import Image
33
- from torchvision import transforms
34
 
35
- # Load model
36
- model_path = hf_hub_download("acd20000/FloorplanValidator", "model.pt")
37
- model = torch.load(model_path, map_location=torch.device('cpu'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  model.eval()
39
 
40
- # Define transformation for input images
41
  transform = transforms.Compose([
42
  transforms.Resize((224, 224)),
43
  transforms.ToTensor(),
44
  transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
45
  ])
46
 
47
- # Load and transform an image
48
  image = Image.open("your_image.jpg").convert('RGB')
49
  input_tensor = transform(image).unsqueeze(0)
50
 
51
- # Make prediction
52
  with torch.no_grad():
53
  output = model(input_tensor)
54
- probabilities = torch.softmax(output, dim=1)
55
- predicted_class = torch.argmax(probabilities, dim=1).item()
56
- confidence = probabilities[0][predicted_class].item()
57
 
58
  result = {
59
- 'class': "floorplan" if predicted_class == 0 else "non-floorplan",
60
  'confidence': confidence
61
  }
62
  print(result)
 
27
  ## Usage
28
 
29
  ```python
 
30
  import torch
31
+ import torch.nn as nn
32
+ from torchvision import transforms, models
33
+ from huggingface_hub import hf_hub_download
34
  from PIL import Image
 
35
 
36
+ # Define the model architecture
37
+ class RealEstateClassifier(nn.Module):
38
+ def __init__(self):
39
+ super().__init__()
40
+ # Load ResNet50
41
+ self.model = models.resnet50(pretrained=False)
42
+ # Modify final layer for binary classification
43
+ num_ftrs = self.model.fc.in_features
44
+ self.model.fc = nn.Linear(num_ftrs, 2) # 2 classes: floorplan and no_image
45
+
46
+ def forward(self, x):
47
+ return self.model(x)
48
+
49
+ # Load the state dict
50
+ model_path = hf_hub_download("acd20000/FloorplanValidator", "best_floorplan_classifier.pt")
51
+ state_dict = torch.load(model_path, map_location=torch.device('cpu'))
52
+
53
+ # Create model and load weights
54
+ model = RealEstateClassifier()
55
+ model.load_state_dict(state_dict)
56
  model.eval()
57
 
58
+ # Define transformation
59
  transform = transforms.Compose([
60
  transforms.Resize((224, 224)),
61
  transforms.ToTensor(),
62
  transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
63
  ])
64
 
65
+ # Make a prediction
66
  image = Image.open("your_image.jpg").convert('RGB')
67
  input_tensor = transform(image).unsqueeze(0)
68
 
 
69
  with torch.no_grad():
70
  output = model(input_tensor)
71
+ probs = torch.softmax(output, dim=1)
72
+ pred_class = torch.argmax(probs, dim=1).item()
73
+ confidence = probs[0][pred_class].item()
74
 
75
  result = {
76
+ 'class': "floorplan" if pred_class == 0 else "non-floorplan",
77
  'confidence': confidence
78
  }
79
  print(result)
best_floorplan_classifier.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1839b7f4231d06933e329e16b4cd388862adf5cbc807b0f363e236b3d808a1c1
3
+ size 94370362