Metadata-Version: 2.1
Name: fdet-offline
Version: 1.0.5
Summary: An easy to use face detection module based on MTCNN and RetinaFace algorithms.
Home-page: https://github.com/vikrosj/fdet-offline
Author: Viktoria R.
Author-email: viktoria.rosjo@gmail.com
Maintainer: Viktoria R.
Maintainer-email: viktoria.rosjo@gmail.com
License: UNKNOWN
Download-URL: https://github.com/vikrosj/fdet-offline/archive/1.0.5.tar.gz
Keywords: face recognition detection biometry
Platform: UNKNOWN
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: CacheControl (==0.12.6)
Requires-Dist: Pillow (==8.0.0)
Requires-Dist: appdirs (==1.4.3)
Requires-Dist: attrs (==20.2.0)
Requires-Dist: certifi (==2019.11.28)
Requires-Dist: chardet (==3.0.4)
Requires-Dist: click (==7.1.2)
Requires-Dist: colorama (==0.4.4)
Requires-Dist: colour (==0.1.5)
Requires-Dist: contextlib2 (==0.6.0)
Requires-Dist: distlib (==0.3.0)
Requires-Dist: distro (==1.4.0)
Requires-Dist: fdet-offline-mtcnn-weights (==1.0.0)
Requires-Dist: future (==0.18.2)
Requires-Dist: html5lib (==1.0.1)
Requires-Dist: idna (==2.8)
Requires-Dist: iniconfig (==1.1.1)
Requires-Dist: ipaddr (==2.2.0)
Requires-Dist: lockfile (==0.12.2)
Requires-Dist: msgpack (==0.6.2)
Requires-Dist: numpy (==1.19.2)
Requires-Dist: opencv-python (==4.4.0.44)
Requires-Dist: packaging (==20.3)
Requires-Dist: pep517 (==0.8.2)
Requires-Dist: pluggy (==0.13.1)
Requires-Dist: progress (==1.5)
Requires-Dist: py (==1.9.0)
Requires-Dist: pyparsing (==2.4.6)
Requires-Dist: pytest (==6.1.1)
Requires-Dist: pytoml (==0.1.21)
Requires-Dist: requests (==2.22.0)
Requires-Dist: retrying (==1.3.3)
Requires-Dist: six (==1.14.0)
Requires-Dist: toml (==0.10.1)
Requires-Dist: torch (==1.6.0+cpu)
Requires-Dist: torchvision (==0.7.0+cpu)
Requires-Dist: ttictoc (==0.5.6)
Requires-Dist: urllib3 (==1.25.8)
Requires-Dist: webencodings (==0.5.1)

# FDet-Offline: just like FDet, but offline

### Download like this: 
```console
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](https://github.com/acnazarejr/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:

```python
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](https://pytorch.org/docs/stable/generated/torch.load.html#torch.load).

This partial function gets *map_location* from *__load_model*.

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

```python
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):

```python

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):


```python
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:

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

[load_state_dict_from_url](https://pytorch.org/docs/stable/_modules/torch/hub.html#load_state_dict_from_url), returns a [torch.load](https://pytorch.org/docs/stable/generated/torch.load.html#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;

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


