Identification network¶
idCNN¶
This module contains the main Tensorflow operations needed to train and the idCNN
Network parameters¶
Stop training criteria (idCNN)¶
-
class
stop_training_criteria.
Stop_Training
(number_of_animals, epochs_before_checking_stopping_conditions=10, check_for_loss_plateau=True, first_accumulation_flag=False)[source]¶ Stops the training of the network according to the conditions specified in
__call__()
Attributes: - num_epochs : int
Number of epochs before starting the training
- number_of_animals : int
Number of animals in the video
- epochs_before_checking_stopping_conditions : int
Number of epochs before starting to check the stopping conditions
- overfitting_counter : int
Counts the number of consecutive overfitting epochs during training
- check_for_loss_plateau : bool
Flag to check for a plateu in the loss of the validation
- first_accumulation_flag : bool
Flag to indicate that it is the first step of the accumulation
Methods
__call__
(loss_accuracy_training, …)Returns True when one of the conditions to stop the training is satisfied, otherwise it returns False
Store accurcay and loss¶
Get data¶
Epoch runner¶
Computes a given operation for an entire epoch divided in batches
-
class
epoch_runner.
EpochRunner
(data_set, starting_epoch=0, print_flag=False, batch_size=None)[source]¶ Runs an epoch divided in batches for a given operation and a given data set (
DataSet
).Attributes: - epochs_completed : int
Number of epochs completed in the current step of the training
- starting_epoch : int
Epoch at which the training step started
- print_flag : bool
If True prints the values of the loss, the accucacy, and the individual accuracy at the end of the epoch
- data_set : <DataSet object>
Object containing the images and labels to be passed through the network in the current epoch (see
DataSet
)- batch_size : int
Number of images to be passed through the network in each bach.
Methods
next_batch
(batch_size)Returns the images and labels for the next batch to be computed. run_epoch
(name, store_loss_and_accuracy, …)Performs a given batch_operation for an entire epoch and stores the values of the loss and the accurcaies in a Store_Accuracy_and_Loss
object for visualization-
next_batch
(batch_size)[source]¶ Returns the images and labels for the next batch to be computed. Images and labels are extracted from a
get_data.DataSet
objectParameters: - batch_size : int
Number of examples to be passed through the network in this batch
Returns: - images : ndarray
Array of shape [batch_size, height, width, channels] containing the images to be used in this batch
- labels : ndarray
Array of shape [batch_size, number_of_classes] containing the labels corresponding to the images to be used in this batch
See also
get_data.DataSet
-
run_epoch
(name, store_loss_and_accuracy, batch_operation)[source]¶ Performs a given batch_operation for an entire epoch and stores the values of the loss and the accurcaies in a
Store_Accuracy_and_Loss
object for visualizationParameters: - name : string
A string to be printed in the epoch information. Typically ‘Training’ or ‘Validation’.
- store_loss_and_accuracy : <Store_Accuracy_and_Loss object>
Object collecting the values of the loss, accurcay and individual accuracies (see
store_accuracy_and_loss.Store_Accuracy_and_Loss
)- batch_operation : func
Function to be run in the epoch
Returns: - feed_dict : dict
Dictionary with the parameters and variables needed to run the batch_operation. It is used to save the Tensorflow summaries if needed
See also
get_data.DataSet
store_accuracy_and_loss.Store_Accuracy_and_Loss
next_batch()
Get predictions¶
Retrieves the predictions of the model idCNN (ConvNetwork
) for a set of images
-
class
get_predictions.
GetPrediction
(data_set)[source]¶ Manages the inference of the identities of a set of images
Attributes: - data_set : <DataSet object>
Object containing the images whose labels has to be predicted (see
DataSet
)- softmax_probs : ndarray
Array of shape [number of images, number of animals] with the softmax vectors for every image in the data_set
- predictions : ndarray
Array of shape [number of images, 1] with the predictions computed as the argmax of the softmax vector of every image (in dense format).
- _fc_vectors : ndarray
Array of shape [number of images, number of neurons in second to last fully connected layer]
- batch_size : int
Size of the batch to send the images through the network to get the predictions
Methods
get_predictions_softmax
(batch_operation)Runs a batch_operation (typically predict()
)next_batch
(batch_size)Return the next batch_size examples from this data set.