text:
# Python API¶

## Estimators¶

 Logits estimator. Logits estimator with center loss. NN estimator for Triplet networks. NN estimator for Siamese Networks. An estimator for regression problems Creates a callable that can be given to bob.learn.tensorflow.estimators A simple learning_rate_decay_fn.

## Architectures¶

 Class that creates the architecture presented in the paper: Creates the graph for the Light CNN-9 in bob.learn.tensorflow.network.dummy(inputs[, …]) Create all the necessary variables for this CNN bob.learn.tensorflow.network.mlp(inputs, …) An MLP is a representation of a Multi-Layer Perceptron. Creates the Inception Resnet V2 model. Creates the Inception Resnet V1 model. Creates the Inception Resnet V2 model applying batch not to each Convolutional and FullyConnected layer. Creates the Inception Resnet V1 model applying batch not to each Convolutional and FullyConnected layer. Oxford Net VGG 19-Layers version E Example from tf-slim Oxford Net VGG 16-Layers version E Example from tf-slim

## Data¶

 A generator class which wraps bob.bio.base databases so that they can be used with tf.data.Dataset.from_generator Dump random batches from a list of image paths and labels: Dump random batches for siamese networks from a list of image paths and labels: Dump random batches for triplee networks from a list of image paths and labels: Dump random batches from a list of tf-record files and applies some image augmentation Dump random batches from a list of tf-record files A generator class which wraps samples so that they can be used with tf.data.Dataset.from_generator Converts the image to channel_last format. Converts the image to channel_first format.

## Style Transfer¶

 Trains neural style transfer using the approach presented in:

## Losses¶

 Simple CrossEntropy loss. Implementation of the CrossEntropy + Center Loss from the paper “A Discriminative Feature Learning Approach for Deep Face Recognition”(http://ydwen.github.io/papers/WenECCV16.pdf) Compute the contrastive loss as in Compute the triplet loss as in Compute the triplet loss as in Implements the style loss from: Implements the content loss from: Computes the denoising loss as in: Computes weights that normalizes your loss per class. Computes weights that normalizes your loss per class.

## Detailed Information¶

bob.learn.tensorflow.get_config()[source]

Returns a string containing the configuration information.

bob.learn.tensorflow.estimators.check_features(features)[source]
bob.learn.tensorflow.estimators.get_trainable_variables(extra_checkpoint, mode='train')[source]

Given the extra_checkpoint dictionary provided to the estimator, extract the content of “trainable_variables”.

If trainable_variables is not provided, all end points are trainable by default. If trainable_variables==[], all end points are NOT trainable. If trainable_variables contains some end_points, ONLY these endpoints will be trainable.

bob.learn.tensorflow.estimators.extra_checkpoint

The extra_checkpoint dictionary provided to the estimator

Type

dict

bob.learn.tensorflow.estimators.mode

The estimator mode. TRAIN, EVAL, and PREDICT. If not TRAIN, None is returned.

Returns

• Returns None if trainable_variables is not in extra_checkpoint;

• otherwise returns the content of extra_checkpoint .

class bob.learn.tensorflow.estimators.Logits(architecture, optimizer, loss_op, n_classes, config=None, embedding_validation=False, model_dir='', validation_batch_size=None, params=None, extra_checkpoint=None, apply_moving_averages=True, add_histograms=None, vat_loss=None, architecture_has_logits=False, balanced_loss_weight=False, use_sigmoid=False, labels_are_one_hot=False, optimize_loss=<function optimize_loss>, optimize_loss_learning_rate=None)

Bases: tensorflow_estimator.python.estimator.estimator.Estimator

Logits estimator.

NN estimator with Cross entropy loss in the hot-encoded layer bob.learn.tensorflow.estimators.Logits.

The architecture function should follow the following pattern:

def my_beautiful_architecture(placeholder, **kwargs):

end_points = dict()
graph = convXX(placeholder)
end_points['conv'] = graph

return graph, end_points

The loss function should follow the following pattern:

def my_beautiful_loss(logits, labels, **kwargs):
return loss_set_of_ops(logits, labels)

architecture

Pointer to a function that builds the graph.

optimizer

One of the tensorflow solvers

config
n_classes

Number of classes of your problem. The logits will be appended in this class

loss_op

Pointer to a function that computes the loss.

embedding_validation

Run the validation using embeddings?? [default: False]

model_dir

Model path

validation_batch_size

Size of the batch for validation. This value is used when the validation with embeddings is used. This is a hack.

params

extra_checkpoint

In case you want to use other model to initialize some variables. This argument should be in the following format:

extra_checkpoint = {
"checkpoint_path": <YOUR_CHECKPOINT>,
"scopes": dict({"<SOURCE_SCOPE>/": "<TARGET_SCOPE>/"}),
"trainable_variables": [<LIST OF VARIABLES OR SCOPES THAT YOU WANT TO RETRAIN>]
}

Type

dict

apply_moving_averages

Apply exponential moving average in the training variables and in the loss. https://www.tensorflow.org/api_docs/python/tf/train/ExponentialMovingAverage By default the decay for the variable averages is 0.9999 and for the loss is 0.9

Type

bool

class bob.learn.tensorflow.estimators.LogitsCenterLoss(architecture=None, optimizer=None, config=None, n_classes=0, embedding_validation=False, model_dir='', alpha=0.9, factor=0.01, validation_batch_size=None, params=None, extra_checkpoint=None, apply_moving_averages=True, optimize_loss=<function optimize_loss>, optimize_loss_learning_rate=None)

Bases: tensorflow_estimator.python.estimator.estimator.Estimator

Logits estimator with center loss.

NN estimator with Cross entropy loss in the hot-encoded layer bob.learn.tensorflow.estimators.Logits plus the center loss implemented in: “Wen, Yandong, et al. “A discriminative feature learning approach for deep face recognition.” European Conference on Computer Vision. Springer, Cham, 2016.”

See Logits for the description of parameters.

class bob.learn.tensorflow.estimators.MovingAverageOptimizer(optimizer, **kwargs)

Bases: object

Creates a callable that can be given to bob.learn.tensorflow.estimators

This class is useful when you want to have a learning_rate_decay_fn and a moving average optimizer and use bob.learn.tensorflow.estimators

optimizer

A tf.train.Optimizer that is created and wrapped with tf.contrib.opt.MovingAverageOptimizer.

Type

object

Example

>>> import tensorflow as tf
>>> from bob.learn.tensorflow.estimators import MovingAverageOptimizer
>>> actual_optimizer = optimizer(lr=1e-3)
>>> isinstance(actual_optimizer, tf.train.Optimizer)
True
>>> actual_optimizer is optimizer.optimizer
True

class bob.learn.tensorflow.estimators.Regressor(architecture, optimizer=<tensorflow.python.training.adam.AdamOptimizer object>, loss_op=<function mean_squared_error>, label_dimension=1, config=None, model_dir=None, apply_moving_averages=True, add_regularization_losses=True, extra_checkpoint=None, add_histograms=None, optimize_loss=<function optimize_loss>, optimize_loss_learning_rate=None)

Bases: tensorflow_estimator.python.estimator.estimator.Estimator

An estimator for regression problems

class bob.learn.tensorflow.estimators.Siamese(architecture=None, optimizer=None, config=None, loss_op=None, model_dir='', validation_batch_size=None, params=None, extra_checkpoint=None, add_histograms=None, add_regularization_losses=True, optimize_loss=<function optimize_loss>, optimize_loss_learning_rate=None)

Bases: tensorflow_estimator.python.estimator.estimator.Estimator

NN estimator for Siamese Networks. Proposed in: “Chopra, Sumit, Raia Hadsell, and Yann LeCun. “Learning a similarity metric discriminatively, with application to face verification.” Computer Vision and Pattern Recognition, 2005. CVPR 2005. IEEE Computer Society Conference on. Vol. 1. IEEE, 2005.”

See Logits for the description of parameters.

class bob.learn.tensorflow.estimators.Triplet(architecture=None, optimizer=None, config=None, loss_op=<function triplet_loss>, model_dir='', validation_batch_size=None, extra_checkpoint=None, optimize_loss=<function optimize_loss>, optimize_loss_learning_rate=None)

Bases: tensorflow_estimator.python.estimator.estimator.Estimator

NN estimator for Triplet networks.

Schroff, Florian, Dmitry Kalenichenko, and James Philbin. “Facenet: A unified embedding for face recognition and clustering.” Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. 2015.

See Logits for the description of parameters.

bob.learn.tensorflow.estimators.learning_rate_decay_fn(learning_rate, global_step, decay_steps, decay_rate, staircase=False)[source]

A simple learning_rate_decay_fn.

To use it with tf.contrib.layer.optimize_loss:

>>> from bob.learn.tensorflow.estimators import learning_rate_decay_fn
>>> from functools import partial
>>> learning_rate_decay_fn = partial(
...     learning_rate_decay_fn,
...     decay_steps=1000,
...     decay_rate=0.9,
...     staircase=True,
... )

bob.learn.tensorflow.dataset.from_hdf5file_to_tensor(filename)[source]
bob.learn.tensorflow.dataset.from_filename_to_tensor(filename, extension=None)[source]

Read a file and it convert it to tensor.

If the file extension is something that tensorflow understands (.jpg, .bmp, .tif,…), it uses the tf.image.decode_image otherwise it uses bob.io.base.load

bob.learn.tensorflow.dataset.append_image_augmentation(image, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, random_gamma=False, random_crop=False)[source]

Append to the current tensor some random image augmentation operation

Parameters
gray_scale:

Convert to gray scale?

output_shape:

If set, will randomly crop the image given the output shape

random_flip:

Randomly flip an image horizontally (https://www.tensorflow.org/api_docs/python/tf/image/random_flip_left_right)

random_brightness:

Adjust the brightness of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_brightness)

random_contrast:

Adjust the contrast of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_contrast)

random_saturation:

Adjust the saturation of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_saturation)

random_rotate:

Randomly rotate face images between -5 and 5 degrees

per_image_normalization:

Linearly scales image to have zero mean and unit norm.

bob.learn.tensorflow.dataset.arrange_indexes_by_label(input_labels, possible_labels)[source]
bob.learn.tensorflow.dataset.triplets_random_generator(input_data, input_labels)[source]

Giving a list of samples and a list of labels, it dumps a series of triplets for triple nets.

Parameters

input_data: List of whatever representing the data samples

input_labels: List of the labels (needs to be in EXACT same order as input_data)

bob.learn.tensorflow.dataset.siamease_pairs_generator(input_data, input_labels)[source]

Giving a list of samples and a list of labels, it dumps a series of pairs for siamese nets.

Parameters

input_data: List of whatever representing the data samples

input_labels: List of the labels (needs to be in EXACT same order as input_data)

bob.learn.tensorflow.dataset.blocks_tensorflow(images, block_size)[source]

Return all non-overlapping blocks of an image using tensorflow operations.

Parameters
• images (tf.Tensor) – The input color images. It is assumed that the image has a shape of [?, H, W, C].

• block_size ((int, int)) – A tuple of two integers indicating the block size.

Returns

• blocks (tf.Tensor) – All the blocks in the batch dimension. The output will be of size [?, block_size[0], block_size[1], C].

• n_blocks (int) – The number of blocks that was obtained per image.

bob.learn.tensorflow.dataset.tf_repeat(tensor, repeats)[source]
Parameters
• tensor – A Tensor. 1-D or higher.

• repeats – A list. Number of repeat for each dimension, length must be the same as the number of dimensions in input

Returns

• A Tensor. Has the same type as input. Has the shape of tensor.shape *

• repeats

bob.learn.tensorflow.dataset.all_patches(image, label, key, size)[source]

Extracts all patches of an image

Parameters
• image – The image should be channels_last format and already batched.

• label – The label for the image

• key – The key for the image

• size ((int, int)) – The height and width of the blocks.

Returns

• blocks – The non-overlapping blocks of size from image and labels and keys are repeated.

• label

• key

class bob.learn.tensorflow.dataset.generator.Generator(samples, reader, multiple_samples=False, **kwargs)[source]

Bases: object

A generator class which wraps samples so that they can be used with tf.data.Dataset.from_generator

epoch

The number of epochs that have been passed so far.

Type

int

multiple_samples

If true, it assumes that the bio database’s samples actually contain multiple samples. This is useful for when you want to for example treat video databases as image databases.

Type

bool, optional

reader

A callable with the signature of data, label, key = reader(sample) which takes a sample and loads it.

Type

object, optional

samples

A list of samples to be given to reader to load the data.

Type
output_types

The types of the returned samples.

Type
output_shapes

The shapes of the returned samples.

Type

(tf.TensorShape, tf.TensorShape, tf.TensorShape)

property output_types
property output_shapes
bob.learn.tensorflow.dataset.generator.dataset_using_generator(*args, **kwargs)[source]

A generator class which wraps samples so that they can be used with tf.data.Dataset.from_generator

bob.learn.tensorflow.dataset.generator.samples

A list of samples to be given to reader to load the data.

Type
bob.learn.tensorflow.dataset.generator.reader

A callable with the signature of data, label, key = reader(sample) which takes a sample and loads it.

Type

object, optional

bob.learn.tensorflow.dataset.generator.multiple_samples

If true, it assumes that the bio database’s samples actually contain multiple samples. This is useful for when you want to for example treat video databases as image databases.

Type

bool, optional

class bob.learn.tensorflow.dataset.bio.BioGenerator(database, biofiles, load_data=None, biofile_to_label=None, multiple_samples=False, **kwargs)[source]

Bases: object

A generator class which wraps bob.bio.base databases so that they can be used with tf.data.Dataset.from_generator

biofile_to_label

A callable with the signature of label = biofile_to_label(biofile). By default -1 is returned as label.

Type

object, optional

biofiles

The list of the bio files .

Type
database

The database that you want to use.

Type

bob.bio.base.database.BioDatabase

epoch

The number of epochs that have been passed so far.

Type

int

keys

The keys of samples obtained by calling biofile.make_path("", "")

Type

[str]

labels

The labels obtained by calling label = biofile_to_label(biofile)

Type

[int]

load_data

A callable with the signature of data = load_data(database, biofile). bob.bio.base.read_original_data is wrapped to be used by default.

Type

object, optional

multiple_samples

If true, it assumes that the bio database’s samples actually contain multiple samples. This is useful for when you want to for example treat video databases as image databases.

Type

bool, optional

output_types

The types of the returned samples.

Type
output_shapes

The shapes of the returned samples.

Type

(tf.TensorShape, tf.TensorShape, tf.TensorShape)

property labels
property keys
property output_types
property output_shapes
bob.learn.tensorflow.dataset.image.shuffle_data_and_labels_image_augmentation(filenames, labels, data_shape, data_type, batch_size, epochs=None, buffer_size=1000, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, extension=None)[source]

Dump random batches from a list of image paths and labels:

The list of files and labels should be in the same order e.g. filenames = [‘class_1_img1’, ‘class_1_img2’, ‘class_2_img1’] labels = [0, 0, 1]

Parameters

filenames:

List containing the path of the images

labels:

List containing the labels (needs to be in EXACT same order as filenames)

data_shape:

Samples shape saved in the tf-record

data_type:
batch_size:

Size of the batch

epochs:

Number of epochs to be batched

buffer_size:

Size of the shuffle bucket

gray_scale:

Convert to gray scale?

output_shape:

If set, will randomly crop the image given the output shape

random_flip:

Randomly flip an image horizontally (https://www.tensorflow.org/api_docs/python/tf/image/random_flip_left_right)

random_brightness:

Adjust the brightness of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_brightness)

random_contrast:

Adjust the contrast of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_contrast)

random_saturation:

Adjust the saturation of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_saturation)

random_rotate:

Randomly rotate face images between -5 and 5 degrees

per_image_normalization:

Linearly scales image to have zero mean and unit norm.

extension:

bob.learn.tensorflow.dataset.image.create_dataset_from_path_augmentation(filenames, labels, data_shape, data_type, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, extension=None)[source]

Create dataset from a list of tf-record files

Parameters

filenames:

List containing the path of the images

labels:

List containing the labels (needs to be in EXACT same order as filenames)

data_shape:

Samples shape saved in the tf-record

data_type:

feature:

bob.learn.tensorflow.dataset.image.image_augmentation_parser(filename, label, data_shape, data_type, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, extension=None)[source]

Parses a single tf.Example into image and label tensors.

bob.learn.tensorflow.dataset.siamese_image.shuffle_data_and_labels_image_augmentation(filenames, labels, data_shape, data_type, batch_size, epochs=None, buffer_size=1000, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, extension=None)[source]

Dump random batches for siamese networks from a list of image paths and labels:

The list of files and labels should be in the same order e.g. filenames = [‘class_1_img1’, ‘class_1_img2’, ‘class_2_img1’] labels = [0, 0, 1]

The batches returned with tf.Session.run() with be in the following format: data a dictionary containing the keys [‘left’, ‘right’], each one representing one element of the pair and labels which is [0, 1] where 0 is the genuine pair and 1 is the impostor pair.

Parameters

filenames:

List containing the path of the images

labels:

List containing the labels (needs to be in EXACT same order as filenames)

data_shape:

Samples shape saved in the tf-record

data_type:
batch_size:

Size of the batch

epochs:

Number of epochs to be batched

buffer_size:

Size of the shuffle bucket

gray_scale:

Convert to gray scale?

output_shape:

If set, will randomly crop the image given the output shape

random_flip:

Randomly flip an image horizontally (https://www.tensorflow.org/api_docs/python/tf/image/random_flip_left_right)

random_brightness:

Adjust the brightness of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_brightness)

random_contrast:

Adjust the contrast of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_contrast)

random_saturation:

Adjust the saturation of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_saturation)

random_rotate:

Randomly rotate face images between -5 and 5 degrees

per_image_normalization:

Linearly scales image to have zero mean and unit norm.

extension:

bob.learn.tensorflow.dataset.siamese_image.create_dataset_from_path_augmentation(filenames, labels, data_shape, data_type, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, extension=None)[source]

Create dataset from a list of tf-record files

Parameters

filenames:

List containing the path of the images

labels:

List containing the labels (needs to be in EXACT same order as filenames)

data_shape:

Samples shape saved in the tf-record

data_type:
batch_size:

Size of the batch

epochs:

Number of epochs to be batched

buffer_size:

Size of the shuffle bucket

gray_scale:

Convert to gray scale?

output_shape:

If set, will randomly crop the image given the output shape

random_flip:

Randomly flip an image horizontally (https://www.tensorflow.org/api_docs/python/tf/image/random_flip_left_right)

random_brightness:

Adjust the brightness of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_brightness)

random_contrast:

Adjust the contrast of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_contrast)

random_saturation:

Adjust the saturation of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_saturation)

random_rotate:

Randomly rotate face images between -10 and 10 degrees

per_image_normalization:

Linearly scales image to have zero mean and unit norm.

extension:

bob.learn.tensorflow.dataset.siamese_image.image_augmentation_parser(filename_left, filename_right, label, data_shape, data_type, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, extension=None)[source]

Parses a single tf.Example into image and label tensors.

bob.learn.tensorflow.dataset.triplet_image.shuffle_data_and_labels_image_augmentation(filenames, labels, data_shape, data_type, batch_size, epochs=None, buffer_size=1000, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, extension=None)[source]

Dump random batches for triplee networks from a list of image paths and labels:

The list of files and labels should be in the same order e.g. filenames = [‘class_1_img1’, ‘class_1_img2’, ‘class_2_img1’] labels = [0, 0, 1]

The batches returned with tf.Session.run() with be in the following format: data a dictionary containing the keys [‘anchor’, ‘positive’, ‘negative’].

Parameters

filenames:

List containing the path of the images

labels:

List containing the labels (needs to be in EXACT same order as filenames)

data_shape:

Samples shape saved in the tf-record

data_type:
batch_size:

Size of the batch

epochs:

Number of epochs to be batched

buffer_size:

Size of the shuffle bucket

gray_scale:

Convert to gray scale?

output_shape:

If set, will randomly crop the image given the output shape

random_flip:

Randomly flip an image horizontally (https://www.tensorflow.org/api_docs/python/tf/image/random_flip_left_right)

random_brightness:

Adjust the brightness of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_brightness)

random_contrast:

Adjust the contrast of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_contrast)

random_saturation:

Adjust the saturation of an RGB image by a random factor (https://www.tensorflow.org/api_docs/python/tf/image/random_saturation)

random_rotate:

Randomly rotate face images between -5 and 5 degrees

per_image_normalization:

Linearly scales image to have zero mean and unit norm.

extension:

bob.learn.tensorflow.dataset.triplet_image.create_dataset_from_path_augmentation(filenames, labels, data_shape, data_type=tf.float32, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, extension=None)[source]

Create dataset from a list of tf-record files

Parameters

filenames:

List containing the path of the images

labels:

List containing the labels (needs to be in EXACT same order as filenames)

data_shape:

Samples shape saved in the tf-record

data_type:

feature:

bob.learn.tensorflow.dataset.triplet_image.image_augmentation_parser(anchor, positive, negative, data_shape, data_type=tf.float32, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, extension=None)[source]

Parses a single tf.Example into image and label tensors.

Utilities for TFRecords

bob.learn.tensorflow.dataset.tfrecords.tfrecord_name_and_json_name(output)[source]
bob.learn.tensorflow.dataset.tfrecords.normalize_tfrecords_path(output)[source]
bob.learn.tensorflow.dataset.tfrecords.bytes_feature(value)[source]
bob.learn.tensorflow.dataset.tfrecords.int64_feature(value)[source]
bob.learn.tensorflow.dataset.tfrecords.dataset_to_tfrecord(dataset, output)[source]

Writes a tf.data.Dataset into a TFRecord file.

Parameters
• dataset (tf.data.Dataset) – The tf.data.Dataset that you want to write into a TFRecord file.

• output (str) – Path to the TFRecord file. Besides this file, a .json file is also created. This json file is needed when you want to convert the TFRecord file back into a dataset.

Returns

A tf.Operation that, when run, writes contents of dataset to a file. When running in eager mode, calling this function will write the file. Otherwise, you have to call session.run() on the returned operation.

Return type

tf.Operation

bob.learn.tensorflow.dataset.tfrecords.dataset_from_tfrecord(tfrecord)[source]

Reads TFRecords and returns a dataset. The TFRecord file must have been created using the dataset_to_tfrecord function.

Parameters

tfrecord (str or list) – Path to the TFRecord file. Pass a list if you are sure several tfrecords need the same map function.

Returns

A dataset that contains the data from the TFRecord file.

Return type

tf.data.Dataset

bob.learn.tensorflow.dataset.tfrecords.write_a_sample(writer, data, label, key, feature=None, size_estimate=False)[source]
bob.learn.tensorflow.dataset.tfrecords.example_parser(serialized_example, feature, data_shape, data_type)[source]

Parses a single tf.Example into image and label tensors.

bob.learn.tensorflow.dataset.tfrecords.image_augmentation_parser(serialized_example, feature, data_shape, data_type, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, random_gamma=False, random_crop=False)[source]

Parses a single tf.Example into image and label tensors.

bob.learn.tensorflow.dataset.tfrecords.read_and_decode(filename_queue, data_shape, data_type=tf.float32, feature=None)[source]

Simples parse possible for a tfrecord. It assumes that you have the pair train/data and train/label

bob.learn.tensorflow.dataset.tfrecords.create_dataset_from_records(tfrecord_filenames, data_shape, data_type, feature=None)[source]

Create dataset from a list of tf-record files

Parameters

tfrecord_filenames:

List containing the tf-record paths

data_shape:

Samples shape saved in the tf-record

data_type:

feature:

bob.learn.tensorflow.dataset.tfrecords.create_dataset_from_records_with_augmentation(tfrecord_filenames, data_shape, data_type, feature=None, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, random_gamma=False, random_crop=False)[source]

Create dataset from a list of tf-record files

Parameters

tfrecord_filenames:

List containing the tf-record paths

data_shape:

Samples shape saved in the tf-record

data_type:

feature:

bob.learn.tensorflow.dataset.tfrecords.shuffle_data_and_labels_image_augmentation(tfrecord_filenames, data_shape, data_type, batch_size, epochs=None, buffer_size=1000, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, random_gamma=False, random_crop=False, drop_remainder=False)[source]

Dump random batches from a list of tf-record files and applies some image augmentation

Parameters
bob.learn.tensorflow.dataset.tfrecords.shuffle_data_and_labels(tfrecord_filenames, data_shape, data_type, batch_size, epochs=None, buffer_size=1000)[source]

Dump random batches from a list of tf-record files

Parameters

tfrecord_filenames:

List containing the tf-record paths

data_shape:

Samples shape saved in the tf-record

data_type:
batch_size:

Size of the batch

epochs:

Number of epochs to be batched

buffer_size:

Size of the shuffle bucket

bob.learn.tensorflow.dataset.tfrecords.batch_data_and_labels(tfrecord_filenames, data_shape, data_type, batch_size, epochs=1)[source]

Dump in order batches from a list of tf-record files

Parameters
bob.learn.tensorflow.dataset.tfrecords.batch_data_and_labels_image_augmentation(tfrecord_filenames, data_shape, data_type, batch_size, epochs=1, gray_scale=False, output_shape=None, random_flip=False, random_brightness=False, random_contrast=False, random_saturation=False, random_rotate=False, per_image_normalization=True, random_gamma=False, random_crop=False, drop_remainder=False)[source]

Dump in order batches from a list of tf-record files

Parameters
• tfrecord_filenames – List containing the tf-record paths

• data_shape – Samples shape saved in the tf-record

• data_type – tf data type(https://www.tensorflow.org/versions/r0.12/resources/dims_types#data_types)

• batch_size – Size of the batch

• epochs – Number of epochs to be batched

• drop_remainder – If True, the last remaining batch that has smaller size than batch_size will be dropped.

bob.learn.tensorflow.dataset.tfrecords.describe_tf_record(tf_record_path, shape, batch_size=1)[source]

Describe the number of samples and the number of classes of a tf-record

Parameters
• tf_record_path (str) – Base path containing your tf-record files

• shape (tuple) – Shape inside of the tf-record

• batch_size (int) – Well, batch size

Returns

• n_samples (int) – Total number of samples

• n_classes (int) – Total number of classes

bob.learn.tensorflow.network.chopra(inputs, conv1_kernel_size=[7, 7], conv1_output=15, pooling1_size=[2, 2], conv2_kernel_size=[6, 6], conv2_output=45, pooling2_size=[4, 3], fc1_output=250, seed=10, reuse=False)

Class that creates the architecture presented in the paper:

Chopra, Sumit, Raia Hadsell, and Yann LeCun. “Learning a similarity metric discriminatively, with application to face verification.” 2005 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR’05). Vol. 1. IEEE, 2005.

This is modifield version of the original architecture. It is inspired on https://gitlab.idiap.ch/bob/xfacereclib.cnn/blob/master/lua/network.lua

– C1 : Convolutional, kernel = 7x7 pixels, 15 feature maps

– M2 : MaxPooling, 2x2

– HT : Hard Hyperbolic Tangent

– C3 : Convolutional, kernel = 6x6 pixels, 45 feature maps

– M4 : MaxPooling, 4x3

– HT : Hard Hyperbolic Tangent

– R : Reshaping layer HT 5x5 => 25 (45 times; once for each feature map)

– L5 : Linear 25 => 250

Parameters

conv1_kernel_size:

conv1_output:

pooling1_size:

conv2_kernel_size:

conv2_output:

pooling2_size

fc1_output:

seed:

bob.learn.tensorflow.network.dummy(inputs, reuse=False, mode='train', trainable_variables=None, **kwargs)

Create all the necessary variables for this CNN

Parameters
• inputs

• reuse

• mode

• trainable_variables

bob.learn.tensorflow.network.inception_resnet_v1(inputs, dropout_keep_prob=0.8, bottleneck_layer_size=128, reuse=None, scope='InceptionResnetV1', mode='train', trainable_variables=None, **kwargs)

Creates the Inception Resnet V1 model.

Parameters
• inputs – 4-D tensor of size [batch_size, height, width, 3].

• num_classes – number of predicted classes.

• is_training – whether is training or not.

• dropout_keep_prob (float) – the fraction to keep before final layer.

• reuse – whether or not the network and its variables should be reused. To be able to reuse ‘scope’ must be given.

• scope – Optional variable_scope.

• trainable_variables (list) – List of variables to be trainable=True

Returns

• logits – the logits outputs of the model.

• end_points – the set of end_points from the inception model.

bob.learn.tensorflow.network.inception_resnet_v1_batch_norm(inputs, dropout_keep_prob=0.8, bottleneck_layer_size=128, reuse=None, scope='InceptionResnetV1', mode='train', trainable_variables=None, weight_decay=1e-05, **kwargs)

Creates the Inception Resnet V1 model applying batch not to each Convolutional and FullyConnected layer.

Parameters
• inputs – 4-D tensor of size [batch_size, height, width, 3].

• num_classes – number of predicted classes.

• is_training – whether is training or not.

• dropout_keep_prob (float) – the fraction to keep before final layer.

• reuse – whether or not the network and its variables should be reused. To be able to reuse ‘scope’ must be given.

• scope – Optional variable_scope.

• trainable_variables (list) – List of variables to be trainable=True

Returns

• logits – the logits outputs of the model.

• end_points – the set of end_points from the inception model.

bob.learn.tensorflow.network.inception_resnet_v2(inputs, dropout_keep_prob=0.8, bottleneck_layer_size=128, reuse=None, scope='InceptionResnetV2', mode='train', trainable_variables=None, **kwargs)

Creates the Inception Resnet V2 model.

Parameters
• inputs – 4-D tensor of size [batch_size, height, width, 3].

• num_classes – number of predicted classes.

• is_training – whether is training or not.

• dropout_keep_prob (float) – the fraction to keep before final layer.

• reuse – whether or not the network and its variables should be reused. To be able to reuse ‘scope’ must be given.

• scope – Optional variable_scope.

• trainable_variables (list) – List of variables to be trainable=True

Returns

• logits – the logits outputs of the model.

• end_points – the set of end_points from the inception model.

bob.learn.tensorflow.network.inception_resnet_v2_batch_norm(inputs, dropout_keep_prob=0.8, bottleneck_layer_size=128, reuse=None, scope='InceptionResnetV2', mode='train', trainable_variables=None, weight_decay=5e-05, **kwargs)

Creates the Inception Resnet V2 model applying batch not to each Convolutional and FullyConnected layer.

Parameters:

inputs:

4-D tensor of size [batch_size, height, width, 3].

num_classes:

number of predicted classes.

is_training:

whether is training or not.

dropout_keep_prob: float

the fraction to keep before final layer.

reuse:

whether or not the network and its variables should be reused. To be able to reuse ‘scope’ must be given.

scope:

Optional variable_scope.

trainable_variables: list

List of variables to be trainable=True

Returns:

logits:

the logits outputs of the model.

end_points:

the set of end_points from the inception model.

bob.learn.tensorflow.network.light_cnn9(inputs, seed=10, reuse=False, trainable_variables=None, **kwargs)

Creates the graph for the Light CNN-9 in

Wu, Xiang, et al. “A light CNN for deep face representation with noisy labels.” arXiv preprint arXiv:1511.02683 (2015).

bob.learn.tensorflow.network.mlp(inputs, output_shape, hidden_layers=[10], hidden_activation=<function tanh>, output_activation=None, seed=10, **kwargs)

An MLP is a representation of a Multi-Layer Perceptron.

This implementation is feed-forward and fully-connected. The implementation allows setting a global and the output activation functions. References to fully-connected feed-forward networks: Bishop’s Pattern Recognition and Machine Learning, Chapter 5. Figure 5.1 shows what is programmed.

MLPs normally are multi-layered systems, with 1 or more hidden layers.

Parameters

output_shape: number of neurons in the output.

hidden_layers: list that contains the amount of hidden layers, where each element is the number of neurons

hidden_activation: Activation function of the hidden layers. Possible values can be seen
here.

If you set to None, the activation will be linear.

output_activation: Activation of the output layer. If you set to None, the activation will be linear

seed:

bob.learn.tensorflow.network.mlp_with_batchnorm_and_dropout(inputs, fully_connected_layers, mode='train', trainable_variables=None, **kwargs)[source]
bob.learn.tensorflow.network.vgg_16(inputs, reuse=None, mode='train', trainable_variables=None, scope='vgg_16', **kwargs)

Oxford Net VGG 16-Layers version E Example from tf-slim

https://raw.githubusercontent.com/tensorflow/models/master/research/slim/nets/vgg.py

Parameters:

inputs: a 4-D tensor of size [batch_size, height, width, 3].

reuse: whether or not the network and its variables should be reused. To be

able to reuse ‘scope’ must be given.

mode:

Estimator mode keys

bob.learn.tensorflow.network.vgg_19(inputs, reuse=None, mode='train', **kwargs)

Oxford Net VGG 19-Layers version E Example from tf-slim

https://raw.githubusercontent.com/tensorflow/models/master/research/slim/nets/vgg.py

Parameters:

inputs: a 4-D tensor of size [batch_size, height, width, 3].

reuse: whether or not the network and its variables should be reused. To be

able to reuse ‘scope’ must be given.

mode:

Estimator mode keys

The network using keras (same as new_architecture function below):

from tensorflow.python.keras import *
from tensorflow.python.keras.layers import *
simplecnn = Sequential([
BatchNormalization(scale=False),
Activation('relu'),
BatchNormalization(scale=False),
Activation('relu'),
Flatten(),
Dense(1024, use_bias=False),
BatchNormalization(scale=False),
Activation('relu'),
Dropout(rate=0.4),
Dense(2),
])
simplecnn.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
conv2d_1 (Conv2D)            (None, 28, 28, 32)        864
_________________________________________________________________
batch_normalization_1 (Batch (None, 28, 28, 32)        96
_________________________________________________________________
activation_1 (Activation)    (None, 28, 28, 32)        0
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 14, 14, 32)        0
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 14, 14, 64)        18432
_________________________________________________________________
batch_normalization_2 (Batch (None, 14, 14, 64)        192
_________________________________________________________________
activation_2 (Activation)    (None, 14, 14, 64)        0
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 7, 7, 64)          0
_________________________________________________________________
flatten_1 (Flatten)          (None, 3136)              0
_________________________________________________________________
dense_1 (Dense)              (None, 1024)              3211264
_________________________________________________________________
batch_normalization_3 (Batch (None, 1024)              3072
_________________________________________________________________
activation_3 (Activation)    (None, 1024)              0
_________________________________________________________________
dropout_1 (Dropout)          (None, 1024)              0
_________________________________________________________________
dense_2 (Dense)              (None, 2)                 2050
=================================================================
Total params: 3,235,970
Trainable params: 3,233,730
Non-trainable params: 2,240
_________________________________________________________________

bob.learn.tensorflow.network.SimpleCNN.architecture(input_layer, mode='train', kernerl_size=(3, 3), n_classes=2, data_format='channels_last', reuse=False, add_batch_norm=False, trainable_variables=None, **kwargs)[source]
bob.learn.tensorflow.network.SimpleCNN.base_architecture(input_layer, mode='train', kernerl_size=(3, 3), data_format='channels_last', add_batch_norm=False, trainable_variables=None, use_bias_with_batch_norm=True, **kwargs)[source]
bob.learn.tensorflow.network.SimpleCNN.create_conv_layer(inputs, mode, data_format, endpoints, number, filters, kernel_size, pool_size, pool_strides, add_batch_norm=False, trainable_variables=None, use_bias_with_batch_norm=True)[source]
bob.learn.tensorflow.network.SimpleCNN.model_fn(features, labels, mode, params=None, config=None)[source]

Model function for CNN.

bob.learn.tensorflow.network.SimpleCNN.new_architecture(input_layer, mode='train', kernerl_size=(3, 3), data_format='channels_last', add_batch_norm=True, trainable_variables=None, use_bias_with_batch_norm=False, reuse=False, **kwargs)[source]
bob.learn.tensorflow.network.SimpleCNN.slim_architecture(input_layer, mode='train', kernerl_size=(3, 3), data_format='channels_last', add_batch_norm=True, trainable_variables=None, use_bias_with_batch_norm=False, reuse=False, **kwargs)[source]
bob.learn.tensorflow.utils.util.keras_channels_index()[source]
bob.learn.tensorflow.utils.util.compute_euclidean_distance(x, y)[source]

Computes the euclidean distance between two tensorflow variables

bob.learn.tensorflow.utils.util.load_mnist(perc_train=0.9)[source]
bob.learn.tensorflow.utils.util.create_mnist_tfrecord(tfrecords_filename, data, labels, n_samples=6000)[source]
bob.learn.tensorflow.utils.util.compute_eer(data_train, labels_train, data_validation, labels_validation, n_classes)[source]
bob.learn.tensorflow.utils.util.compute_accuracy(data_train, labels_train, data_validation, labels_validation, n_classes)[source]
bob.learn.tensorflow.utils.util.debug_embbeding(image, architecture, embbeding_dim=2, feature_layer='fc3')[source]
bob.learn.tensorflow.utils.util.pdist(A)[source]

Compute a pairwise euclidean distance in the same fashion as in scipy.spation.distance.pdist

bob.learn.tensorflow.utils.util.predict_using_tensors(embedding, labels, num=None)[source]

Compute the predictions through exhaustive comparisons between embeddings using tensors

bob.learn.tensorflow.utils.util.compute_embedding_accuracy_tensors(embedding, labels, num=None)[source]

Compute the accuracy in a closed-set

Parameters

embeddings: tf.Tensor

Set of embeddings

labels: tf.Tensor

Correspondent labels

bob.learn.tensorflow.utils.util.compute_embedding_accuracy(embedding, labels)[source]

Compute the accuracy in a closed-set

Parameters

embeddings: numpy.array

Set of embeddings

labels: numpy.array

Correspondent labels

bob.learn.tensorflow.utils.util.get_available_gpus()[source]

Returns the number of GPU devices that are available.

Returns

The names of available GPU devices.

Return type

[str]

bob.learn.tensorflow.utils.util.to_channels_last(image)[source]

Converts the image to channel_last format. This is the same format as in matplotlib, skimage, and etc.

Parameters

image (tf.Tensor) – At least a 3 dimensional image. If the dimension is more than 3, the last 3 dimensions are assumed to be [C, H, W].

Returns

image – The image in […, H, W, C] format.

Return type

tf.Tensor

Raises

ValueError – If dim of image is less than 3.

bob.learn.tensorflow.utils.util.to_channels_first(image)[source]

Converts the image to channel_first format. This is the same format as in bob.io.image and bob.io.video.

Parameters

image (tf.Tensor) – At least a 3 dimensional image. If the dimension is more than 3, the last 3 dimensions are assumed to be [H, W, C].

Returns

image – The image in […, C, H, W] format.

Return type

tf.Tensor

Raises

ValueError – If dim of image is less than 3.

bob.learn.tensorflow.utils.util.to_skimage(image)

Converts the image to channel_last format. This is the same format as in matplotlib, skimage, and etc.

Parameters

image (tf.Tensor) – At least a 3 dimensional image. If the dimension is more than 3, the last 3 dimensions are assumed to be [C, H, W].

Returns

image – The image in […, H, W, C] format.

Return type

tf.Tensor

Raises

ValueError – If dim of image is less than 3.

bob.learn.tensorflow.utils.util.to_matplotlib(image)

Converts the image to channel_last format. This is the same format as in matplotlib, skimage, and etc.

Parameters

image (tf.Tensor) – At least a 3 dimensional image. If the dimension is more than 3, the last 3 dimensions are assumed to be [C, H, W].

Returns

image – The image in […, H, W, C] format.

Return type

tf.Tensor

Raises

ValueError – If dim of image is less than 3.

bob.learn.tensorflow.utils.util.to_bob(image)

Converts the image to channel_first format. This is the same format as in bob.io.image and bob.io.video.

Parameters

image (tf.Tensor) – At least a 3 dimensional image. If the dimension is more than 3, the last 3 dimensions are assumed to be [H, W, C].

Returns

image – The image in […, C, H, W] format.

Return type

tf.Tensor

Raises

ValueError – If dim of image is less than 3.

bob.learn.tensorflow.utils.util.bytes2human(n, format='%(value).1f %(symbol)s', symbols='customary')[source]

Convert n bytes into a human readable string based on format. From: https://code.activestate.com/recipes/578019-bytes-to-human-human-to- bytes-converter/ Author: Giampaolo Rodola’ <g.rodola [AT] gmail [DOT] com> License: MIT symbols can be either “customary”, “customary_ext”, “iec” or “iec_ext”, see: http://goo.gl/kTQMs

bob.learn.tensorflow.style_transfer.compute_features(input_image, architecture, checkpoint_dir, target_end_points, preprocess_fn=None)[source]

For a given set of end_points, convolve the input image until these points

Parameters
• input_image (numpy.array) – Input image in the format WxHxC

• architecture – Pointer to the architecture function

• checkpoint_dir (str) – DCNN checkpoint directory

• end_points (dict) – Dictionary containing the end point tensors

• preprocess_fn – Pointer to a preprocess function

bob.learn.tensorflow.style_transfer.compute_gram(features)[source]

Given a list of features (as numpy.arrays) comput the gram matrices of each pinning the channel as in:

Gatys, Leon A., Alexander S. Ecker, and Matthias Bethge. “A neural algorithm of artistic style.” arXiv preprint arXiv:1508.06576 (2015).

Parameters

features (numpy.array) – Convolved features in the format NxWxHxC

bob.learn.tensorflow.style_transfer.do_style_transfer(content_image, style_images, architecture, checkpoint_dir, scopes, content_end_points, style_end_points, preprocess_fn=None, un_preprocess_fn=None, pure_noise=False, iterations=1000, learning_rate=0.1, content_weight=5.0, style_weight=500.0, denoise_weight=500.0)[source]

Trains neural style transfer using the approach presented in:

Gatys, Leon A., Alexander S. Ecker, and Matthias Bethge. “A neural algorithm of artistic style.” arXiv preprint arXiv:1508.06576 (2015).

Parameters
• content_image (numpy.array) – Content image in the Bob format (C x W x H)

• style_images (list) – List of numpy.array (Bob format (C x W x H)) that encodes the style

• architecture – Point to a function with the base architecture

• checkpoint_dir – CNN checkpoint path

• scopes – Dictionary containing the mapping scores

• content_end_points – List of end_points (from the architecture) for the used to encode the content

• style_end_points – List of end_points (from the architecture) for the used to encode the style

• preprocess_fn – Preprocess function. Pointer to a function that preprocess the INPUT signal

• unpreprocess_fn – Un preprocess function. Pointer to a function that preprocess the OUTPUT signal

• pure_noise – If set will save the raw noisy generated image. If not set, the output will be RGB = stylizedYUV.Y, originalYUV.U, originalYUV.V

• iterations – Number of iterations to generate the image

• learning_rate – Adam learning rate

• content_weight – Weight of the content loss

• style_weight – Weight of the style loss

• denoise_weight – Weight denoising loss

class bob.learn.tensorflow.loss.VATLoss(epsilon=8.0, xi=1e-06, num_power_iterations=1, method='vatent', **kwargs)[source]

Bases: object

A class to hold parameters for Virtual Adversarial Training (VAT) Loss and perform it.

epsilon

norm length for (virtual) adversarial training

Type

float

method

The method for calculating the loss: vatent for VAT loss + entropy and vat for only VAT loss.

Type

str

num_power_iterations

the number of power iterations

Type

int

xi

small constant for finite difference

Type

float

virtual_adversarial_loss(features, logits, architecture, mode, name='vat_loss')[source]
generate_virtual_adversarial_perturbation(features, logits, architecture, mode)[source]
bob.learn.tensorflow.loss.balanced_sigmoid_cross_entropy_loss_weights(labels, dtype='float32')[source]

Computes weights that normalizes your loss per class.

Labels must be a batch of binary labels. The function takes labels and computes the weights per batch. Weights will be smaller for the class that have more samples in this batch. This is useful if you unbalanced classes in your dataset or batch.

Parameters
• labels (tf.Tensor) – Labels of your current input. The shape must be [batch_size] and values must be either 0 or 1.

• dtype (tf.dtype) – The dtype that weights will have. It should be float. Best is to provide logits.dtype as input.

Returns

Computed weights that will cancel your dataset imbalance per batch.

Return type

tf.Tensor

Examples

>>> import numpy
>>> import tensorflow as tf
>>> from bob.learn.tensorflow.loss import balanced_sigmoid_cross_entropy_loss_weights
>>> labels = numpy.array([1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0,
...                 1, 1, 0, 1, 1, 1, 0, 1, 0, 1], dtype="int32")
>>> sum(labels), len(labels)
(20, 32)
>>> session = tf.Session() # Eager execution is also possible check https://www.tensorflow.org/guide/eager
>>> session.run(balanced_sigmoid_cross_entropy_loss_weights(labels, dtype='float32'))
array([0.8      , 0.8      , 1.3333334, 1.3333334, 1.3333334, 0.8      ,
0.8      , 1.3333334, 0.8      , 0.8      , 0.8      , 0.8      ,
0.8      , 0.8      , 1.3333334, 0.8      , 1.3333334, 0.8      ,
1.3333334, 1.3333334, 0.8      , 1.3333334, 0.8      , 0.8      ,
1.3333334, 0.8      , 0.8      , 0.8      , 1.3333334, 0.8      ,
1.3333334, 0.8      ], dtype=float32)

You would use it like this:

>>> #weights = balanced_sigmoid_cross_entropy_loss_weights(labels, dtype=logits.dtype)
>>> #loss = tf.losses.sigmoid_cross_entropy(logits=logits, labels=labels, weights=weights)

bob.learn.tensorflow.loss.balanced_softmax_cross_entropy_loss_weights(labels, dtype='float32')[source]

Computes weights that normalizes your loss per class.

Labels must be a batch of one-hot encoded labels. The function takes labels and computes the weights per batch. Weights will be smaller for classes that have more samples in this batch. This is useful if you unbalanced classes in your dataset or batch.

Parameters
• labels (tf.Tensor) – Labels of your current input. The shape must be [batch_size, n_classes]. If your labels are not one-hot encoded, you can use tf.one_hot to convert them first before giving them to this function.

• dtype (tf.dtype) – The dtype that weights will have. It should be float. Best is to provide logits.dtype as input.

Returns

Computed weights that will cancel your dataset imbalance per batch.

Return type

tf.Tensor

Examples

>>> import numpy
>>> import tensorflow as tf
>>> from bob.learn.tensorflow.loss import balanced_softmax_cross_entropy_loss_weights
>>> labels = numpy.array([[1, 0, 0],
...                 [1, 0, 0],
...                 [0, 0, 1],
...                 [0, 1, 0],
...                 [0, 0, 1],
...                 [1, 0, 0],
...                 [1, 0, 0],
...                 [0, 0, 1],
...                 [1, 0, 0],
...                 [1, 0, 0],
...                 [1, 0, 0],
...                 [1, 0, 0],
...                 [1, 0, 0],
...                 [1, 0, 0],
...                 [0, 1, 0],
...                 [1, 0, 0],
...                 [0, 1, 0],
...                 [1, 0, 0],
...                 [0, 0, 1],
...                 [0, 0, 1],
...                 [1, 0, 0],
...                 [0, 0, 1],
...                 [1, 0, 0],
...                 [1, 0, 0],
...                 [0, 1, 0],
...                 [1, 0, 0],
...                 [1, 0, 0],
...                 [1, 0, 0],
...                 [0, 1, 0],
...                 [1, 0, 0],
...                 [0, 0, 1],
...                 [1, 0, 0]], dtype="int32")
>>> session = tf.Session() # Eager execution is also possible check https://www.tensorflow.org/guide/eager
>>> session.run(tf.reduce_sum(labels, axis=0))
array([20,  5,  7], dtype=int32)
>>> session.run(balanced_softmax_cross_entropy_loss_weights(labels, dtype='float32'))
array([0.53333336, 0.53333336, 1.5238096 , 2.1333334 , 1.5238096 ,
0.53333336, 0.53333336, 1.5238096 , 0.53333336, 0.53333336,
0.53333336, 0.53333336, 0.53333336, 0.53333336, 2.1333334 ,
0.53333336, 2.1333334 , 0.53333336, 1.5238096 , 1.5238096 ,
0.53333336, 1.5238096 , 0.53333336, 0.53333336, 2.1333334 ,
0.53333336, 0.53333336, 0.53333336, 2.1333334 , 0.53333336,
1.5238096 , 0.53333336], dtype=float32)

You would use it like this:

>>> #weights = balanced_softmax_cross_entropy_loss_weights(labels, dtype=logits.dtype)
>>> #loss = tf.losses.softmax_cross_entropy(logits=logits, labels=labels, weights=weights)

bob.learn.tensorflow.loss.content_loss(noises, content_features)[source]

Implements the content loss from:

Gatys, Leon A., Alexander S. Ecker, and Matthias Bethge. “A neural algorithm of artistic style.” arXiv preprint arXiv:1508.06576 (2015).

For a given noise signal $$n$$, content image $$c$$ and convolved with the DCNN $$\phi$$ until the layer $$l$$ the content loss is defined as:

$$L(n,c) = \sum_{l=?}^{?}({\phi^l(n) - \phi^l(c)})^2$$

Parameters
• noises (list) – A list of tf.Tensor containing all the noises convolved

• content_features (list) – A list of numpy.array containing all the content_features convolved

bob.learn.tensorflow.loss.contrastive_loss(left_embedding, right_embedding, labels, contrastive_margin=2.0)

Compute the contrastive loss as in

$$L = 0.5 * (1-Y) * D^2 + 0.5 * (Y) * {max(0, margin - D)}^2$$

where, 0 are assign for pairs from the same class and 1 from pairs from different classes.

Parameters

left_feature:

First element of the pair

right_feature:

Second element of the pair

labels:

Label of the pair (0 or 1)

margin:

Contrastive margin

bob.learn.tensorflow.loss.denoising_loss(noise)[source]

Computes the denoising loss as in:

Gatys, Leon A., Alexander S. Ecker, and Matthias Bethge. “A neural algorithm of artistic style.” arXiv preprint arXiv:1508.06576 (2015).

Parameters

noise – Input noise

bob.learn.tensorflow.loss.linear_gram_style_loss(noises, gram_style_features)[source]

Implements the style loss from:

Gatys, Leon A., Alexander S. Ecker, and Matthias Bethge. “A neural algorithm of artistic style.” arXiv preprint arXiv:1508.06576 (2015).

For a given noise signal $$n$$, content image $$c$$ and convolved with the DCNN $$\phi$$ until the layer $$l$$ the STYLE loss is defined as

$$L(n,c) = \sum_{l=?}^{?}\frac{({\phi^l(n)^T*\phi^l(n) - \phi^l(c)^T*\phi^l(c)})^2}{N*M}$$

Parameters
• noises (list) – A list of tf.Tensor containing all the noises convolved

• gram_style_features (list) – A list of numpy.array containing all the content_features convolved

bob.learn.tensorflow.loss.mean_cross_entropy_center_loss(logits, prelogits, labels, n_classes, alpha=0.9, factor=0.01)

Implementation of the CrossEntropy + Center Loss from the paper “A Discriminative Feature Learning Approach for Deep Face Recognition”(http://ydwen.github.io/papers/WenECCV16.pdf)

Parameters

logits: prelogits: labels: n_classes: Number of classes of your task alpha: Alpha factor ((1-alpha)*centers-prelogits) factor: Weight factor of the center loss

bob.learn.tensorflow.loss.mean_cross_entropy_loss(logits, labels, add_regularization_losses=True)

Simple CrossEntropy loss. Basically it wrapps the function tf.nn.sparse_softmax_cross_entropy_with_logits.

Parameters

logits: labels: add_regularization_losses: Regulize the loss???

bob.learn.tensorflow.loss.triplet_average_loss(anchor_embedding, positive_embedding, negative_embedding, margin=5.0)

Compute the triplet loss as in

Schroff, Florian, Dmitry Kalenichenko, and James Philbin. “Facenet: A unified embedding for face recognition and clustering.” Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. 2015.

$$L = sum( |f_a - f_p|^2 - |f_a - f_n|^2 + \lambda)$$

Parameters

left_feature:

First element of the pair

right_feature:

Second element of the pair

label:

Label of the pair (0 or 1)

margin:

Contrastive margin

bob.learn.tensorflow.loss.triplet_fisher_loss(anchor_embedding, positive_embedding, negative_embedding)
bob.learn.tensorflow.loss.triplet_loss(anchor_embedding, positive_embedding, negative_embedding, margin=5.0)

Compute the triplet loss as in

Schroff, Florian, Dmitry Kalenichenko, and James Philbin. “Facenet: A unified embedding for face recognition and clustering.” Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. 2015.

$$L = sum( |f_a - f_p|^2 - |f_a - f_n|^2 + \lambda)$$

Parameters

left_feature:

First element of the pair

right_feature:

Second element of the pair

label:

Label of the pair (0 or 1)

margin:

Contrastive margin


text:
Means of powers of the zeta function

It is well known that the Lindel\"of Hypothesis is equivalent to the statement that $$\frac 1T\int_0^T|\zeta(1/2=it)|^{2k} =O(T^\epsilon)$$ for all positive integers $$k$$ and all positive real $$\epsilon$$, and these fact are known for $$k=1, 2$$. May I ask you for references to the proofs.

• In papers and chapters (Titchmarsh and others) about the Dirichlet divisor problem – reuns Dec 6 '18 at 20:16
• Do you mean the equivalence? I am interested in the proofs of the estimate for $k=1, 2$. – Durac Dec 6 '18 at 20:27
• – reuns Dec 6 '18 at 20:40
• Thanks! Just a remark: this is the chapter of Titchmarsh titled 'Mean value theorems'. (You have answered my question, I am ready to accept.) – Durac Dec 6 '18 at 20:51

format: plain


text:
Show Summary Details
More options …

# Groups Complexity Cryptology

Managing Editor: Shpilrain, Vladimir / Weil, Pascal

Editorial Board: Conder, Marston / Dehornoy, Patrick / Eick, Bettina / Fine, Benjamin / Gilman, Robert / Grigoriev, Dima / Ko, Ki Hyoung / Kreuzer, Martin / Mikhalev, Alexander V. / Myasnikov, Alexei / Perret, Ludovic / Roman'kov, Vitalii / Rosenberger, Gerhard / Sapir, Mark / Thomas, Rick / Tsaban, Boaz / Capell, Enric Ventura

2 Issues per year

CiteScore 2016: 0.35

SCImago Journal Rank (SJR) 2016: 0.372
Source Normalized Impact per Paper (SNIP) 2016: 0.517

Mathematical Citation Quotient (MCQ) 2016: 0.23

Online
ISSN
1869-6104
See all formats and pricing
More options …
Volume 9, Issue 1 (May 2017)

# Cryptography from the tropical Hessian pencil

Jean-Marie Chauvet
/ Eric Mahé
Published Online: 2017-04-19 | DOI: https://doi.org/10.1515/gcc-2017-0002

## Abstract

Recent work by Grigoriev and Shpilrain [8] suggests looking at the tropical semiring for cryptographic schemes. In this contribution we explore the tropical analogue of the Hessian pencil of plane cubic curves as a source of group-based cryptography. Using elementary tropical geometry on the tropical Hessian curves, we derive the addition and doubling formulas induced from their Jacobian and investigate the discrete logarithm problem in this group. We show that the DLP is solvable when restricted to integral points on the tropical Hesse curve, and hence inadequate for cryptographic applications. Consideration of point duplication, however, provides instances of solvable chaotic maps producing random sequences and thus a source of fast keyed hash functions.

MSC 2010: 14H40; 14H52; 14K25; 37E05; 37F10

## 1 Introduction

In the projective plane ${ℙ}^{2}\left(ℂ\right)$ the Hessian pencil is given by the equation

$\lambda \left({x}^{3}+{y}^{3}+{z}^{3}\right)+\mu xyz=0,\lambda ,\mu \in {ℙ}^{1}\left(ℂ\right).$

Its properties are well known (see [1] for an extensive review) and Hesse curves, which constitute the Hessian pencil, have recently been popular among number theorists in relation to applied elliptic curve cryptography [17, 9]. Hessian parametrization of elliptic curves in particular has been shown to improve resistance to side-channel attacks [9].

Following [8], the replacement of the field $ℂ$ with the tropical semiring $𝕋=ℝ\cup \left\{-\mathrm{\infty }\right\}$, equipped with the addition $x+y:=max\left(x,y\right)$ and multiplication $xy:=x+y$ (together with the natural conventions to handle the special value $-\mathrm{\infty }$), provides an original source of cryptographic schemes with very fast implementations [3] in some cases. In addition these implementations remain practical in a parameter space well beyond the original values suggested in [8] and analyzed in [11]. As an alternative to the tropical matrix algebra used there, we turn to tropical geometry in the projective space ${ℙ}^{2}\left(𝕋\right)$ and investigate the tropical analogue of the Hessian pencil.

## Tropical polynomials and tropical curves

A tropical polynomial in n variables ${x}_{1}\mathrm{\dots }{x}_{n}$ is a tropical sum of monomials:

$\sum _{i=1}^{m}{a}_{i}{x}_{1}^{{i}_{1}}\mathrm{\dots }{x}_{n}^{{i}_{n}}:=\underset{1⩽i⩽m}{\mathrm{max}}\left({a}_{i}+{i}_{1}{x}_{1}+\mathrm{\dots }+{i}_{n}{x}_{n}\right).$

Then to every tropical polynomial f we can associate its hypersurface ${V}_{f}\subset {𝕋}^{n}$ defined as the set of points where the maximum is attained at least twice. A tropical hypersurface in ${𝕋}^{n}$ is a union of convex polyhedra of dimension $n-1$, each one having integer slope i.e. being parallel to a hyperplane in ${ℝ}^{n}$ defined over $ℤ$. For every facet P, there are two monomials in f that are equal and greater than any other monomial of f over P (see [13, 12]). When f is homogeneous its hypersurface can be considered as a tropical projective variety in ${ℙ}^{n-1}\left(𝕋\right)$.

For $n=2$ the tropical hypersurface simplifies to a plane tropical curve in ${𝕋}^{2}$ and its facets are just affine segments. An unbounded segment is also called a tentacle.

## Tropical lines

The tropical lines are defined by the polynomials $aX+bY+c:=\mathrm{max}\left(a+X,b+Y,c\right)$. A tropical line is uniquely defined by the juncture of its three tentacles, the root point such that $a+X=b+Y=c$. As in euclidean geometry, two points in a general configuration define a unique tropical line, as shown in Figure 1. (It is still true in the specific configuration where the two points lie on the same tentacle, provided we fix the appropriate one as the root.)

Figure 1

Tropical lines. First row: In the general configuration, two points in ${𝕋}^{2}$ define a unique tropical line passing through them both. Second row: When both points lie on the same tentacle, fixing the appropriate one as the root also defines a unique tropical line.

## Tropical Hesse curves

The direct tropicalization of the Hessian pencil equation yields the tropical polynomial:

$f\left(x,y,z;\lambda ,\mu \right)=\mathrm{max}\left(\lambda +3x,\lambda +3y,\lambda +3z,\mu +x+y+z\right),x,y,z,\lambda ,\mu \in 𝕋$

The tropical Hesse curve is the set of points where the maximum is reached more than once. Introducing the inhomogeneous coordinates in the projective plane $\left(X=z-x,Y=z-y\right)$ and $K=\mu -\lambda$, we designate the tropical Hesse curve given by the tropical polynomial ${F}_{K}\left(X,Y\right)=\mathrm{max}\left(3X,3Y,0,K+X+Y\right)$ by ${H}_{K}$ (Figure 2). The tropical Hesse curves has three tentacles originating in the three vertices of coordinates $\left(K,K\right)$, which we pick as O the origin, $\left(-K,0\right)$ and $\left(0,-K\right)$, respectively. It has three facets: the line segments joining any pair of these vertices with slopes $\left(2,1\right)$, $\left(1,-1\right)$ and $\left(1,2\right)$, respectively (counterclockwise); the curve is symmetric around the axis $X=Y$.

Figure 2

Left: The tropical Hesse curve ${H}_{K}$. Right: The regular subdivision of the tropical Hesse curve, with the scaled tropical Hesse curve (red) showing mapping between crossing segments of the curve and its regular subdivision: tentacles cross boundary edges of the subdivision; internal segments cross internal edges of the subdivision.

## Tropical intersections and tropical elliptic curves

We use basic facts in tropical intersection theory [13] to adapt the geometrical presentation of tropical elliptic curve group law from [4] to the case of the tropical Hesse curve. Let $A\subset \left\{i,j,k\in ℕ:i+j+k=d\right\}$ be called the support of the polynomial

$f\left(x,y,z\right)=\sum _{\left(i,j,k\right)\in A}{a}_{ijk}{x}^{i}{y}^{j}{z}^{k}$

defining a plane tropical curve. The convex hull of points $\left(i,j,k,{a}_{ijk}\right)$ is a 3-dimensional polytope, the lower faces of which project bijectively, under omission of the last coordinate, onto the planar convex hull of A, thus defining a regular subdivision Δ of A. The segments of ${V}_{f}$ arise from the interior edges of Δ, and the tentacles arise from its boundary edges [16]. Figure 2, right, shows the regular subdivision of the tropical Hesse curve. The weight of a facet of the tropical curve is the lattice length of its dual edge in the regular subdivision(i.e. the number of lattice points on the edge, including extremities, minus 1). The degree of the curve is d as defined in the support of its polynomial.

Then the balancing condition holds: for any vertex V in the tropical curve ${V}_{f}$ with adjacent edges ${E}_{1},\mathrm{\dots },{E}_{p}$, let ${w}_{i},{v}_{i}$ be the weight and unit vectors of edge ${E}_{i}$; then ${w}_{1}{v}_{1}+\mathrm{\dots }+{w}_{n}{v}_{n}=0$, where $0=\left(0,0\right)$ of ${ℙ}^{2}\left(𝕋\right)$. For a vertex having exactly three adjacent edges, the multiplicity is defined as the common quantity

${w}_{2}{w}_{3}|det\left({v}_{2},{v}_{3}\right)|={w}_{3}{w}_{1}|det\left({v}_{3},{v}_{1}\right)|={w}_{1}{w}_{2}|det\left({v}_{1},{v}_{2}\right)|$

and following [4] a tropical curve is called smooth if all its vertices are 3-valent and have multiplicity 1, and a tropical elliptic curve is a smooth tropical curve of degree 3 and genus 1 (number of cycles). More generally, the intersection of two segments of a plane tropical curves, with respective weight ${w}_{1},{w}_{2}$ and unit vectors ${v}_{1},{v}_{2}$, has multiplicity ${w}_{1}{w}_{2}|det\left({v}_{1},{v}_{2}\right)|$ (see [16]).

Inspection of Figure 2 (right) show that the weight of the Hesse curve’s tentacles are 3, and the weight of the bounded segments are 1 and the balancing condition checks for all three vertices. The degree is 3 and its genus is 1. All vertices are 3-valent, their multiplicity, however, is e.g. for the origin O:

${m}_{O}=1×1×||\begin{array}{cc}\hfill -2\hfill & \hfill -1\hfill \\ \hfill -1\hfill & \hfill -2\hfill \end{array}||=3$

and the tropical Hesse curve is not smooth. The cycle ${C}_{K}$ of the tropical curve ${H}_{K}$ is obtained simply by removing the three tentacles, its equation is given by $\mathrm{max}\left(3X,3Y,0\right)=K+X+Y$.

## Geometrical presentation of the group law

On a tropical elliptic curve the group law introduced in [4], by analogy with the traditional group law on elliptic curves, has a geometrical presentation. We restrict our attention to the cycle C of the tropical elliptic curve, see Figure 3, with $O\in C$ an origin: addition of $P,Q\in C$ is computed by finding first the intersection S of the tropical line defined by $P,Q$ with the cycle C, and then defining $P+Q$ as the intersection of the tropical line defined by $S,O$ with C. Doubling of $P\in C$ is computed by finding first the intersection S of the tropical line intersecting C with multiplicity 2 at P, with C, and then defining $2P$ as the intersection of the tropical line defined by $S,O$ with C.

For a general point P, a tropical line intersecting C at P with multiplicity 2 does not necessarily exist. On the tropical Hesse curve, however, intersection of the tropical line rooted in any $P\in {C}_{K}$ and ${C}_{K}$ has multiplicity 2, hence doubling is well defined over ${C}_{K}$ even though the curve is not smooth.

Figure 3

Left: Point addition in the tropical Hesse curve group law; a first step determines S from P and Q, a second step yields $P+Q$ from S and the origin O. Right: Point doubling in the tropical Hesse curve group law; a first step determines S from P,a second step yields $2P$ from S and the origin O.

#### Proof.

Computations of determinants for each case of P lying on the three edges of ${C}_{K}$, and remembering that weights of edges on a tropical line are 1 as are weights of the bounded segments of the tropical Hesse curve, yield

$1×1×||\begin{array}{cc}\hfill 2\hfill & \hfill 0\hfill \\ \hfill 1\hfill & \hfill 1\hfill \end{array}||=2,1×1×||\begin{array}{cc}\hfill 1\hfill & \hfill 1\hfill \\ \hfill 2\hfill & \hfill 0\hfill \end{array}||=2,1×1×||\begin{array}{cc}\hfill 1\hfill & \hfill 1\hfill \\ \hfill -1\hfill & \hfill 1\hfill \end{array}||=2$

when P lies on the upper segment emanating from O, the lower segment emanating from O, the segment opposed to O, respectively. ∎

In [10, 15] Kajiwara and Nobe derive duplication and addition formula for the group law on the tropical Hesse curve using the process of ultradiscretization of the level-three theta functions on the (non-tropical) Hesse cubic curve. Here instead we calculate coordinates of points directly from the geometrical presentation above to obtain short formulas amenable to fast implementations. Let us divide the cycle ${C}_{K}$ and its interior into six faces, respectively:

${F}_{1}:=\left\{X,Y\in \overline{{C}_{K}}:X\ge 0,Y\ge X\right\},$${F}_{2}:=\left\{X,Y\in \overline{{C}_{K}}:X\le 0,Y\ge X,Y\ge 0\right\},$${F}_{3}:=\left\{X,Y\in \overline{{C}_{K}}:X\le 0,Y\ge X,Y\le 0\right\},$${F}_{4}:=\left\{X,Y\in \overline{{C}_{K}}:X\le 0,Y\le X,Y\le 0\right\},$${F}_{5}:=\left\{X,Y\in \overline{{C}_{K}}:X\ge 0,Y\ge X,Y\le 0\right\},$${F}_{6}:=\left\{X,Y\in \overline{{C}_{K}}:X\ge 0,Y\le X,Y\ge 0\right\}.$

In the first step of the addition, the intersection of ${C}_{K}$ and the tropical line determined by $P,Q\in {C}_{K}$ is determined. To do so we distinguish six cases according to which face the root of the tropical line lies in, as shown on Figure 4. In each of these configurations, for a root on a given face, the two points to add could be any pair combination of the three intersection points. We then produce in Table 1 three formulas for each configuration giving the third point from the coordinates of the two others, naming them by convention A on the unbounded north-east ray of the tropical line, B on the horizontal ray and C on the vertical one. This third point and the origin O then determine the second tropical line which intersects again ${C}_{K}$ at the sought for addition point, which we also call A, B, or C according to the first step.

Figure 4

The six configurations of the group addition on the tropical Hesse curve according to the face the root of the tropical line $P,Q$ lies in: Face 1 to 6, left to right, top to bottom.

Table 1

Given P and Q on ${C}_{K}$ defining a tropical line with root r, P being one of $A,B,C$, and Q being one of $A,B,C$ on this tropical line, the table provides coordinates of $P+Q$ according to which face r lies in.

## Doubling formulas

In order to produce the doubling formulas, we consider the tropical line to be rooted on the point in ${C}_{K}$ to be doubled and using the same partition of the curve in six faces as above to derive the formulas.

Table 2

Formulas for doubling of P and alternate preimage Q of the double of P.

Note that exactly two points on the tropical Hesse curve have the same image by doubling, with the exception of the origin O. Table 2 displays formulas for the doubling of point P and for Q the other point in the preimage of $\left[2\right]P$. Let us denote by ${\left[\frac{1}{2}\right]}_{0}P$ and ${\left[\frac{1}{2}\right]}_{1}P$ the preimages of P by the group law doubling; then ${\left[\frac{1}{2}\right]}_{0}P$ and ${\left[\frac{1}{2}\right]}_{1}P$ lie on opposite faces of the tropical Hesse curve in the following pairings $\left({F}_{1},{F}_{4}\right),\left({F}_{2},{F}_{5}\right),\left({F}_{3},{F}_{6}\right)$.

The formulas coincide with the ones obtained through ultradiscretization in [10, 14, 15] but involve a smaller number of elementary computations (additions and comparisons). Hence their implementation over either $ℝ$ with standard floating point precision or over $ℤ$ with large integers can be made very efficient. Experiments with unoptimized Python implementation of the double-and-add algorithm for elliptic point multiplications using the above tables show that, over a range of exponent’s length from 10 bits to 1.024 bits, point multiplication costs in average 2.3 integral multiplications and 0.7 integral comparisons per exponent’s bit which obviously compare favorably with analogues on the non-tropical Hesse cubic [6, 9].

## 3.1 Metrics on the tropical Hesse curve

The tropical Hesse curve’s cycle ${C}_{K}$ is obviously homeomorphic to the circle ${S}^{1}$ as a topological space. Furthermore, calling ${V}_{1},{V}_{2}$ the vertices starting from the origin O counterclockwise, and ${E}_{0},{E}_{1},{E}_{2}$ the successive edges, these may be assigned a length defined by $\frac{|{E}_{i}|}{|{v}_{i}|}$, where vertical bars denote the Euclidean metric and ${v}_{i}$ is the primitive integer vector along the considered edge. The total length of the cycle is then

$\mathrm{\ell }\left({C}_{k}\right)=\frac{\sqrt{5}×K}{\sqrt{5}}+\frac{\sqrt{2}×K}{\sqrt{2}}+\frac{\sqrt{5}×K}{\sqrt{5}}=3K$

The explicitation of the homomorphism for tropical elliptic curves in [4] to the case of the tropical Hesse curve is

$\lambda :{C}_{K}\to ℝ/ℤ\sim {S}^{1},\lambda \left(O\right)=0,\lambda \left({V}_{1}\right)=0+\frac{\mathrm{\ell }\left({E}_{0}\right)}{\mathrm{\ell }\left({C}_{K}\right)}=\frac{1}{3},\lambda \left({V}_{2}\right)=\lambda \left({V}_{1}\right)+\frac{\mathrm{\ell }\left({E}_{1}\right)}{\mathrm{\ell }\left({C}_{K}\right)}=\frac{2}{3},$

where it is enough to specify the images of the vertices. Even though the tropical Hesse curve is not a tropical elliptic curve – it is not smooth –, the proofs in [4] are still valid for λ as defined above. We can define a signed distance on ${C}_{K}$, namely $d\left(P,Q\right)=\mathrm{\ell }\left({C}_{K}\right)×\left(\lambda \left(P\right)-\lambda \left(Q\right)\right)$ which verifies

$d\left(P,Q\right)+d\left(Q,R\right)=d\left(P,R\right)$$\text{for all}P,Q,R\in {C}_{K},$$d\left(O,P+Q\right)=d\left(O,P\right)+d\left(O,Q\right)$$\text{for all}P,Q\in {C}_{K},$$\lambda \left(P+Q\right)=\lambda \left(P\right)+\lambda \left(Q\right)$$\text{for all}P,Q\in {C}_{K},$

where $+$ denotes the group law addition.

## 3.2 DLP on integral points

Let us now consider the standard cryptographic setting in ECC where Alice and Bob agree on a public elliptic curve, here an integral point $\left({X}_{\mathrm{pub}},{Y}_{\mathrm{pub}}\right)$ or equivalently the uniquely associated tropical Hesse curve such that $\left({X}_{\mathrm{pub}},{Y}_{\mathrm{pub}}\right)\in {C}_{K}$, and a public integral point $P\in {C}_{K}$ on this curve’s cycle – which could simply be $\left({X}_{\mathrm{pub}},{Y}_{\mathrm{pub}}\right)$. Alice and Bob choose a random secret $a,b$, respectively, and Alice sends Bob $\left[a\right]P$, Bob sends Alice $\left[b\right]P$ so that both can compute the shared secret $\left[ab\right]P=\left[ba\right]P$ using the group law on the curve. The shared secret is evidently compromised if Eve is able to recover a from $\left[a\right]P$ and P, or to recover $\left[ab\right]P$ from $P,\left[a\right]P,\left[b\right]P$.

The explicit homomorphism and the signed distance defined in the previous section afford simple analysis of this cryptographic setting on the tropical Hesse curve. Starting with ${P}_{0}=O$, let us enumerate all integral points on the cycle ${C}_{K}$ counterclockwise ${P}_{0},{P}_{1},\mathrm{\dots },{P}_{3K-1}$. There are $3K$ such points on the cycle and the formulas for λ and d show that the group law addition reduces to a counterclockwise shift modulo $3K$. There is one point, O, or order 1, two points ${V}_{1}$ and ${V}_{2}$ of order 3, and the order of all other points divide K. The metric leads to the relation ${P}_{nm\left(\mathrm{mod}3K\right)}=\left[n\right]{P}_{m}$ which given public knowledge of ${P}_{m}$ and interception of ${P}_{j}=\left[n\right]{P}_{m}$, allows derivation of $n=j{m}^{-1}\left(\mathrm{mod}3K\right)$.

## 3.3 Doubling leads to chaos

Although the previous analysis shows that the standard group law is inadequate for cryptographic purposes, the doubling operation shows sensitivity to initial conditions and ergodicity [10]. Although the discretized doubling on integral points of the tropical Hesse curve is a permutation and thus cannot be chaotic, we can extend it to a larger subset of points with coordinates in $ℚ$, namely the set F of points which coordinates are fractions with denominator of the form ${2}^{n}$ for $n\in ℕ$. The set F is stable under the doubling point of the group law and, more importantly, under the halving operation yielding the two halves ${\left[{2}^{-1}\right]}_{0}M$ and ${\left[{2}^{-1}\right]}_{1}M$.

The algebraic entropy [2] of the doubling map, a quantity measuring the complexity of the map defined by ${lim}_{n\to \mathrm{\infty }}\mathrm{log}\left({d}_{n}\right)/n$, where ${d}_{n}$ is the degree of the rational map of the n-th iterate, is here $\mathrm{log}\left(2\right)$ and positive. Figure 5 shows that the cycle ${C}_{K}$ is filled with points in the halving orbit of P, a point not a vertex.

Figure 5

Left: On the cycle ${C}_{22+101/128}$ of the tropical Hesse curve, 256 iterations of the halving map, showing almost equal distribution on all faces, respectively 42, 43, 43, 42, 43, and 43 points on faces 1 to 6. Right: x coordinates of the first1,000 doubling iterations of point $\left(8+1/128,15+51/128\right)$.

## 4.1 The tropical Hesse chaotic map

For a cryptographic application of the conjunction of both algebraic group properties and chaotic characteristics of the tropical Hessian pencil reviewed in the previous sections, we fix a tropical Hesse curve ${C}_{K}$ and consider the following map on its cycle:

${P}_{i+1}={\left[{2}^{-1}\right]}_{k}{P}_{i},k=0,1,$

which sends a point ${P}_{i}$ of the cycle to one of its two halves according to the key bit k. The ${P}_{i}$ points coordinates are dyadic rationals, and together with the tropical elliptic addition constitute a group. Lyapunov exponent calculations show, in Figure 6, that the map behavior is chaotic in the early iterations and then stabilizes much like a random time series.

Figure 6

Left diagram: Evolution of the (log) stretching factor in the early iterations of the tropical Hessian doubling/halving chaotic map. Right diagram: Comparative evolutions of the tropical Hessian map, black circles, and a random timeseries, blue triangles. (Graphs generated in R using the lyap_k function of the tseriesChaos package from $2,000$ halvingsof ${C}_{170,370/131,072}$.)

We consider the iteration of this chaotic map according to successive bits ${k}_{0}{k}_{1}\mathrm{\dots }{k}_{n-1}$ of a secret key k, and define

${P}_{n}={f}_{k}\left({P}_{0}\right),$

where ${P}_{i+1}={\left[{2}^{-1}\right]}_{{k}_{i}}{P}_{i}$, as our keyed chaotic map.

## 4.2 A keyed cipher construction

The construction proposed is iterative and leverages the group structure on the tropical Hesse curve cycle. The message block M and the secret key S have the same bit size n. Note that M and S are mapped each to a point on the upper edge of the public ${C}_{K}$ tropical Hesse curve (K a dyadic rational), which we denote by ${M}_{0}$ and ${S}_{0}$, respectively.

The cipher round

${M}_{j+1}={f}_{{S}_{j}}\left({M}_{j}+{S}_{j}\right),{S}_{j+1}={f}_{{S}_{j}}\left({S}_{j}\right)$

is iterated r times, with r a public parameter of the cipher, to produce the ciphertext ${M}_{r}$. The addition is the group addition on the tropical elliptic curve. In the rest of this section we denote this cipher construction by $\mathrm{THC}\left(K,r\right)$.

## 4.3 Correlation and diffusion properties

The $\mathrm{THC}\left(K,r\right)$ cipher construction operates on a single block of the message and can be used in other block cipher architectures chaining successive message blocks and secret keys. We ran measuring experiments of this single step, however, in order to assess the diffusion properties within a single message block. At each round a secret key is mixed in the message before applying the keyed chaotic map, a step which is similar to the Single-Key Even-Mansour Scheme described by Dunkelman, Keller and Shamir [5].

As seen in Figure 7, for typical values of the parameters, the cipher construction shows good decorrelation between plaintext bits and ciphertext bits. Bits 0 to 127 of the 128-bit long messages are along the horizontal axis, and the number of times the said message bit is changed after ten rounds over 1,000 runs on random messages is plotted on the vertical axis. The closer the score is to half of the runs, here 500, the closer to random is the correlation between plaintext and ciphertext.

Figure 7

Boxplot graph of individual bit correlations between plaintext and ciphertext for THC(${2}^{128}+1$,10): horizontal axis,bit position in ciphertext; vertical axis, cumulated bit differences over 1000 runs; the closer to half, here 500 the better. Thedisplay shows artifacts on a few of the high bits and few mid-bits as a result of the choice of mapping of messages and keysto the tropical Hesse Curve.

In order to study the diffusion properties, we run the cipher construction on messages that differ on a single bit only while keeping the same secret key. We then compute the Hamming distance, the number of different bits, of the ciphertexts of these single-bit differing plaintexts.

Figure 8

Boxplot graph of Hamming distances, in bits, between plaintext and ciphertext showing how bit by bit changes are propagated from plaintext to ciphertext according to position: left, 16-bit keys and plaintexts; right, 32-bit keys and plaintexts.

Figure 8 shows the results of running five rounds on 16-bit and 32-bit long messages, and comparing the ciphertext with the sixteen others obtained by changing one bit at each position in the original message. Each round produces an output ciphertext larger than the input message: here ciphertexts are 543-bit long of which an average of 28.67 % are changed when a single bit of the message is switched. Note that the diffusion is larger when the bit changed is higher in the message (most significant bits). By construction the diffusion stays local and with larger key sizes, the ciphertexts are longer, hence the ratio of changed bits decreases: it is 16,4 % for a 32-bit key size yielding 1,055-bit long ciphertexts from 32-bit long plaintext messages.

## 5 Conclusions

Properties of elliptic curve geometry naturally carry over to tropical geometry where tropical variety analogues can be defined for notions of degrees, intersections, Jacobians, metrics and group law. Looking at the specific instance of the Hesse cubic curve, a well-studied form of elliptic curve with interesting properties for cryptographic usage, it appears that these properties are lost in the linearization of the group law induced by the tropicalization of the Hessian pencil.

The tropical Hesse group law doubling map $P\to \left[{2}^{n}\right]P$, however, and more generally the maps $P\to \left[{p}^{n}\right]P$, $p\in ℤ$, give rise to piecewise linear discrete dynamical systems exhibiting solvable chaos [7] behavior. These maps are good candidates components for S-box implementations with the added benefit of very fast formula implementations since they reduce to few basic additions and comparisons in the tropical semiring.

## References

• [1]

M. Artebani and I. Dolgachev, The Hesse pencil of plane cubic curves, preprint (2006), https://arxiv.org/abs/math/0611590.

• [2]

P. M. Bellon and C.-M. Viallet, Algebraic entropy, Comm. Math. Phys. 204 (1999), no. 2, 425–437.  Google Scholar

• [3]

J. Chauvet and E. Mahe, Key agreement under tropical parallels, Groups Complex. Cryptol. 7 (2015), no. 2, 195–198.  Google Scholar

• [4]

M. Dehli Vigeland, The group law on a tropical elliptic curve, preprint (2004), https://arxiv.org/abs/math/0411485.

• [5]

O. Dunkelman, N. Keller and A. Shamir, Minimalism in cryptography: The even-mansour scheme revisited, Technical Report 2011/541, IACR Cryptology ePrint Archive, 2011, http://dblp.org/rec/journals/iacr/DunkelmanKS11a.

• [6]

R. R. Farashahi and M. Joye, Efficient arithmetic on Hessian curves, Public Key Cryptography, Lecture Notes in Comput. Sci. 6056, Springer, Berlin (2010), 243–260.  Google Scholar

• [7]

B. Grammaticos, A. Ramani and C. Viallet, Solvable chaos, Phys. Lett. A 336 (2005), no. 2–3, 152–158.  Google Scholar

• [8]

D. Grigoriev and V. Shpilrain, Tropical cryptography, Comm. Algebra 42 (2014), no. 6, 2624–2632.  Google Scholar

• [9]

M. Joye and J.-J. Quisquater, Hessian elliptic curves and side-channel attacks, Proceedings of Cryptographic Hardware and Embedded Systems – CHES 2001, Lecture Notes in Comput. Sci. 2162, Springer, Berlin (2001), 402–410.  Google Scholar

• [10]

K. Kajiwara, M. Kaneko, A. Nobe and T. Tsuda, Ultradiscretization of a solvable two-dimensional chaotic map associated with the hesse cubic curve, Kyushu J. Math. 63 (2009), no. 2, 315–338.  Google Scholar

• [11]

M. Kotov and A. Ushakov, Analysis of a key exchange protocol based on tropical matrix algebra, Technical Report 2015/852, Cryptology ePrint Archive, 2015, http://eprint.iacr.org/.

• [12]

D. Maclagan and B. Sturmfels, Introduction to Tropical Geometry, Grad. Stud. Math. 161, American Mathematical Society, Providence, 2015.  Google Scholar

• [13]

G. Mikhalkin, Tropical geometry and its applications, preprint (2006), https://arxiv.org/abs/math/0601041.

• [14]

A. Nobe, A tropical analogue of the Hessian group, preprint (2011), https://arxiv.org/abs/1104.0999.

• [15]

A. Nobe, The group law on the tropical Hesse pencil, preprint (2011), http://arxiv.org/abs/1111.0131.

• [16]

J. Richter-Gebert, B. Sturmfels and T. Theobald, First steps in tropical geometry, preprint (2003), https://arxiv.org/abs/math/0306366.

• [17]

N. Smart, The Hessian form of an elliptic curve, Cryptographic Hardware and Embedded Systems – CHES 2001, Lecture Notes in Comput. Sci. 2162, Springer, Berlin (2001), 118–125.  Google Scholar

Published Online: 2017-04-19

Published in Print: 2017-05-01

Citation Information: Groups Complexity Cryptology, ISSN (Online) 1869-6104, ISSN (Print) 1867-1144,

Export Citation

© 2017 Walter de Gruyter GmbH, Berlin/Boston.


text:
View Single Post
 2015-03-06, 02:11 #11 science_man_88     "Forget I exist" Jul 2009 Dumbassville 26·131 Posts did I do the math correct ? I know I shouldn't play with this, However I manipulated the equation in Theorem 1 to: $k>(2np^2-2np+\frac{3}{2}p)$ where k is such that 2*k*p+1 is Mp I was thinking of manipulating it more, but if I've messed up already it's pointless to try to extrapolate further. EDIT: I think I messed up the +3/2 part I think it should be -3/2 now that I looked over my manipulation on paper. EDIT2: I found a fatal error I failed to correct further up if only I hadn't gone through 27 steps. Last fiddled with by science_man_88 on 2015-03-06 at 02:53 Reason: had to edit what I said needed editing.


text:
HPlourde Group Title what is (cosx/sinx)/sinxcosx simplified one year ago one year ago

1. abb0t Group Title

$\frac{ \cos(x) }{ \sin(x) } \times \frac{ \sin(x)\cos(x) }{ 1 }$

2. zepdrix Group Title

$\large \frac{\left(\dfrac{\cos x}{\sin x}\right)}{\sin x \cos x}$Woops I dunno if you're looking at it correctly abbot :O Only the top one is a fraction.

3. zepdrix Group Title

$\large \frac{\left(\dfrac{\cos x}{\sin x}\right)}{\sin x \cos x} \qquad = \qquad \left(\frac{\cos x}{\sin x}\right)\frac{1}{\sin x \cos x}$

4. HPlourde Group Title

ya but what about multiplying by the recipricol.... cause i am seriously confused.

5. zepdrix Group Title

$\large \left(\frac{\cancel{\cos x}}{\sin x}\right)\frac{1}{\sin x \cancel{\cos x}}$

6. zepdrix Group Title

Ok here's the thing with the reciprocal :) lemme explain.

7. HPlourde Group Title

ok sounds good

8. zepdrix Group Title

The bottom fraction is actually this,$\large \frac{\sin x \cos x}{1}$ So if you wanted to write it as a division of fractions, you could write it like this,$\large \frac{\left(\dfrac{\cos x}{\sin x}\right)}{\sin x \cos x} \qquad = \qquad \frac{\left(\dfrac{\cos x}{\sin x}\right)}{\left(\dfrac{\sin x \cos x}{1}\right)}$And then from here, we could multiply by the reciprocal of the bottom fraction.

9. HPlourde Group Title

aha!!!!! now it's making sense!!!

10. zepdrix Group Title

When we started this problem, we weren't dividing fractions. Only the top one was a fraction. Maybe that's why there was a little confusion :)

11. HPlourde Group Title

i think so...this is the only one that i've been confused over so far... thank you:)

12. HPlourde Group Title

i got the right answer. thanks a billion

13. zepdrix Group Title

yay!


text:
全文文献 工具书 数字 学术定义 翻译助手 学术趋势 更多

 频率 的翻译结果: 查询用时：1.728秒
 历史查询

 频率
 frequency
 Study and Application of W-band Frequency Source Technology W波段频率源技术研究与应用 短句来源 Study on Frequency Resolved Optical Gating and LD-pumped Frequency-doubled Cr:LiSAF Laser 频率分辨光学快门的理论研究和LD泵浦Cr:LiSAF蓝光激光器的研究 短句来源 Researches on Coastal Storm Surge Frequency during the Warm Period of Middle Holocene in Middle Jiangsu Province 江苏中部海岸全新世中期温暖期风暴潮频率的研究 短句来源 Study on the Application of Time and Frequency Transfer with GPS Common-view GPS共视时间频率传递应用研究 短句来源 Application and Research on Nonparametric Statistics Theory in Flood Frequency 非参数统计理论在洪水频率分析中的应用研究 短句来源 更多
 frequencies
 THE EFFECT OF ELECTRONEGATIVITY OF SUBSTITUENTS UPON THE VIBRATIONAL FREQUENCIES OF P=O AND P=S GROUPS IN ORGANO-PHOSPHORUS COMPOUNDS 有机磷化合物中取代基电负性对P=O及P=S振动频率的影响 短句来源 TWO SIMPLE METHODS FOR ESTIMATION OF Rh GENE COMPLEX FREQUENCIES 估计Rh基因组合体频率的两种简易方法 短句来源 Analysis of the Natural Frequencies of Large Radar 大型雷达结构自振频率分析 短句来源 Iteration Method for Finding the Damped Natural Frequencies of Foundation Vibration 基础阻尼振动固有频率迭代求解 短句来源 The Optimal Design of Structures with Constraints of Stresses, Displacements and Frequencies 具有频率、位移和应力约束的结构优化设计 短句来源 更多
 frequency of
 THE STUDY OF VIBRATIONAL FREQUENCY OF C = O BOND OF BENZOIC ACID 苯甲酸C=O键的振动频率的研究 短句来源 THE SERIES RESISTANCE AND CUTOFF FREQUENCY OF DOUBLE DIFFUSED PARAMETRIC DIODE 双扩散参量二极管的串联电阻及截止频率 短句来源 CERTAIN FACTORS AFFECTING THE FREQUENCY OF INDUCTION OF WHEAT(TRITICUM VULGARE)POLLEN PLANTS 影响小麦(Triticum vulgare)花粉植株诱导频率的几种因素 短句来源 TEMPERATURE STABILITY ANALYSIS OF THE RESONANT FREQUENCY OF A PIEZOELECTRIC CERAMIC VIBRATOR 压电陶瓷振子的谐振频率温度稳定性分析 短句来源 Photoelectric Measurement of the Frequency of Micro Vibration Signal——An Active Photoelectric Detector of the Twist of Textured Yarn 微小振动信号频率的光电测定——弹力丝捻度动态光电检測仪 短句来源 更多
 the frequency
 Mapping the Disease Gene in SCA Families and the Frequency Distribution Analysis of Different Subtypes of SCA in Hans of China SCA致病基因定位及中国汉族人群SCA亚型频率分布 短句来源 Study on Damage Identification Method Based on the Frequency Change and Element Matrix Perturbation Theory 基于频率变化与单元矩阵摄动理论的结构损伤识别方法研究 短句来源 CERTAIN FACTORS AFFECTING THE FREQUENCY OF INDUCTION OF WHEAT(TRITICUM VULGARE)POLLEN PLANTS 影响小麦(Triticum vulgare)花粉植株诱导频率的几种因素 短句来源 The Application of“Receptance”for Deriving the Frequency Equation of Vibration of a Close-coupled System 应用“接受”推导封闭偶联系的振动频率方程 短句来源 Photoelectric Measurement of the Frequency of Micro Vibration Signal——An Active Photoelectric Detector of the Twist of Textured Yarn 微小振动信号频率的光电测定——弹力丝捻度动态光电检測仪 短句来源 更多

我想查看译文中含有：的双语例句

 frequency
 Frequency-Domain Bounds for Nonnegative, Unsharply Band-Limited Functions In this paper we give a further investigation of the method introduced by the author in [1, Frequency-domain bounds for nonnegative unsharply band-limited functions] for proving bounds for functions with nonnegative Fourier transforms. We present two-sided singular value estimates for a class of convolution-product operators related to time-frequency localization. This paper presents an expansion for radial tempered distributions on ${\bf R}^n$ in terms of smooth, radial analyzing and synthesizing functions with space-frequency localization properties similar to standard wavelets. The Balian-Low theorem (BLT) is a key result in time-frequency analysis, originally stated by Balian and, independently, by Low, as: If a Gabor system $\{e^{2\pi imbt} \, g(t-na)\}_{m,n \in \mbox{\bf Z}}$ 更多
 frequencies
 They are potential tools for the decomposition and handling of signals that, like speech or music, seem over short intervals to have well-defined frequencies that, however, change with time. We prove a trigonometric inequality of Ingham's type for nonharmonic Fourier series when the gap condition between frequencies does not hold any more. We provide an almost sure convergent expansion of fractional Brownian motion in wavelets which decorrelates the high frequencies. The MC1595 was utilized to compose a phase detector in which difference of phases varies with the change of frequencies. The model built in this way describes the stable point scattering mechanisms in a large spatial extent and can be extrapolated to other frequencies in the optical region. 更多
 frequency of
 The syntonic frequency of the MOS RO changes in relation to many environmental elements, such as temperature, source voltage, and so on. The characteristic frequency of chaotic motion is thus extracted. Then, using the instantaneous frequency extraction principle of the Hilbert Transform, the rotor broken-bar fault characteristic frequency of 2sfs can be exactly extracted from the IMF component, which includes the rotor fault information. The experiment shows that the method can efficiently extract the frequency of a period-change radio frequency signal in a complex pulses environment and reveals a new feature for the signal sorting of interleaved radar pulse serial. The results showed the following: 1) occurrence frequency of P. 更多
 the frequency
 The measure for uncertainty is a product of two factors evaluating the frequency selectivity in comparison with the ideal filter and the effective length of the filter in the digital domain, respectively. The frequency domain method and the multiplier technique are used. The frequency domain method and the multiplier technique are applied. In BMS, both the frequency and the severity components are considered. Results show that the apparent active energy E of the reaction is 105.51 kJ/mol, the frequency factor lnA is 3.602 and the reaction order n is 2. 更多
其他
 点击这里查询相关文摘
 相关查询

 CNKI小工具 在英文学术搜索中查有关频率的内容 在知识搜索中查有关频率的内容 在数字搜索中查有关频率的内容 在概念知识元中查有关频率的内容 在学术趋势中查有关频率的内容

 CNKI主页 |  设CNKI翻译助手为主页 | 收藏CNKI翻译助手 | 广告服务 | 英文学术搜索
2008 CNKI－中国知网

2008中国知网(cnki) 中国学术期刊(光盘版)电子杂志社


text:
# How often do quarks annihilate?

How often do quarks annihilate?

Quarks bond frequently with quarks, and antiquarks bond frequently with antiquarks. So why do quarks not annihilate antiquarks extremely quickly?

More to the point, how much mass is lost in a body to quark annihilation for a given duration of time?

• I don't understand what you mean with "how often"? Compared to what? In what situation? And what do you mean with them being known to bond "very often"? – ACuriousMind Nov 20 '15 at 23:19
• What you are asking for is essentially the decay rate of the quark antiquark pair. A $\pi^0$ particle is a combination of $u\bar{u}$ and $d\bar{d}$ and decays in about $10^{-16}$s. – octonion Nov 20 '15 at 23:28
• @octonion It is worth noting, however, that the $\rho$ meson has the same valence quark content as the $\pi^0$ and has a much shorter lifetime (on order of $10^{-24}$ seconds). Which may be the reason that the question is receiving downvote, Mason, it is founded on an untrue idea (that there is a characteristic time for this this behavior). The last sentence "More to the point, how much mass is lost in a body to quark annihilation for a given duration of time?" has a worse version of the same problem: it's not even clear what you think is going on that would give that meaning. – dmckee Nov 20 '15 at 23:42
• I also don't understand why a naive but fair question needs to be downvoted. – octonion Nov 20 '15 at 23:52
• As I said, the notion that there is a time scale for quark annihilation is erroneous. In each case that time scale is driven by two things: (a) the coupling constant of the allowed reactions (why the $\rho$ and $\pi^0$ are so different) and the relative wave-functions of the participants (why the $\pi^0$ and the $\pi^\pm$ are so different). Worse is the notion that there is a mass loss to these processes in ambient matter; this suggests that you've taken some pop-sci description far too seriously and then spent some time thinking hard about it when it won't stand up to that. – dmckee Nov 21 '15 at 0:19