Skip to content

Add config #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./.venv
67 changes: 16 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,19 @@
<img src="./data/images/logo.png" width="150" >
# Projekt - Rozpoznawanie i przetwarzanie obrazów

# FaceX-Zoo
FaceX-Zoo is a PyTorch toolbox for face recognition. It provides a training module with various supervisory heads and backbones towards state-of-the-art face recognition, as well as a standardized evaluation module which enables to evaluate the models in most of the popular benchmarks just by editing a simple configuration. Also, a simple yet fully functional face SDK is provided for the validation and primary application of the trained models. Rather than including as many as possible of the prior techniques, we enable FaceX-Zoo to easilyupgrade and extend along with the development of face related domains. Please refer to the [technical report](https://arxiv.org/pdf/2101.04407.pdf) for more detailed information about this project.

About the name:
* "Face" - this repo is mainly for face recognition.
* "X" - we also aim to provide something beyond face recognition, e.g. face parsing, face lightning.
* "Zoo" - there include a lot of algorithms and models in this repo.
![image](data/images/arch.jpg)
- Kamil Majewski 272929
- Michał Dziamski 272928

# What's New
- [Oct. 2021] [Swin Transformer](https://arxiv.org/pdf/2103.14030.pdf) is supported now! We obtain a quite promising result of 98.17 in MegaFace rank1 protocol with Swin-S. For more results, pretrained models and logs please refer to [3.1 Experiments of SOTA backbones](training_mode/README.md). For training face recognition model with Swin Transformer, please refer to [swin_training](training_mode/swin_training). Note that the input size is 224\*224 but not 112\*112 and we use AdamW+CosineLRScheduler to optimize it instead of SGD+MultiStepLR.
- [Sep. 2021] We provide a [Dockfile](docker/Dockerfile) to buid the docker image of this project.
- [Aug. 2021] [RepVGG](https://arxiv.org/pdf/2101.03697.pdf) has been added to the backbones for face recognition, the performance of RepVGG_A0, B0, B1 can be found in [3.1 Experiments of SOTA backbones](training_mode).
- [Jul. 2021] A method for facial expression recognition named [DMUE](https://openaccess.thecvf.com/content/CVPR2021/papers/She_Dive_Into_Ambiguity_Latent_Distribution_Mining_and_Pairwise_Uncertainty_Estimation_CVPR_2021_paper.pdf) has been accepted by CVPR2021, and all codes have been released [here](addition_module/DMUE).
- [Jun. 2021] We evaluate some knowledge distillation methods on face recognition task, results and codes can be found in [face_lightning](addition_module/face_lightning/KDF) module.
- [May. 2021] Tools to convert a trained model to onnx format and the provided sdk format can be found in [model_convertor](addition_module/model_convertor).
- [Apr. 2021] IJB-C 1:1 protocol has been added to the [evaluation module](test_protocol/test_ijbc.sh).
- [Mar. 2021] [ResNeSt](https://hangzhang.org/files/resnest.pdf) and [ReXNet](https://arxiv.org/pdf/2007.00992.pdf) have been added to the backbones, [MagFace](https://arxiv.org/pdf/2103.06627.pdf) has been added to the heads.
- [Feb. 2021] Distributed training and mixed precision training by [apex](https://github.com/NVIDIA/apex) is supported. Please check [distributed_training](training_mode/distributed_training) and [train_amp.py](training_mode/conventional_training/train_amp.py)
- [Jan. 2021] We commit the initial version of FaceX-Zoo.
------------------------------
Uruchamienie programu
------------------------------
Wymagania:
- Python 3.10+
- Kamera USB lub wbudowana
- bash, pip

# Requirements
* python >= 3.7.1
* pytorch >= 1.1.0
* torchvision >= 0.3.0

# Model Training
See [README.md](training_mode/README.md) in [training_mode](training_mode), currently support conventional training and [semi-siamese training](https://arxiv.org/abs/2007.08398).
# Model Evaluation
See [README.md](test_protocol/README.md) in [test_protocol](test_protocol), currently support [LFW](https://people.cs.umass.edu/~elm/papers/lfw.pdf), [CPLFW](http://www.whdeng.cn/CPLFW/Cross-Pose-LFW.pdf), [CALFW](https://arxiv.org/abs/1708.08197), [RFW](https://arxiv.org/abs/1812.00194), [AgeDB30](https://core.ac.uk/download/pdf/83949017.pdf), [IJB-C](http://biometrics.cse.msu.edu/Publications/Face/Mazeetal_IARPAJanusBenchmarkCFaceDatasetAndProtocol_ICB2018.pdf), [MegaFace](https://arxiv.org/abs/1512.00596) and MegaFace-mask.
# Face SDK
See [README.md](face_sdk/README.md) in [face_sdk](face_sdk), currently support face detection, face alignment and face recognition.
# Face Mask Adding
See [README.md](addition_module/face_mask_adding/FMA-3D/README.md) in [FMA-3D](addition_module/face_mask_adding/FMA-3D).

# License
FaceX-Zoo is released under the [Apache License, Version 2.0](LICENSE).

# Acknowledgements
This repo is mainly inspired by [InsightFace](https://github.com/deepinsight/insightface), [InsightFace_Pytorch](https://github.com/TreB1eN/InsightFace_Pytorch), [face.evoLVe](https://github.com/ZhaoJ9014/face.evoLVe.PyTorch/blob/master/README.md). We thank the authors a lot for their valuable efforts.

# Citation
Please consider citing our paper in your publications if the project helps your research. BibTeX reference is as follows.
```BibTeX
@inproceedings{wang2021facex,
author = {Jun Wang, Yinglu Liu, Yibo Hu, Hailin Shi and Tao Mei},
title = {FaceX-Zoo: A PyTorh Toolbox for Face Recognition},
journal = {Proceedings of the 29th ACM international conference on Multimedia},
year = {2021}
}
```
If you have any questions, please contact with Jun Wang ([email protected]), Yinglu Liu ([email protected]), [Yibo Hu](https://aberhu.github.io/) ([email protected]), [Hailin Shi](https://sites.google.com/view/hailin-shi) ([email protected]) and [Wu Liu](http://drliuwu.com)([email protected]).
```bash
git clone https://github.com/DEJA-1/RIPOX.git
cd RIPOX
chmod +x run.sh # Linux/macOS only
./run.sh
```
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
opencv-python
torch
torchvision
scikit-image
PySide6
33 changes: 33 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

echo "Sprawdzanie środowiska..."

OS="$(uname -s)"

if [ "$OS" == "Darwin" ]; then
ACTIVATE=".venv/bin/activate"
PYTHON=python3
elif [ "$OS" == "Linux" ]; then
ACTIVATE=".venv/bin/activate"
PYTHON=python3
elif [[ "$OS" == MINGW* || "$OS" == CYGWIN* || "$OS" == MSYS* ]]; then
ACTIVATE=".venv/Scripts/activate"
PYTHON=python
else
exit 1
fi

if [ ! -d ".venv" ]; then
echo "Tworzenie środowiska virtualenv..."
$PYTHON -m venv .venv
fi

echo "Aktywacja środowiska..."
source "$ACTIVATE"

echo "Instalacja zależności..."
pip install --upgrade pip
pip install --break-system-packages -r requirements.txt

echo "Uruchamianie systemu..."
$PYTHON src/main.py
19 changes: 19 additions & 0 deletions src/configurator/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"frame_crop": {
"x": 0,
"y": 0,
"width": 1400,
"height": 1200
},
"detection": {
"confidence_threshold": 0.9994
},
"alert": {
"show_rectangle": true,
"show_alert": true,
"play_sound": false
},
"overlay": {
"show_lines": true
}
}
118 changes: 118 additions & 0 deletions src/configurator/configurator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import sys
import os
import json
from PySide6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QLabel,
QSpinBox, QCheckBox, QPushButton, QHBoxLayout, QDoubleSpinBox
)

CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'config.json')


class Configurator(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Konfigurator")
self.setFixedSize(300, 300)

self.layout = QVBoxLayout()
self._load_config()

self.layout.addWidget(QLabel("Kadrowanie (x, y, szer, wys):"))
self.crop_x = QSpinBox()
self.crop_y = QSpinBox()
self.crop_w = QSpinBox()
self.crop_h = QSpinBox()
for box in [self.crop_x, self.crop_y, self.crop_w, self.crop_h]:
box.setRange(0, 1920)
self.crop_x.setValue(self.cfg.get("frame_crop", {}).get("x", 0))
self.crop_y.setValue(self.cfg.get("frame_crop", {}).get("y", 0))
self.crop_w.setValue(self.cfg.get("frame_crop", {}).get("width", 0))
self.crop_h.setValue(self.cfg.get("frame_crop", {}).get("height", 0))
row = QHBoxLayout()
for widget in [self.crop_x, self.crop_y, self.crop_w, self.crop_h]:
row.addWidget(widget)
self.layout.addLayout(row)

self.layout.addWidget(QLabel("Confidence threshold:"))
self.confidence = QDoubleSpinBox()
self.confidence.setRange(0.0001, 1.0000)
self.confidence.setDecimals(4)
self.confidence.setSingleStep(0.0001)
default_conf = self.cfg.get("detection", {}).get("confidence_threshold", 0.9991)
self.confidence.setValue(float(default_conf))
self.layout.addWidget(self.confidence)

self.rect_cb = QCheckBox("Ramka")
self.alert_cb = QCheckBox("Alert na ekranie")
self.sound_cb = QCheckBox("Dźwięk")

self.rect_cb.setChecked(self.cfg.get("alert", {}).get("show_rectangle", False))
self.alert_cb.setChecked(self.cfg.get("alert", {}).get("show_alert", False))
self.sound_cb.setChecked(self.cfg.get("alert", {}).get("play_sound", False))

self.layout.addWidget(self.rect_cb)
self.layout.addWidget(self.alert_cb)
self.layout.addWidget(self.sound_cb)

self.lines_cb = QCheckBox("Linie pomocnicze")
self.lines_cb.setChecked(self.cfg.get("overlay", {}).get("show_lines", False))
self.layout.addWidget(self.lines_cb)

self.save_btn = QPushButton("Zapisz")
self.save_btn.clicked.connect(self.save_config)
self.layout.addWidget(self.save_btn)

self.setLayout(self.layout)

def _load_config(self):
if os.path.exists(CONFIG_PATH):
try:
with open(CONFIG_PATH, 'r') as f:
self.cfg = json.load(f)
except Exception:
self.cfg = {}
else:
self.cfg = {}

def save_config(self):
config = {
"frame_crop": {
"x": self.crop_x.value(),
"y": self.crop_y.value(),
"width": self.crop_w.value(),
"height": self.crop_h.value()
},
"detection": {
"confidence_threshold": round(self.confidence.value(), 4)
},
"alert": {
"show_rectangle": self.rect_cb.isChecked(),
"show_alert": self.alert_cb.isChecked(),
"play_sound": self.sound_cb.isChecked()
},
"overlay": {
"show_lines": self.lines_cb.isChecked()
}
}
with open(CONFIG_PATH, 'w') as f:
json.dump(config, f, indent=4)
self.close()

@staticmethod
def load_user_config():
config_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'config.json'))
if os.path.exists(config_path):
try:
with open(config_path, 'r') as f:
return json.load(f)
except Exception as e:
print(f"Could not load user config: {e}")
return {}


if __name__ == "__main__":
app = QApplication(sys.argv)
window = Configurator()
window.show()
sys.exit(app.exec())
Binary file added src/data/model/kamil1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/data/model/kamil2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/data/model/kamil3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/data/model/kamil4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/data/model/michal.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading