deepcinac.cinac_model

File that contains methods use to fit the data to the model and train it.

Module Contents

Classes

Swish

CinacModel

Model used to train a classifier.

Functions

attention_3d_block(inputs, time_steps[, ...])

from: https://github.com/philipperemy/keras-attention-mechanism

sensitivity(y_true, y_pred)

specificity(y_true, y_pred)

precision(y_true, y_pred)

swish(x)

Implementing a the swish activation function.

Attributes

TF_VERSION

config

deepcinac.cinac_model.TF_VERSION
deepcinac.cinac_model.config
deepcinac.cinac_model.attention_3d_block(inputs, time_steps, use_single_attention_vector=False)

from: https://github.com/philipperemy/keras-attention-mechanism :param inputs: :param use_single_attention_vector: if True, the attention vector is shared across the input_dimensions where the attention is applied. :return:

deepcinac.cinac_model.sensitivity(y_true, y_pred)
deepcinac.cinac_model.specificity(y_true, y_pred)
deepcinac.cinac_model.precision(y_true, y_pred)
class deepcinac.cinac_model.Swish(activation, **kwargs)

Bases: tensorflow.keras.layers.Activation

deepcinac.cinac_model.swish(x)

Implementing a the swish activation function. From: https://www.kaggle.com/shahariar/keras-swish-activation-acc-0-996-top-7 Paper describing swish: https://arxiv.org/abs/1710.05941

Parameters

x

Returns

class deepcinac.cinac_model.CinacModel(**kwargs)

Model used to train a classifier. First add data using add_input_data() method Second prepare_model() And at last fit()

Parameters
  • **kwargs

  • results_path (-) – (str, mandatory), path where to save the results (such as classifier weigths)

  • n_gpus (-) – (int, default is 1) Maximum number of processes to spin up when using process-based threading

  • workers (-) – (int, default is 10), number of workers used to run the classifier

  • using_multi_class (-) – (int, default is 1) number of classes used to classify the activity. So far only 1 or 3 are valid

  • cell (options. 3 means we distinguish active) –

  • activity (from overlap) –

  • gives (from neuropil and other. 1 class) –

  • type (better results so far. Don't use it for cell) –

  • yaml (the number of classes will be set throught the) –

  • file. (configuration) –

  • n_epochs (-) – (int, default is 30), number of epochs for training the classifier

  • batch_size (-) – (int, default is 8) size of the batch used to train the classifier

  • window_len (-) – (int, default 100) number of frames of the segments given to the classifier

  • max_width (-) – (int, default 25) number of pixels for the width of the frame surrounding the cell. Should be

  • classifier. (loss function used to train the) –

  • max_height (-) – (int, default 25) number of pixels for the height of the frame surrounding the cell. Should be

  • classifier.

  • overlap_value (-) – (float, default 0.9), overlap between 2 segments using sliding window of size window_len

  • frames. (0.9 means contiguous segments will share 90% of their) –

  • max_n_transformations (-) – (int, default is 6) max number of geometric transformations to apply to each

  • segment.

  • pixels_around (-) – (int, default is 0), number of pixels to add around the mask of the cell (for activity

  • classifier)

  • with_augmentation_for_training_data (-) – (bool, default is True): is True, then geometric transformations are

  • dataset (precise the proportion in the final training) –

  • buffer (-) – (int, default is 1): indicated of how many pixels to inflate the mask of the cell.

  • split_values (-) – (tuple of 3 floats, default is (0.8, 0.2, 0)), tuple of 3 floats, the sum should be equal

  • training (to 1. Give the distribution of the dataset into) –

  • test (validation and) –

  • loss_fct (-) – (str, default is ‘binary_crossentropy’ is using_multi_class is 1, ‘categorical_crossentropy’

  • else)

  • classifier.

  • with_learning_rate_reduction (-) –

  • parameters (according to the following) –

  • learning_rate_reduction_patience (-) – (int, default is 2) number of epochs before reducing the learning

  • improved (rate if the validation accuracy has not) –

  • True (with_learning_rate_reduction needs to be) –

  • learning_rate_start (-) – (float, default is 0.001) default learning rate to start with

  • with_early_stopping (-) – (bool, True) if True, then early stopping is activated, if the classifier doesn’t

  • early_stop_patience (-) –

  • early_stop_patience – (int, default if 15): number of epochs before the training stops if no progress is

  • made (based on validation accuracy values) –

  • model_descr (-) –

  • model (file used to save the) –

  • with_shuffling (-) –

  • dataset

  • seed_value (-) –

  • dataset. (means the shuffle will always be the same for a given) –

  • main_ratio_balance (-) – (tuple of 3 floats, default is (0.6, 0.2, 0.2)), sequence of 3 float, the sum should

  • classifier (be equal to 1. Used for activity) –

  • dataset

  • transient (between sequence according to real) –

  • "neuropil" (fake transient and) –

  • crop_non_crop_ratio_balance (-) – (tuple of 2 floats, default is (-1, -1)), use for stratification in activity

  • classifier

  • -1 (if values are) –

  • segment (we don't use it. Otherwise allows to balance segments between) –

  • cropped. (with transient cropped versus not) –

  • non_crop_ratio_balance (-) – (tuple of 2 floats, default is (-1, -1)), use for stratification in activity

  • classifier

  • -1

  • segment

  • transient. (with one transient vers more than one) –

  • with_model_check_point (-) – (bool, default is True) allows to save weights of the classifier at each epoch

  • verbose (-) – (int, default is 2), 0 no verbose, 1 main outputs printed, 2 all outputs printed

  • dropout_value (-) – (float, default 0.5), dropout between CNN layers

  • dropout_value_rnn (-) – (float, default 0.5), dropout between RNN layers

  • dropout_at_the_end (-) – (float, default 0), dropout value at the end of the model

  • with_batch_normalization (-) – (bool, default False), if True use batch normalization

  • optimizer_choice (-) – (str, default is “RMSprop”), optimizer to use, choices “SGD”, “RMSprop”,”Adam”

  • activation_fct (-) – (str, default is “swish”) , activation function to use, you can choose any activation

  • TensorFlow (function available in) –

  • available. (swish is also) –

  • without_bidirectional (-) – (bool, default is False), if True, LSTM is not bidirectionnal

  • conv_filters (-) – (tuple of 4 int, default is (64, 64, 128, 128)), the dimensionality of the output space

  • integers ((i.e. the number of filters in the convolution) sequence of 4) –

:param : :param representing the filters of the 4 convolution layers: :param - lstm_layers_size: :type - lstm_layers_size: sequence of int, default is (128, 256) :param - bin_lstm_size: :type - bin_lstm_size: int, default is 256 :param - use_bin_at_al_version: :type - use_bin_at_al_version: bool, default is True :param - apply_attention: (bool, default is True), if True, attention mechanism is used :param - apply_attention_before_lstm: (bool, default is True), if True it means attention mechanism will be apply :param before LSTM: :param - use_single_attention_vector: :type - use_single_attention_vector: bool, default is False :param - cell_type_categories_yaml_file: (str, default is None) path and filename of the yaml file used to c :param configure the classifier for cell type: :type configure the classifier for cell type: types of cell, number of classes :param cell_type_categories_default.yaml will be used with pyramidal cells and interneuron and 2 classes.: :param - n_windows_len_to_keep_by_cell: (int, default 2), used only for cell type classifier, indicate how many :param segment of length window_len to keep for training. If too many segment are given then the classifier might: :param not be able to generalize well: :param - frames_to_avoid_for_cell_type: (sequence of int, default []), list of frame indices. If given, then :param segment than contains one of those indices won’t be add to the training. Useful for example if movies are: :param concatenated.:

load_cell_type_categories_from_yaml_file(yaml_file)

Load cell type names from a yaml file. If more than 2 type cells are given, then a multi-class classifier will be used. If 2 type cells are given, then either it could be multi-class or binary classifier, then this choice should be given in the parameters of CinacModel. If 2 cell-type are given, for binary classifier, it should be precised which cell type should be predicted if we get more than 0.5 probability. :param yaml_file:

Returns:

add_input_data_from_dir(dir_name, verbose=0, display_cells_count=False)

Add input data loading all .cinac file in dir_name If a (UTF-8 encoded) txt file is in the dir, it is parsed in order to give to each cinac_file an id the format is for each line: cinac_file_name: id :param dir_name: str, path + directory from which to load .cinac files :param verbose: 0 no print, 1 informations are printed :param display_cells_count: if True, print the number of cells added in training and the number of sessions associated, :param common field of view are identified using the basename of the ci movie in the cinac file:

Returns:

add_input_data(cinac_file_names, session_ids=None, verbose=0, cinac_files_only_for_training=None, cinac_files_to_keep_absolutely=None, cinac_files_to_exclude=None, display_cells_count=False)

Add input data. :param cinac_file_name: str or list of str, represents the files .cinac :param session_ids: None if no session_id otherwise a tuple, list or just a string (or int) representing the :param id of each cinac_file: :type id of each cinac_file: one id can be common to several cinac_file :param verbose: 0 no print, 1 informations are printed :param cinac_files_to_exclude: list of String or None, if the cinac_file_name is in the list, then we don’t add it :param display_cells_count: if True, print the number of cells added in training and the number of sessions associated, :param common field of view are identified using the basename of the ci movie in the cinac file:

Returns:

__build_model()

Returns:

_split_and_stratify_cell_type_mode_data(verbose=0)

Split (between validation and training) and stratify the data, should be used when self.cell_type_classifier_mode is True :param verbose:

Returns:

_split_and_stratify_data_for_window_len_h5(verbose=0)

Split (between validation and training) and stratify the data

Returns:

_split_and_stratify_data(verbose=0)

Split (between validation and training) and stratify the data

Returns:

prepare_model(verbose=0)

Will build the model that will be use to fit the data. Should be called only after the data has been set. Returns:

fit()