Update README.md
Browse files
README.md
CHANGED
|
@@ -68,20 +68,35 @@ We present EdgeFace- a lightweight and efficient face recognition network inspir
|
|
| 68 |
# load model
|
| 69 |
model_name="edgeface_base"
|
| 70 |
model=get_model(model_name)
|
| 71 |
-
checkpoint_path=f'checkpoints/{
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
transform = transforms.Compose([
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
transformed_input =
|
| 82 |
|
| 83 |
# extract embedding
|
|
|
|
| 84 |
embedding = model(transformed_input)
|
|
|
|
|
|
|
|
|
|
| 85 |
```
|
| 86 |
|
| 87 |
|
|
|
|
| 68 |
# load model
|
| 69 |
model_name="edgeface_base"
|
| 70 |
model=get_model(model_name)
|
| 71 |
+
checkpoint_path=f'checkpoints/{model_name}.pt'
|
| 72 |
+
# 1. Load the weights into the model
|
| 73 |
+
model.load_state_dict(torch.load(checkpoint_path, map_location='cpu'))
|
| 74 |
+
|
| 75 |
+
# 2. Set the model to evaluation mode on its own line
|
| 76 |
+
model.eval()
|
| 77 |
|
| 78 |
transform = transforms.Compose([
|
| 79 |
+
transforms.ToTensor(),
|
| 80 |
+
transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
|
| 81 |
+
])
|
| 82 |
+
|
| 83 |
+
path = 'path to_face_image'
|
| 84 |
+
aligned = align.get_aligned_face(path)
|
| 85 |
+
transformed_input = transform(aligned)
|
| 86 |
+
|
| 87 |
+
# FIX: Add the batch dimension (turns [3, 112, 112] into [1, 3, 112, 112])
|
| 88 |
+
transformed_input = transformed_input.unsqueeze(0)
|
| 89 |
|
| 90 |
+
# Move to the same device as the model (crucial if you switched to 'mps' or 'cuda')
|
| 91 |
+
device = next(model.parameters()).device
|
| 92 |
+
transformed_input = transformed_input.to(device)
|
| 93 |
|
| 94 |
# extract embedding
|
| 95 |
+
with torch.no_grad(): # Use no_grad to save memory during inference
|
| 96 |
embedding = model(transformed_input)
|
| 97 |
+
|
| 98 |
+
print(embedding.shape)
|
| 99 |
+
|
| 100 |
```
|
| 101 |
|
| 102 |
|