<commit_before># -*- coding: utf-8 -*-
"""Wide Residual Network models for Keras.
Loosely based on https://github.com/titu1994/Wide-Residual-Networks/blob/master/wide_residual_network.py

# Reference
- [Wide Residual Networks](https://arxiv.org/abs/1605.07146)
"""
from keras.models import Model
from keras.layers import Input, Add, Activation, Dropout, Flatten, Dense
from keras.layers.convolutional import Convolution2D, Convolution3D, MaxPooling2D, MaxPooling3D, AveragePooling2D, AveragePooling3D
from keras.layers.normalization import BatchNormalization
from keras import backend as K

from utilities.cnn_utilities import get_dimensions_encoding


def model_wide_residual_network(n_bins, batchsize, **kwargs):
    """
    Defines a Keras WRN model. Wrapper for the create_wrn function.
    :param tuple n_bins: Number of bins (x,y,z,t) of the data that will be fed to the network.
    :param int batchsize: Batchsize of the fed data.
    :param kwargs: arbitrary number of keyword arguments based on the args in create_wrn
    :return: Model model: Keras WRN model.
    """
    if n_bins.count(1) == 2:
        dim = 2
        model = create_wide_residual_network(n_bins, batchsize, dim, **kwargs)

    elif n_bins.count(1) == 1:
        dim = 3
        model = create_wide_residual_network(n_bins, batchsize, dim, **kwargs)

    else:
        raise IOError('Data types other than 2D or 3D are not yet supported. '
                      'Please specify a 2D or 3D n_bins tuple.')

    return model


def decode_input_dimensions(n_bins, batchsize):
    """
    Returns the input dimensions (e.g. batchsize x 11 x 13 x 18 x Channels for 3D)
    and appropriate strides and avg_pooling sizes depending on the projection type.
    :param tuple n_bins: Number of bins (x,y,z,t) of the data.
    :param int batchsize: Batchsize of the fed data.
    :return: tuple input_dim: 2D, 3D or 4D dimensions tuple (ints).
    :return: [tuple, tuple] strides: Strides of the WRN.
    :return: tuple average_pooling_size: Avg_pooling size of the WRN.
    """
    input_dim = get_dimensions_encoding(n_bins, batchsize) # includes batchsize

    # 2d case
    if n_bins[0] == 1 and n_bins[3] == 1 and n_bins.count(1) == 2:
        print 'Using a Wide ResNet with YZ projection'
        strides = [(1,1), (1,1), (2,2)]
        average_pooling_size = (7,9)

    elif n_bins[0] == 1 and n_bins[1] == 1 and n_bins.count(1) == 2:
        print 'Using a Wide ResNet with ZT projection'
        strides = [(1,1), (1,2), (2,2)]
        average_pooling_size = (9,13)

    # 3d case
    elif n_bins[1] == 1 and n_bins.count(1) == 1:
        print 'Using a Wide ResNet with XZT projection'
        strides = [(1,1,1), (1,1,2), (2,2,2)]
        average_pooling_size = (6,9,13)

    elif n_bins[3] == 1 and n_bins.count(1) == 1:
        print 'Using a Wide ResNet with XYZ projection'
        strides = [(1,1,1), (1,1,1), (2,2,2)]
        average_pooling_size = (6,7,9)

    else:
        raise IndexError('The projection type could not be decoded using the parameter n_bins. '
                         'Please check if your projection is available in the function.')

    return input_dim, strides, average_pooling_size

<commit_msg>Added YZT for WRN<commit_after># -*- coding: utf-8 -*-
"""Wide Residual Network models for Keras.
Loosely based on https://github.com/titu1994/Wide-Residual-Networks/blob/master/wide_residual_network.py

# Reference
- [Wide Residual Networks](https://arxiv.org/abs/1605.07146)
"""
from keras.models import Model
from keras.layers import Input, Add, Activation, Dropout, Flatten, Dense
from keras.layers.convolutional import Convolution2D, Convolution3D, MaxPooling2D, MaxPooling3D, AveragePooling2D, AveragePooling3D
from keras.layers.normalization import BatchNormalization
from keras import backend as K

from utilities.cnn_utilities import get_dimensions_encoding


def model_wide_residual_network(n_bins, batchsize, **kwargs):
    """
    Defines a Keras WRN model. Wrapper for the create_wrn function.
    :param tuple n_bins: Number of bins (x,y,z,t) of the data that will be fed to the network.
    :param int batchsize: Batchsize of the fed data.
    :param kwargs: arbitrary number of keyword arguments based on the args in create_wrn
    :return: Model model: Keras WRN model.
    """
    if n_bins.count(1) == 2:
        dim = 2
        model = create_wide_residual_network(n_bins, batchsize, dim, **kwargs)

    elif n_bins.count(1) == 1:
        dim = 3
        model = create_wide_residual_network(n_bins, batchsize, dim, **kwargs)

    else:
        raise IOError('Data types other than 2D or 3D are not yet supported. '
                      'Please specify a 2D or 3D n_bins tuple.')

    return model


def decode_input_dimensions(n_bins, batchsize):
    """
    Returns the input dimensions (e.g. batchsize x 11 x 13 x 18 x Channels for 3D)
    and appropriate strides and avg_pooling sizes depending on the projection type.
    :param tuple n_bins: Number of bins (x,y,z,t) of the data.
    :param int batchsize: Batchsize of the fed data.
    :return: tuple input_dim: 2D, 3D or 4D dimensions tuple (ints).
    :return: [tuple, tuple] strides: Strides of the WRN.
    :return: tuple average_pooling_size: Avg_pooling size of the WRN.
    """
    input_dim = get_dimensions_encoding(n_bins, batchsize) # includes batchsize

    # 2d case
    if n_bins[0] == 1 and n_bins[3] == 1 and n_bins.count(1) == 2:
        print 'Using a Wide ResNet with YZ projection'
        strides = [(1,1), (1,1), (2,2)]
        average_pooling_size = (7,9)

    elif n_bins[0] == 1 and n_bins[1] == 1 and n_bins.count(1) == 2:
        print 'Using a Wide ResNet with ZT projection'
        strides = [(1,1), (1,2), (2,2)]
        average_pooling_size = (9,13)

    # 3d case
    elif n_bins[1] == 1 and n_bins.count(1) == 1:
        print 'Using a Wide ResNet with XZT projection'
        strides = [(1,1,1), (1,1,2), (2,2,2)]
        average_pooling_size = (6,9,13)

    elif n_bins[3] == 1 and n_bins.count(1) == 1:
        print 'Using a Wide ResNet with XYZ projection'
        strides = [(1,1,1), (1,1,1), (2,2,2)]
        average_pooling_size = (6,7,9)

    elif n_bins[0] == 1 and n_bins.count(1) == 1:
        print 'Using a Wide ResNet with YZT projection'
        strides = [(1,1,1), (1,1,2), (2,2,2)]
        average_pooling_size = (7,9,13)

    else:
        raise IndexError('The projection type could not be decoded using the parameter n_bins. '
                         'Please check if your projection is available in the function.')

    return input_dim, strides, average_pooling_size


{'fraction_non_alphanumeric': 0.10497655422780215, 'fraction_numerical': 0.03403418544849493, 'mean_word_length': 3.158490566037736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2109900', 'n_tokens_mistral': 2413, 'n_tokens_neox': 2207, 'n_words': 723}