Detection

Face detector

class expert.data.detection.face_detector.FaceDetector(model_selection: Optional[int] = 0, min_detection_confidence: Optional[float] = 0.75, max_num_faces: Optional[int] = 10, device: Optional[torch.device] = None)[source]

Bases: object

Face detection and embedding implementation.

FaceDetector processes an BGR image and returns a list of the detected face embeddings and bounding boxes.

Example

>>> face_detector = FaceDetector(model_selection=0, min_detection_confidence=0.9)
property device: torch.device

Check the device type.

Returns

Device type on local machine.

Return type

torch.device

detect(image: numpy.ndarray) List[source]
Parameters

image (np.ndarray) – RGB image represented as numpy ndarray.

Returns

List with detected face locations.

Return type

List

embed(image: numpy.ndarray) List[source]

Cropping and embedding area where the face is located.

Parameters

image (np.ndarray) – BGR image represented as numpy ndarray.

Returns

List with detected face locations and embeddings.

Return type

List

Inception resnet

class expert.data.detection.inception_resnet_v1.BasicConv2d(in_planes: int, out_planes: int, kernel_size: int, stride: int, padding: int = 0)[source]

Bases: torch.nn.modules.module.Module

forward(x: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class expert.data.detection.inception_resnet_v1.Block35(scale: float = 1.0)[source]

Bases: torch.nn.modules.module.Module

forward(x: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class expert.data.detection.inception_resnet_v1.Block17(scale: float = 1.0)[source]

Bases: torch.nn.modules.module.Module

forward(x: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class expert.data.detection.inception_resnet_v1.Block8(scale: float = 1.0, noReLU: bool = False)[source]

Bases: torch.nn.modules.module.Module

forward(x: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class expert.data.detection.inception_resnet_v1.Mixed_6a[source]

Bases: torch.nn.modules.module.Module

forward(x: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class expert.data.detection.inception_resnet_v1.Mixed_7a[source]

Bases: torch.nn.modules.module.Module

forward(x: torch.Tensor) torch.Tensor[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class expert.data.detection.inception_resnet_v1.InceptionResnetV1(pretrained: Optional[str] = 'vggface2', classify: Optional[bool] = False, num_classes: Optional[int] = None, dropout_prob: Optional[float] = 0.6, device: Optional[torch.device] = None)[source]

Bases: torch.nn.modules.module.Module

Inception Resnet V1 model with optional loading of pretrained weights.

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

Raises

Exception – If “pretrained” is not specified and “classify” is True, “num_classes” must be specified.

Example

>>> import torch
>>> device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
>>> resnet = InceptionResnetV1(pretrained='vggface2', device=device).eval()
property device: torch.device

Check the device type.

Returns

Device type on local machine.

Return type

torch.device

forward(x: torch.Tensor) torch.Tensor[source]

Calculate embeddings or logits given a batch of input image tensors.

Parameters

x (Tensor) – Batch of image tensors representing faces.

Returns

Batch of embedding vectors or multinomial logits.

Return type

Tensor