Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • amir
  • gan
  • integrate_structures
  • lstm
  • master
  • newlstm
  • oldmaster
  • predict
  • speed-up
  • tf20
  • towards_tf2
  • updates
  • 0.1.0
  • 0.1.1
  • 0.1.10
  • 0.1.2
  • 0.1.3
  • 0.1.4
  • 0.1.5
  • 0.1.6
  • 0.1.7
  • 0.1.8
  • 0.1.9
  • v0.0.1b1
  • v0.0.1b10
  • v0.0.1b11
  • v0.0.1b12
  • v0.0.1b13
  • v0.0.1b14
  • v0.0.1b15
  • v0.0.1b16
  • v0.0.1b2
  • v0.0.1b3
  • v0.0.1b4
  • v0.0.1b5
  • v0.0.1b6
  • v0.0.1b7
  • v0.0.1b8
  • v0.0.1b9
  • v1.0.0
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.0.4
  • v1.1.0
  • v1.1.1
  • v1.2.0
  • v1.2.1
  • v1.2.2b0
  • v2.0.0
  • v3.0.0
51 results

Target

Select target project
  • bob/bob.learn.tensorflow
1 result
Select Git revision
  • amir
  • gan
  • integrate_structures
  • lstm
  • master
  • newlstm
  • oldmaster
  • predict
  • speed-up
  • tf20
  • towards_tf2
  • updates
  • 0.1.0
  • 0.1.1
  • 0.1.10
  • 0.1.2
  • 0.1.3
  • 0.1.4
  • 0.1.5
  • 0.1.6
  • 0.1.7
  • 0.1.8
  • 0.1.9
  • v0.0.1b1
  • v0.0.1b10
  • v0.0.1b11
  • v0.0.1b12
  • v0.0.1b13
  • v0.0.1b14
  • v0.0.1b15
  • v0.0.1b16
  • v0.0.1b2
  • v0.0.1b3
  • v0.0.1b4
  • v0.0.1b5
  • v0.0.1b6
  • v0.0.1b7
  • v0.0.1b8
  • v0.0.1b9
  • v1.0.0
  • v1.0.1
  • v1.0.2
  • v1.0.3
  • v1.0.4
  • v1.1.0
  • v1.1.1
  • v1.2.0
  • v1.2.1
  • v1.2.2b0
  • v2.0.0
  • v3.0.0
51 results
Show changes
Commits on Source (7)
...@@ -2,16 +2,16 @@ ...@@ -2,16 +2,16 @@
# See https://pre-commit.com/hooks.html for more hooks # See https://pre-commit.com/hooks.html for more hooks
repos: repos:
- repo: https://github.com/timothycrosley/isort - repo: https://github.com/timothycrosley/isort
rev: 5.6.4 rev: 5.8.0
hooks: hooks:
- id: isort - id: isort
args: [--sl, --line-length, "88"] args: [--sl, --line-length, "88"]
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 20.8b1 rev: 20.8b1
hooks: hooks:
- id: black - id: black
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0 rev: v3.4.0
hooks: hooks:
- id: check-ast - id: check-ast
- id: check-case-conflict - id: check-case-conflict
...@@ -20,7 +20,7 @@ repos: ...@@ -20,7 +20,7 @@ repos:
- id: debug-statements - id: debug-statements
- id: check-added-large-files - id: check-added-large-files
- repo: https://gitlab.com/pycqa/flake8 - repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4 rev: 3.9.0
hooks: hooks:
- id: flake8 - id: flake8
args: [--ignore, "E203,W503,E501,E302,E111,E114,E121,E402"] args: [--ignore, "E203,W503,E501,E302,E111,E114,E121,E402"]
import math
import numbers import numbers
import tensorflow as tf 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( def _check_input(
...@@ -164,7 +168,7 @@ def Normalize(mean, std=1.0, **kwargs): ...@@ -164,7 +168,7 @@ def Normalize(mean, std=1.0, **kwargs):
class SphereFaceLayer(tf.keras.layers.Layer): 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>`_ 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}))) }`. 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): ...@@ -178,7 +182,7 @@ class SphereFaceLayer(tf.keras.layers.Layer):
m: float m: float
Margin Margin
""" """
def __init__(self, n_classes=10, m=0.5): def __init__(self, n_classes=10, m=0.5):
...@@ -227,7 +231,7 @@ class ModifiedSoftMaxLayer(tf.keras.layers.Layer): ...@@ -227,7 +231,7 @@ class ModifiedSoftMaxLayer(tf.keras.layers.Layer):
Parameters Parameters
---------- ----------
n_classes: int n_classes: int
Number of classes for the new logit function Number of classes for the new logit function
""" """
...@@ -256,15 +260,6 @@ class ModifiedSoftMaxLayer(tf.keras.layers.Layer): ...@@ -256,15 +260,6 @@ class ModifiedSoftMaxLayer(tf.keras.layers.Layer):
return logits return logits
from tensorflow.keras.layers import (
BatchNormalization,
Dropout,
Dense,
Concatenate,
GlobalAvgPool2D,
)
def add_bottleneck(model, bottleneck_size=128, dropout_rate=0.2): def add_bottleneck(model, bottleneck_size=128, dropout_rate=0.2):
""" """
Amend a bottleneck layer to a Keras Model Amend a bottleneck layer to a Keras Model
......
from .alexnet import AlexNet_simplified from .alexnet import AlexNet_simplified
from .arcface import ArcFaceLayer
from .arcface import ArcFaceLayer3Penalties
from .arcface import ArcFaceModel
from .densenet import DeepPixBiS from .densenet import DeepPixBiS
from .densenet import DenseNet from .densenet import DenseNet
from .densenet import densenet161 # noqa: F401 from .densenet import densenet161 # noqa: F401
from .mine import MineModel
from .embedding_validation import EmbeddingValidation from .embedding_validation import EmbeddingValidation
from .arcface import ArcFaceLayer, ArcFaceLayer3Penalties, ArcFaceModel from .mine import MineModel
# gets sphinx autodoc done right - don't remove it # gets sphinx autodoc done right - don't remove it
def __appropriate__(*args): def __appropriate__(*args):
......
import math
import tensorflow as tf import tensorflow as tf
from .embedding_validation import EmbeddingValidation
from bob.learn.tensorflow.metrics.embedding_accuracy import accuracy_from_embeddings from bob.learn.tensorflow.metrics.embedding_accuracy import accuracy_from_embeddings
import math
from .embedding_validation import EmbeddingValidation
class ArcFaceModel(EmbeddingValidation): class ArcFaceModel(EmbeddingValidation):
...@@ -48,10 +51,10 @@ class ArcFaceLayer(tf.keras.layers.Layer): ...@@ -48,10 +51,10 @@ class ArcFaceLayer(tf.keras.layers.Layer):
Number of classes Number of classes
m: float m: float
Margin Margin
s: int s: int
Scale Scale
""" """
def __init__(self, n_classes=10, s=30, m=0.5): def __init__(self, n_classes=10, s=30, m=0.5):
...@@ -102,9 +105,9 @@ class ArcFaceLayer(tf.keras.layers.Layer): ...@@ -102,9 +105,9 @@ class ArcFaceLayer(tf.keras.layers.Layer):
class ArcFaceLayer3Penalties(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>`_ 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: Defined as:
:math:`s(cos(m_1\\theta_i + m_2) -m_3` :math:`s(cos(m_1\\theta_i + m_2) -m_3`
""" """
...@@ -148,4 +151,3 @@ class ArcFaceLayer3Penalties(tf.keras.layers.Layer): ...@@ -148,4 +151,3 @@ class ArcFaceLayer3Penalties(tf.keras.layers.Layer):
logits = self.s * logits logits = self.s * logits
return logits return logits
import tensorflow as tf import tensorflow as tf
from bob.learn.tensorflow.metrics.embedding_accuracy import accuracy_from_embeddings from bob.learn.tensorflow.metrics.embedding_accuracy import accuracy_from_embeddings
class EmbeddingValidation(tf.keras.Model): class EmbeddingValidation(tf.keras.Model):
""" """
Use this model if the validation step should validate the accuracy with respect to embeddings. 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` In this model, the `test_step` runs the function `bob.learn.tensorflow.metrics.embedding_accuracy.accuracy_from_embeddings`
""" """
def compile( def compile(
self, **kwargs, self,
**kwargs,
): ):
""" """
Compile Compile
...@@ -29,7 +31,6 @@ class EmbeddingValidation(tf.keras.Model): ...@@ -29,7 +31,6 @@ class EmbeddingValidation(tf.keras.Model):
logits, _ = self(X, training=True) logits, _ = self(X, training=True)
loss = self.loss(y, logits) loss = self.loss(y, logits)
trainable_vars = self.trainable_variables
self.optimizer.minimize(loss, self.trainable_variables, tape=tape) self.optimizer.minimize(loss, self.trainable_variables, tape=tape)
self.compiled_metrics.update_state(y, logits, sample_weight=None) 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 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(): def test_arcface_layer():
......
[build-system]
requires = ["setuptools", "wheel", "bob.extension"]
build-backend = "setuptools.build_meta"
1.2.2b0 2.0.1b0