Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- vision
|
| 5 |
+
- image-classification
|
| 6 |
+
datasets:
|
| 7 |
+
- imagenet-1k
|
| 8 |
+
---
|
| 9 |
+
## How to Use
|
| 10 |
+
``` python
|
| 11 |
+
# Preprocess Image
|
| 12 |
+
def process_image(image, model):
|
| 13 |
+
preprocess = transforms.Compose([
|
| 14 |
+
transforms.Resize((224, 224)),
|
| 15 |
+
transforms.ToTensor(),
|
| 16 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
|
| 17 |
+
])
|
| 18 |
+
input_tensor = preprocess(image).unsqueeze(0)
|
| 19 |
+
input_tensor = input_tensor.to(device)
|
| 20 |
+
with torch.no_grad():
|
| 21 |
+
output = model(input_tensor)
|
| 22 |
+
predicted_count = output.item()
|
| 23 |
+
print(f"Predicted Headcount: {predicted_count}")
|
| 24 |
+
return math.ceil(predicted_count)
|
| 25 |
+
# Load Model
|
| 26 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 27 |
+
|
| 28 |
+
def load_model(selected_model):
|
| 29 |
+
model = None
|
| 30 |
+
model_path = None
|
| 31 |
+
if selected_model == 'VGG16':
|
| 32 |
+
model = models.VGG16()
|
| 33 |
+
model_path = "vgg16_headcount.pth"
|
| 34 |
+
else:
|
| 35 |
+
model = models.ResNet50()
|
| 36 |
+
model_path = "resnet50_headcount.pth"
|
| 37 |
+
model.load_state_dict(torch.load(model_path, map_location=device, weights_only=True))
|
| 38 |
+
model.to(device)
|
| 39 |
+
model.eval()
|
| 40 |
+
print(f"{selected_model}.Heavy Model loaded successfully")
|
| 41 |
+
return model
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
```
|