Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fdet-offline

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fdet-offline

An easy to use face detection module based on MTCNN and RetinaFace algorithms.

  • 1.0.5
  • PyPI
  • Socket score

Maintainers
1

FDet-Offline: just like FDet, but offline

Download like this:

pip install fdet-offline --find-links https://download.pytorch.org/whl/torch_stable.html

Package depends on torch-packages not in PyPi.


A version of fdet where you don't have to access the internet to download the weights.

These are the changes:

MTCNN (only works for this model at the moment)

1.

In fdet/mtcnn.py, line 73-76, the url for the MTCNN-weights are listed:

base_url = 'https://github.com/acnazarejr/fdet/releases/download/weights/'
self._pnet = self.__load_model(_PNet, base_url + 'mtcnn_pnet.pt')
self._rnet = self.__load_model(_RNet, base_url + 'mtcnn_rnet.pt')
self._onet = self.__load_model(_ONet, base_url + 'mtcnn_onet.pt')

I downloaded those weights and created packages to import them (because PyPi has a 100MB max on package size, this was the solution).

I put the weights in the directory weights in the package fdet_offline_mtcnn_weights. The function fdet_offline_mtcnn_weights.import_weights takes mtcnn_type as input and returns a partial function of torch.load.

This partial function gets map_location from __load_model.

The previously mentioned fdet/mtcnn.py, line 73-76, now looks like this:

self._pnet = self.__load_model(_PNet, 'pnet')
self._rnet = self.__load_model(_RNet, 'rnet')
self._onet = self.__load_model(_ONet, 'onet')

In fdet/mtcnn.py, what previously was (url was input):


def __load_model(self, net_class: type, url: str) -> torch.nn.Module:
    """Download and construct the models"""
    try:
        state_dict = load_state_dict_from_url(url, map_location=self._device_control)

is now (mtcnn_type is input):

def __load_model(self, net_class: type, mtcnn_type: str) -> torch.nn.Module:
    """Download and construct the models"""
    try:
        load_state_dict = import_weights.load_partial(mtcnn_type)
        state_dict = load_state_dict(map_location=self._device_control)

2.

At fdet/mtcnn.py, line 427:

state_dict = load_state_dict_from_url(url, map_location=self._device_control)

load_state_dict_from_url, returns a torch.load which takes the weight-file as input. I replaced the load_state_dict_from_url with torch.load, and that's it.

That line now states this instead;

state_dict = torch.load(url, map_location=self._device_control)

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc