• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cosanlab / py-feat / 15090929758

19 Oct 2024 05:10AM UTC coverage: 54.553%. First build
15090929758

push

github

web-flow
Merge pull request #228 from cosanlab/huggingface

WIP: Huggingface Integration

702 of 1620 new or added lines in 46 files covered. (43.33%)

3409 of 6249 relevant lines covered (54.55%)

3.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.71
/feat/identity_detectors/facenet/facenet_test.py
1
from feat.utils import set_torch_device
6✔
2
from feat.identity_detectors.facenet.facenet_model import InceptionResnetV1
6✔
3

4

5
class Facenet:
6✔
6
    """Facenet Inception Resnet V1 model with optional loading of pretrained weights.
7

8
    Model parameters can be loaded based on pretraining on the VGGFace2 or CASIA-Webface
9
    datasets. Pretrained state_dicts are automatically downloaded on model instantiation if
10
    requested and cached in the torch cache. Subsequent instantiations use the cache rather than
11
    redownloading.
12

13
    Keyword Arguments:
14
        pretrained {str} -- Optional pretraining dataset. Either 'huggingface', 'vggface2' or 'casia-webface'.
15
            (default: {None})
16
        classify {bool} -- Whether the model should output classification probabilities or feature
17
            embeddings. (default: {False})
18
        num_classes {int} -- Number of output classes. If 'pretrained' is set and num_classes not
19
            equal to that used for the pretrained model, the final linear layer will be randomly
20
            initialized. (default: {None})
21
        dropout_prob {float} -- Dropout probability. (default: {0.6})
22
    """
23

24
    def __init__(
6✔
25
        self,
26
        pretrained="huggingface",
27
        classify=False,
28
        num_classes=None,
29
        dropout_prob=0.6,
30
        device="auto",
31
    ):
32
        super().__init__()
×
33

NEW
34
        if pretrained == "huggingface":
×
NEW
35
            self.model = InceptionResnetV1(
×
36
                pretrained=None,
37
                classify=classify,
38
                num_classes=num_classes,
39
                dropout_prob=dropout_prob,
40
                device=device,
41
            )
NEW
42
            self.model.from_pretrained("py-feat/facenet")
×
43
        else:
NEW
44
            pretrained = "vggface2"
×
NEW
45
            self.model = InceptionResnetV1(
×
46
                pretrained=pretrained,
47
                classify=classify,
48
                num_classes=num_classes,
49
                dropout_prob=dropout_prob,
50
                device=device,
51
            )
52

53
        self.device = set_torch_device(device)
×
54
        self.model.eval()
×
55

56
    def __call__(self, img):
6✔
57
        """
58
        img is of shape BxCxHxW --
59
        """
60

61
        return self.model.forward(img)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc