Commit b2ee7d5c authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

[pre-commit] fix pre-commit complaints

parent 06c797fe
Pipeline #49168 passed with stages
in 4 minutes and 45 seconds
import math
import numbers
import tensorflow as tf
import math
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import GlobalAvgPool2D
def _check_input(
......@@ -164,7 +168,7 @@ def Normalize(mean, std=1.0, **kwargs):
class SphereFaceLayer(tf.keras.layers.Layer):
"""
r"""
Implements the SphereFace loss from equation (7) of `SphereFace: Deep Hypersphere Embedding for Face Recognition <https://arxiv.org/abs/1704.08063>`_
If the parameter `original` is set to `True` it will computes exactly what's written in eq (7): :math:`\\text{soft}(x_i) = \\frac{exp(||x_i||\\text{cos}(\\psi(\\theta_{yi})))}{exp(||x_i||\\text{cos}(\\psi(\\theta_{yi}))) + \sum_{j;j\\neq yi} exp(||x_i||\\text{cos}(\psi(\\theta_{j}))) }`.
......@@ -178,7 +182,7 @@ class SphereFaceLayer(tf.keras.layers.Layer):
m: float
Margin
"""
def __init__(self, n_classes=10, m=0.5):
......@@ -227,7 +231,7 @@ class ModifiedSoftMaxLayer(tf.keras.layers.Layer):
Parameters
----------
n_classes: int
Number of classes for the new logit function
"""
......@@ -256,15 +260,6 @@ class ModifiedSoftMaxLayer(tf.keras.layers.Layer):
return logits
from tensorflow.keras.layers import (
BatchNormalization,
Dropout,
Dense,
Concatenate,
GlobalAvgPool2D,
)
def add_bottleneck(model, bottleneck_size=128, dropout_rate=0.2):
"""
Amend a bottleneck layer to a Keras Model
......
from .alexnet import AlexNet_simplified
from .arcface import ArcFaceLayer
from .arcface import ArcFaceLayer3Penalties
from .arcface import ArcFaceModel
from .densenet import DeepPixBiS
from .densenet import DenseNet
from .densenet import densenet161 # noqa: F401
from .mine import MineModel
from .embedding_validation import EmbeddingValidation
from .arcface import ArcFaceLayer, ArcFaceLayer3Penalties, ArcFaceModel
from .mine import MineModel
# gets sphinx autodoc done right - don't remove it
def __appropriate__(*args):
......
import math
import tensorflow as tf
from .embedding_validation import EmbeddingValidation
from bob.learn.tensorflow.metrics.embedding_accuracy import accuracy_from_embeddings
import math
from .embedding_validation import EmbeddingValidation
class ArcFaceModel(EmbeddingValidation):
......@@ -48,10 +51,10 @@ class ArcFaceLayer(tf.keras.layers.Layer):
Number of classes
m: float
Margin
Margin
s: int
Scale
Scale
"""
def __init__(self, n_classes=10, s=30, m=0.5):
......@@ -102,9 +105,9 @@ class ArcFaceLayer(tf.keras.layers.Layer):
class ArcFaceLayer3Penalties(tf.keras.layers.Layer):
"""
Implements the ArcFace loss from equation (4) of `ArcFace: Additive Angular Margin Loss for Deep Face Recognition <https://arxiv.org/abs/1801.07698>`_
Defined as:
:math:`s(cos(m_1\\theta_i + m_2) -m_3`
"""
......@@ -148,4 +151,3 @@ class ArcFaceLayer3Penalties(tf.keras.layers.Layer):
logits = self.s * logits
return logits
import tensorflow as tf
from bob.learn.tensorflow.metrics.embedding_accuracy import accuracy_from_embeddings
class EmbeddingValidation(tf.keras.Model):
"""
Use this model if the validation step should validate the accuracy with respect to embeddings.
In this model, the `test_step` runs the function `bob.learn.tensorflow.metrics.embedding_accuracy.accuracy_from_embeddings`
"""
def compile(
self, **kwargs,
self,
**kwargs,
):
"""
Compile
......@@ -29,7 +31,6 @@ class EmbeddingValidation(tf.keras.Model):
logits, _ = self(X, training=True)
loss = self.loss(y, logits)
trainable_vars = self.trainable_variables
self.optimizer.minimize(loss, self.trainable_variables, tape=tape)
self.compiled_metrics.update_state(y, logits, sample_weight=None)
......
from bob.learn.tensorflow.models import (
EmbeddingValidation,
ArcFaceLayer,
ArcFaceModel,
ArcFaceLayer3Penalties,
)
from bob.learn.tensorflow.layers import (
SphereFaceLayer,
ModifiedSoftMaxLayer,
)
import numpy as np
from bob.learn.tensorflow.layers import ModifiedSoftMaxLayer
from bob.learn.tensorflow.layers import SphereFaceLayer
from bob.learn.tensorflow.models import ArcFaceLayer
from bob.learn.tensorflow.models import ArcFaceLayer3Penalties
def test_arcface_layer():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment