prompt
large_stringlengths 72
9.34k
| completion
large_stringlengths 0
7.61k
|
---|---|
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
<|fim_middle|>
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | pass |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
<|fim_middle|>
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | strides = pool_size |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
<|fim_middle|>
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | data_format = default_data_format |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
<|fim_middle|>
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | strides = self.pool_size |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
<|fim_middle|>
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | rows = input_shape[2]
cols = input_shape[3] |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
<|fim_middle|>
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | rows = input_shape[1]
cols = input_shape[2] |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
<|fim_middle|>
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | raise Exception('Invalid dim_ordering: ' + self.dim_ordering) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
<|fim_middle|>
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | return (input_shape[0], input_shape[1], rows, cols) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
<|fim_middle|>
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | return (input_shape[0], rows, cols, input_shape[3]) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
<|fim_middle|>
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | raise Exception('Invalid dim_ordering: ' + self.dim_ordering) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
<|fim_middle|>
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | dim_ordering = default_data_format |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
<|fim_middle|>
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | strides = self.pool_size |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
<|fim_middle|>
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4] |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
<|fim_middle|>
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3] |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
<|fim_middle|>
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | raise Exception('Invalid dim_ordering: ' + self.dim_ordering) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
<|fim_middle|>
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
<|fim_middle|>
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4]) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
<|fim_middle|>
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | raise Exception('Invalid dim_ordering: ' + self.dim_ordering) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
<|fim_middle|>
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | data_format = default_data_format |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
<|fim_middle|>
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | return (input_shape[0], input_shape[3]) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
<|fim_middle|>
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | return (input_shape[0], input_shape[1]) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
<|fim_middle|>
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | data_format = default_data_format |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
<|fim_middle|>
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | return (input_shape[0], input_shape[4]) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
<|fim_middle|>
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | return (input_shape[0], input_shape[1]) |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
<|fim_middle|>
<|fim▁end|> | pass |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def <|fim_middle|>(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def <|fim_middle|>(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | get_output_shape_for |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def <|fim_middle|>(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def <|fim_middle|>(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def <|fim_middle|>(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def <|fim_middle|>(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | get_output_shape_for |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def <|fim_middle|>(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def <|fim_middle|>(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def <|fim_middle|>(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def <|fim_middle|>(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | get_output_shape_for |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def <|fim_middle|>(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def <|fim_middle|>(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def <|fim_middle|>(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def <|fim_middle|>(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | get_output_shape_for |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def <|fim_middle|>(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def <|fim_middle|>(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | get_output_shape_for |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def <|fim_middle|>(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | __init__ |
<|file_name|>layers_pooling.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'ar'
from layers_basic import LW_Layer, default_data_format
from layers_convolutional import conv_output_length
###############################################
class _LW_Pooling1D(LW_Layer):
input_dim = 3
def __init__(self, pool_size=2, strides=None, padding='valid'):
if strides is None:
strides = pool_size
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.pool_length = pool_size
self.stride = strides
self.border_mode = padding
def get_output_shape_for(self, input_shape):
length = conv_output_length(input_shape[1], self.pool_length, self.border_mode, self.stride)
return (input_shape[0], length, input_shape[2])
class LW_MaxPooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_MaxPooling1D, self).__init__(pool_size, strides, padding)
class LW_AveragePooling1D(_LW_Pooling1D):
def __init__(self, pool_size=2, strides=None, padding='valid'):
super(LW_AveragePooling1D, self).__init__(pool_size, strides, padding)
###############################################
class _LW_Pooling2D(LW_Layer):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
if data_format == 'default':
data_format = default_data_format
assert data_format in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert padding in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = padding
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
rows = input_shape[2]
cols = input_shape[3]
elif self.dim_ordering == 'channels_last':
rows = input_shape[1]
cols = input_shape[2]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
rows = conv_output_length(rows, self.pool_size[0], self.border_mode, self.strides[0])
cols = conv_output_length(cols, self.pool_size[1], self.border_mode, self.strides[1])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], rows, cols)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], rows, cols, input_shape[3])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_MaxPooling2D, self).__init__(pool_size, strides, padding, data_format)
class LW_AveragePooling2D(_LW_Pooling2D):
def __init__(self, pool_size=(2, 2), strides=None, padding='valid', data_format='default'):
super(LW_AveragePooling2D, self).__init__(pool_size, strides, padding, data_format)
###############################################
class _LW_Pooling3D(LW_Layer):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
if dim_ordering == 'default':
dim_ordering = default_data_format
assert dim_ordering in {'channels_last', 'channels_first'}, 'data_format must be in {channels_last, channels_first}'
self.pool_size = tuple(pool_size)
if strides is None:
strides = self.pool_size
self.strides = tuple(strides)
assert border_mode in {'valid', 'same'}, 'border_mode must be in {valid, same}'
self.border_mode = border_mode
self.dim_ordering = dim_ordering
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_first':
len_dim1 = input_shape[2]
len_dim2 = input_shape[3]
len_dim3 = input_shape[4]
elif self.dim_ordering == 'channels_last':
len_dim1 = input_shape[1]
len_dim2 = input_shape[2]
len_dim3 = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
len_dim1 = conv_output_length(len_dim1, self.pool_size[0], self.border_mode, self.strides[0])
len_dim2 = conv_output_length(len_dim2, self.pool_size[1], self.border_mode, self.strides[1])
len_dim3 = conv_output_length(len_dim3, self.pool_size[2], self.border_mode, self.strides[2])
if self.dim_ordering == 'channels_first':
return (input_shape[0], input_shape[1], len_dim1, len_dim2, len_dim3)
elif self.dim_ordering == 'channels_last':
return (input_shape[0], len_dim1, len_dim2, len_dim3, input_shape[4])
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
class LW_MaxPooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_MaxPooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
class LW_AveragePooling3D(_LW_Pooling3D):
def __init__(self, pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='default'):
super(LW_AveragePooling3D, self).__init__(pool_size, strides, border_mode, dim_ordering)
###############################################
class _LW_GlobalPooling1D(LW_Layer):
def __init__(self):
pass
def get_output_shape_for(self, input_shape):
return (input_shape[0], input_shape[2])
class LW_GlobalAveragePooling1D(_LW_GlobalPooling1D):
pass
class LW_GlobalMaxPooling1D(_LW_GlobalPooling1D):
pass
###############################################
class _LW_GlobalPooling2D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def get_output_shape_for(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[3])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling2D(_LW_GlobalPooling2D):
pass
class LW_GlobalMaxPooling2D(_LW_GlobalPooling2D):
pass
###############################################
class _LW_GlobalPooling3D(LW_Layer):
def __init__(self, data_format='default'):
if data_format == 'default':
data_format = default_data_format
self.dim_ordering = data_format
def <|fim_middle|>(self, input_shape):
if self.dim_ordering == 'channels_last':
return (input_shape[0], input_shape[4])
else:
return (input_shape[0], input_shape[1])
class LW_GlobalAveragePooling3D(_LW_GlobalPooling3D):
pass
class LW_GlobalMaxPooling3D(_LW_GlobalPooling3D):
pass
###############################################
if __name__ == '__main__':
pass<|fim▁end|> | get_output_shape_for |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):<|fim▁hole|> # at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..<|fim▁end|> | """Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
<|fim_middle|>
<|fim▁end|> | """Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this.. |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
<|fim_middle|>
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys())) |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
<|fim_middle|>
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | """Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
<|fim_middle|>
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | """Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
<|fim_middle|>
<|fim▁end|> | """Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this.. |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
<|fim_middle|>
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | assert IAuth.providedBy(auth) |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
<|fim_middle|>
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | self.config[act] = kwargs[act]
del kwargs[act] |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
<|fim_middle|>
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys())) |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
<|fim_middle|>
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | raise KeyError("unknown action") |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
<|fim_middle|>
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | return True |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
<|fim_middle|>
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | raise KeyError("unknown action") |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
<|fim_middle|>
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | return True |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
<|fim_middle|>
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | raise KeyError("unknown action") |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
<|fim_middle|>
<|fim▁end|> | if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this.. |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
<|fim_middle|>
else:
return True # anyone can do this..
<|fim▁end|> | if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
<|fim_middle|>
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | return False |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
<|fim_middle|>
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | return False |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
<|fim_middle|>
return False
else:
return True # anyone can do this..
<|fim▁end|> | if callable(cfg) and not cfg(user, *args):
return False
return True |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
<|fim_middle|>
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | return False |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
<|fim_middle|>
<|fim▁end|> | return True # anyone can do this.. |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def <|fim_middle|>(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | __init__ |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def <|fim_middle|>(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | advertiseAction |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def <|fim_middle|>(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def actionAllowed(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | needAuthForm |
<|file_name|>authz.py<|end_file_name|><|fim▁begin|>from buildbot.status.web.auth import IAuth
class Authz(object):
"""Decide who can do what."""
knownActions = [
# If you add a new action here, be sure to also update the documentation
# at docs/cfg-statustargets.texinfo
'gracefulShutdown',
'forceBuild',
'forceAllBuilds',
'pingBuilder',
'stopBuild',
'stopAllBuilds',
'cancelPendingBuild',
]
def __init__(self,
default_action=False,
auth=None,
**kwargs):
self.auth = auth
if auth:
assert IAuth.providedBy(auth)
self.config = dict( (a, default_action) for a in self.knownActions )
for act in self.knownActions:
if act in kwargs:
self.config[act] = kwargs[act]
del kwargs[act]
if kwargs:
raise ValueError("unknown authorization action(s) " + ", ".join(kwargs.keys()))
def advertiseAction(self, action):
"""Should the web interface even show the form for ACTION?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
return True
return False
def needAuthForm(self, action):
"""Does this action require an authentication form?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg == 'auth' or callable(cfg):
return True
return False
def <|fim_middle|>(self, action, request, *args):
"""Is this ACTION allowed, given this http REQUEST?"""
if action not in self.knownActions:
raise KeyError("unknown action")
cfg = self.config.get(action, False)
if cfg:
if cfg == 'auth' or callable(cfg):
if not self.auth:
return False
user = request.args.get("username", ["<unknown>"])[0]
passwd = request.args.get("passwd", ["<no-password>"])[0]
if user == "<unknown>" or passwd == "<no-password>":
return False
if self.auth.authenticate(user, passwd):
if callable(cfg) and not cfg(user, *args):
return False
return True
return False
else:
return True # anyone can do this..
<|fim▁end|> | actionAllowed |
<|file_name|>__init__.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""
Linguistic and other taggers.
Tagging each token in a sentence with supplementary information,
such as its part-of-speech (POS) tag, and named entity (NE) tag.
"""
__all__ = [
"PerceptronTagger",
"pos_tag",
"pos_tag_sents",
"tag_provinces",
"chunk_parse",
"NER",
]
<|fim▁hole|>from pythainlp.tag.pos_tag import pos_tag, pos_tag_sents
from pythainlp.tag._tag_perceptron import PerceptronTagger
from pythainlp.tag.chunk import chunk_parse
from pythainlp.tag.named_entity import NER<|fim▁end|> | from pythainlp.tag.locations import tag_provinces |
<|file_name|>linkbox.py<|end_file_name|><|fim▁begin|>#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
<|fim▁hole|>#
# Standard python modules
#
#-------------------------------------------------------------------------
import logging
_LOG = logging.getLogger(".widgets.linkbox")
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
from gi.repository import GObject
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# LinkBox class
#
#-------------------------------------------------------------------------
class LinkBox(Gtk.HBox):
def __init__(self, link, button):
GObject.GObject.__init__(self)
self.set_spacing(6)
self.pack_start(link, False, True, 0)
if button:
self.pack_start(button, False, True, 0)
self.show()<|fim▁end|> | __all__ = ["LinkBox"]
#------------------------------------------------------------------------- |
<|file_name|>linkbox.py<|end_file_name|><|fim▁begin|>#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
__all__ = ["LinkBox"]
#-------------------------------------------------------------------------
#
# Standard python modules
#
#-------------------------------------------------------------------------
import logging
_LOG = logging.getLogger(".widgets.linkbox")
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
from gi.repository import GObject
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# LinkBox class
#
#-------------------------------------------------------------------------
class LinkBox(Gtk.HBox):
<|fim_middle|>
<|fim▁end|> | def __init__(self, link, button):
GObject.GObject.__init__(self)
self.set_spacing(6)
self.pack_start(link, False, True, 0)
if button:
self.pack_start(button, False, True, 0)
self.show() |
<|file_name|>linkbox.py<|end_file_name|><|fim▁begin|>#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
__all__ = ["LinkBox"]
#-------------------------------------------------------------------------
#
# Standard python modules
#
#-------------------------------------------------------------------------
import logging
_LOG = logging.getLogger(".widgets.linkbox")
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
from gi.repository import GObject
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# LinkBox class
#
#-------------------------------------------------------------------------
class LinkBox(Gtk.HBox):
def __init__(self, link, button):
<|fim_middle|>
<|fim▁end|> | GObject.GObject.__init__(self)
self.set_spacing(6)
self.pack_start(link, False, True, 0)
if button:
self.pack_start(button, False, True, 0)
self.show() |
<|file_name|>linkbox.py<|end_file_name|><|fim▁begin|>#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
__all__ = ["LinkBox"]
#-------------------------------------------------------------------------
#
# Standard python modules
#
#-------------------------------------------------------------------------
import logging
_LOG = logging.getLogger(".widgets.linkbox")
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
from gi.repository import GObject
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# LinkBox class
#
#-------------------------------------------------------------------------
class LinkBox(Gtk.HBox):
def __init__(self, link, button):
GObject.GObject.__init__(self)
self.set_spacing(6)
self.pack_start(link, False, True, 0)
if button:
<|fim_middle|>
self.show()
<|fim▁end|> | self.pack_start(button, False, True, 0) |
<|file_name|>linkbox.py<|end_file_name|><|fim▁begin|>#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
__all__ = ["LinkBox"]
#-------------------------------------------------------------------------
#
# Standard python modules
#
#-------------------------------------------------------------------------
import logging
_LOG = logging.getLogger(".widgets.linkbox")
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
from gi.repository import GObject
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# LinkBox class
#
#-------------------------------------------------------------------------
class LinkBox(Gtk.HBox):
def <|fim_middle|>(self, link, button):
GObject.GObject.__init__(self)
self.set_spacing(6)
self.pack_start(link, False, True, 0)
if button:
self.pack_start(button, False, True, 0)
self.show()
<|fim▁end|> | __init__ |
<|file_name|>git.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""Git tools."""
from shlex import split
from plumbum import ProcessExecutionError
from plumbum.cmd import git
DEVELOPMENT_BRANCH = "develop"
def run_git(*args, dry_run=False, quiet=False):
"""Run a git command, print it before executing and capture the output."""
command = git[split(" ".join(args))]
if not quiet:
print("{}{}".format("[DRY-RUN] " if dry_run else "", command))
if dry_run:
return ""<|fim▁hole|> print(rv)
return rv
def branch_exists(branch):
"""Return True if the branch exists."""
try:
run_git("rev-parse --verify {}".format(branch), quiet=True)
return True
except ProcessExecutionError:
return False
def get_current_branch():
"""Get the current branch name."""
return run_git("rev-parse --abbrev-ref HEAD", quiet=True).strip()<|fim▁end|> | rv = command()
if not quiet and rv: |
<|file_name|>git.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""Git tools."""
from shlex import split
from plumbum import ProcessExecutionError
from plumbum.cmd import git
DEVELOPMENT_BRANCH = "develop"
def run_git(*args, dry_run=False, quiet=False):
<|fim_middle|>
def branch_exists(branch):
"""Return True if the branch exists."""
try:
run_git("rev-parse --verify {}".format(branch), quiet=True)
return True
except ProcessExecutionError:
return False
def get_current_branch():
"""Get the current branch name."""
return run_git("rev-parse --abbrev-ref HEAD", quiet=True).strip()
<|fim▁end|> | """Run a git command, print it before executing and capture the output."""
command = git[split(" ".join(args))]
if not quiet:
print("{}{}".format("[DRY-RUN] " if dry_run else "", command))
if dry_run:
return ""
rv = command()
if not quiet and rv:
print(rv)
return rv |
<|file_name|>git.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""Git tools."""
from shlex import split
from plumbum import ProcessExecutionError
from plumbum.cmd import git
DEVELOPMENT_BRANCH = "develop"
def run_git(*args, dry_run=False, quiet=False):
"""Run a git command, print it before executing and capture the output."""
command = git[split(" ".join(args))]
if not quiet:
print("{}{}".format("[DRY-RUN] " if dry_run else "", command))
if dry_run:
return ""
rv = command()
if not quiet and rv:
print(rv)
return rv
def branch_exists(branch):
<|fim_middle|>
def get_current_branch():
"""Get the current branch name."""
return run_git("rev-parse --abbrev-ref HEAD", quiet=True).strip()
<|fim▁end|> | """Return True if the branch exists."""
try:
run_git("rev-parse --verify {}".format(branch), quiet=True)
return True
except ProcessExecutionError:
return False |
<|file_name|>git.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""Git tools."""
from shlex import split
from plumbum import ProcessExecutionError
from plumbum.cmd import git
DEVELOPMENT_BRANCH = "develop"
def run_git(*args, dry_run=False, quiet=False):
"""Run a git command, print it before executing and capture the output."""
command = git[split(" ".join(args))]
if not quiet:
print("{}{}".format("[DRY-RUN] " if dry_run else "", command))
if dry_run:
return ""
rv = command()
if not quiet and rv:
print(rv)
return rv
def branch_exists(branch):
"""Return True if the branch exists."""
try:
run_git("rev-parse --verify {}".format(branch), quiet=True)
return True
except ProcessExecutionError:
return False
def get_current_branch():
<|fim_middle|>
<|fim▁end|> | """Get the current branch name."""
return run_git("rev-parse --abbrev-ref HEAD", quiet=True).strip() |
<|file_name|>git.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""Git tools."""
from shlex import split
from plumbum import ProcessExecutionError
from plumbum.cmd import git
DEVELOPMENT_BRANCH = "develop"
def run_git(*args, dry_run=False, quiet=False):
"""Run a git command, print it before executing and capture the output."""
command = git[split(" ".join(args))]
if not quiet:
<|fim_middle|>
if dry_run:
return ""
rv = command()
if not quiet and rv:
print(rv)
return rv
def branch_exists(branch):
"""Return True if the branch exists."""
try:
run_git("rev-parse --verify {}".format(branch), quiet=True)
return True
except ProcessExecutionError:
return False
def get_current_branch():
"""Get the current branch name."""
return run_git("rev-parse --abbrev-ref HEAD", quiet=True).strip()
<|fim▁end|> | print("{}{}".format("[DRY-RUN] " if dry_run else "", command)) |
<|file_name|>git.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""Git tools."""
from shlex import split
from plumbum import ProcessExecutionError
from plumbum.cmd import git
DEVELOPMENT_BRANCH = "develop"
def run_git(*args, dry_run=False, quiet=False):
"""Run a git command, print it before executing and capture the output."""
command = git[split(" ".join(args))]
if not quiet:
print("{}{}".format("[DRY-RUN] " if dry_run else "", command))
if dry_run:
<|fim_middle|>
rv = command()
if not quiet and rv:
print(rv)
return rv
def branch_exists(branch):
"""Return True if the branch exists."""
try:
run_git("rev-parse --verify {}".format(branch), quiet=True)
return True
except ProcessExecutionError:
return False
def get_current_branch():
"""Get the current branch name."""
return run_git("rev-parse --abbrev-ref HEAD", quiet=True).strip()
<|fim▁end|> | return "" |
<|file_name|>git.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""Git tools."""
from shlex import split
from plumbum import ProcessExecutionError
from plumbum.cmd import git
DEVELOPMENT_BRANCH = "develop"
def run_git(*args, dry_run=False, quiet=False):
"""Run a git command, print it before executing and capture the output."""
command = git[split(" ".join(args))]
if not quiet:
print("{}{}".format("[DRY-RUN] " if dry_run else "", command))
if dry_run:
return ""
rv = command()
if not quiet and rv:
<|fim_middle|>
return rv
def branch_exists(branch):
"""Return True if the branch exists."""
try:
run_git("rev-parse --verify {}".format(branch), quiet=True)
return True
except ProcessExecutionError:
return False
def get_current_branch():
"""Get the current branch name."""
return run_git("rev-parse --abbrev-ref HEAD", quiet=True).strip()
<|fim▁end|> | print(rv) |
<|file_name|>git.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""Git tools."""
from shlex import split
from plumbum import ProcessExecutionError
from plumbum.cmd import git
DEVELOPMENT_BRANCH = "develop"
def <|fim_middle|>(*args, dry_run=False, quiet=False):
"""Run a git command, print it before executing and capture the output."""
command = git[split(" ".join(args))]
if not quiet:
print("{}{}".format("[DRY-RUN] " if dry_run else "", command))
if dry_run:
return ""
rv = command()
if not quiet and rv:
print(rv)
return rv
def branch_exists(branch):
"""Return True if the branch exists."""
try:
run_git("rev-parse --verify {}".format(branch), quiet=True)
return True
except ProcessExecutionError:
return False
def get_current_branch():
"""Get the current branch name."""
return run_git("rev-parse --abbrev-ref HEAD", quiet=True).strip()
<|fim▁end|> | run_git |
<|file_name|>git.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""Git tools."""
from shlex import split
from plumbum import ProcessExecutionError
from plumbum.cmd import git
DEVELOPMENT_BRANCH = "develop"
def run_git(*args, dry_run=False, quiet=False):
"""Run a git command, print it before executing and capture the output."""
command = git[split(" ".join(args))]
if not quiet:
print("{}{}".format("[DRY-RUN] " if dry_run else "", command))
if dry_run:
return ""
rv = command()
if not quiet and rv:
print(rv)
return rv
def <|fim_middle|>(branch):
"""Return True if the branch exists."""
try:
run_git("rev-parse --verify {}".format(branch), quiet=True)
return True
except ProcessExecutionError:
return False
def get_current_branch():
"""Get the current branch name."""
return run_git("rev-parse --abbrev-ref HEAD", quiet=True).strip()
<|fim▁end|> | branch_exists |
<|file_name|>git.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
"""Git tools."""
from shlex import split
from plumbum import ProcessExecutionError
from plumbum.cmd import git
DEVELOPMENT_BRANCH = "develop"
def run_git(*args, dry_run=False, quiet=False):
"""Run a git command, print it before executing and capture the output."""
command = git[split(" ".join(args))]
if not quiet:
print("{}{}".format("[DRY-RUN] " if dry_run else "", command))
if dry_run:
return ""
rv = command()
if not quiet and rv:
print(rv)
return rv
def branch_exists(branch):
"""Return True if the branch exists."""
try:
run_git("rev-parse --verify {}".format(branch), quiet=True)
return True
except ProcessExecutionError:
return False
def <|fim_middle|>():
"""Get the current branch name."""
return run_git("rev-parse --abbrev-ref HEAD", quiet=True).strip()
<|fim▁end|> | get_current_branch |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
"""BrowserID authentication backend"""
name = 'persona'
<|fim▁hole|>
def get_user_details(self, response):
"""Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''}
def extra_data(self, user, uid, response, details):
"""Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']}
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if not 'assertion' in self.data:
raise AuthMissingParameter(self, 'assertion')
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
raise AuthFailed(self)
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)<|fim▁end|> | def get_user_id(self, details, response):
"""Use BrowserID email as ID"""
return details['email'] |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
<|fim_middle|>
<|fim▁end|> | """BrowserID authentication backend"""
name = 'persona'
def get_user_id(self, details, response):
"""Use BrowserID email as ID"""
return details['email']
def get_user_details(self, response):
"""Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''}
def extra_data(self, user, uid, response, details):
"""Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']}
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if not 'assertion' in self.data:
raise AuthMissingParameter(self, 'assertion')
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
raise AuthFailed(self)
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs) |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
"""BrowserID authentication backend"""
name = 'persona'
def get_user_id(self, details, response):
<|fim_middle|>
def get_user_details(self, response):
"""Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''}
def extra_data(self, user, uid, response, details):
"""Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']}
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if not 'assertion' in self.data:
raise AuthMissingParameter(self, 'assertion')
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
raise AuthFailed(self)
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)
<|fim▁end|> | """Use BrowserID email as ID"""
return details['email'] |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
"""BrowserID authentication backend"""
name = 'persona'
def get_user_id(self, details, response):
"""Use BrowserID email as ID"""
return details['email']
def get_user_details(self, response):
<|fim_middle|>
def extra_data(self, user, uid, response, details):
"""Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']}
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if not 'assertion' in self.data:
raise AuthMissingParameter(self, 'assertion')
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
raise AuthFailed(self)
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)
<|fim▁end|> | """Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''} |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
"""BrowserID authentication backend"""
name = 'persona'
def get_user_id(self, details, response):
"""Use BrowserID email as ID"""
return details['email']
def get_user_details(self, response):
"""Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''}
def extra_data(self, user, uid, response, details):
<|fim_middle|>
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if not 'assertion' in self.data:
raise AuthMissingParameter(self, 'assertion')
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
raise AuthFailed(self)
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)
<|fim▁end|> | """Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']} |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
"""BrowserID authentication backend"""
name = 'persona'
def get_user_id(self, details, response):
"""Use BrowserID email as ID"""
return details['email']
def get_user_details(self, response):
"""Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''}
def extra_data(self, user, uid, response, details):
"""Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']}
def auth_complete(self, *args, **kwargs):
<|fim_middle|>
<|fim▁end|> | """Completes loging process, must return user instance"""
if not 'assertion' in self.data:
raise AuthMissingParameter(self, 'assertion')
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
raise AuthFailed(self)
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs) |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
"""BrowserID authentication backend"""
name = 'persona'
def get_user_id(self, details, response):
"""Use BrowserID email as ID"""
return details['email']
def get_user_details(self, response):
"""Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''}
def extra_data(self, user, uid, response, details):
"""Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']}
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if not 'assertion' in self.data:
<|fim_middle|>
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
raise AuthFailed(self)
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)
<|fim▁end|> | raise AuthMissingParameter(self, 'assertion') |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
"""BrowserID authentication backend"""
name = 'persona'
def get_user_id(self, details, response):
"""Use BrowserID email as ID"""
return details['email']
def get_user_details(self, response):
"""Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''}
def extra_data(self, user, uid, response, details):
"""Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']}
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if not 'assertion' in self.data:
raise AuthMissingParameter(self, 'assertion')
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
<|fim_middle|>
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)
<|fim▁end|> | raise AuthFailed(self) |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
"""BrowserID authentication backend"""
name = 'persona'
def <|fim_middle|>(self, details, response):
"""Use BrowserID email as ID"""
return details['email']
def get_user_details(self, response):
"""Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''}
def extra_data(self, user, uid, response, details):
"""Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']}
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if not 'assertion' in self.data:
raise AuthMissingParameter(self, 'assertion')
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
raise AuthFailed(self)
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)
<|fim▁end|> | get_user_id |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
"""BrowserID authentication backend"""
name = 'persona'
def get_user_id(self, details, response):
"""Use BrowserID email as ID"""
return details['email']
def <|fim_middle|>(self, response):
"""Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''}
def extra_data(self, user, uid, response, details):
"""Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']}
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if not 'assertion' in self.data:
raise AuthMissingParameter(self, 'assertion')
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
raise AuthFailed(self)
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)
<|fim▁end|> | get_user_details |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
"""BrowserID authentication backend"""
name = 'persona'
def get_user_id(self, details, response):
"""Use BrowserID email as ID"""
return details['email']
def get_user_details(self, response):
"""Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''}
def <|fim_middle|>(self, user, uid, response, details):
"""Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']}
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if not 'assertion' in self.data:
raise AuthMissingParameter(self, 'assertion')
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
raise AuthFailed(self)
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)
<|fim▁end|> | extra_data |
<|file_name|>persona.py<|end_file_name|><|fim▁begin|>"""
BrowserID support
"""
from social.backends.base import BaseAuth
from social.exceptions import AuthFailed, AuthMissingParameter
class PersonaAuth(BaseAuth):
"""BrowserID authentication backend"""
name = 'persona'
def get_user_id(self, details, response):
"""Use BrowserID email as ID"""
return details['email']
def get_user_details(self, response):
"""Return user details, BrowserID only provides Email."""
# {'status': 'okay',
# 'audience': 'localhost:8000',
# 'expires': 1328983575529,
# 'email': '[email protected]',
# 'issuer': 'browserid.org'}
email = response['email']
return {'username': email.split('@', 1)[0],
'email': email,
'fullname': '',
'first_name': '',
'last_name': ''}
def extra_data(self, user, uid, response, details):
"""Return users extra data"""
return {'audience': response['audience'],
'issuer': response['issuer']}
def <|fim_middle|>(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
if not 'assertion' in self.data:
raise AuthMissingParameter(self, 'assertion')
response = self.get_json('https://browserid.org/verify', data={
'assertion': self.data['assertion'],
'audience': self.strategy.request_host()
}, method='POST')
if response.get('status') == 'failure':
raise AuthFailed(self)
kwargs.update({'response': response, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)
<|fim▁end|> | auth_complete |
<|file_name|>netmiko_sh_arp.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# Use Netmiko to execute 'show arp' on pynet-rtr1, pynet-rtr2, and juniper-srx.
from netmiko import ConnectHandler
def main():
# Definition of routers
rtr1 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
}
rtr2 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
'port': 8022,
}
srx = {
'device_type': 'juniper',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
'port': 9822,
}
# Create a list of all the routers.
all_routers = [rtr1, rtr2, srx]
# Loop through all the routers and show arp.
for a_router in all_routers:
net_connect = ConnectHandler(**a_router)
output = net_connect.send_command("show arp")
print "\n\n>>>>>>>>> Device {0} <<<<<<<<<".format(a_router['device_type'])
print output<|fim▁hole|>if __name__ == "__main__":
main()<|fim▁end|> | print ">>>>>>>>> End <<<<<<<<<"
|
<|file_name|>netmiko_sh_arp.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# Use Netmiko to execute 'show arp' on pynet-rtr1, pynet-rtr2, and juniper-srx.
from netmiko import ConnectHandler
def main():
# Definition of routers
<|fim_middle|>
if __name__ == "__main__":
main()
<|fim▁end|> | rtr1 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
}
rtr2 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
'port': 8022,
}
srx = {
'device_type': 'juniper',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
'port': 9822,
}
# Create a list of all the routers.
all_routers = [rtr1, rtr2, srx]
# Loop through all the routers and show arp.
for a_router in all_routers:
net_connect = ConnectHandler(**a_router)
output = net_connect.send_command("show arp")
print "\n\n>>>>>>>>> Device {0} <<<<<<<<<".format(a_router['device_type'])
print output
print ">>>>>>>>> End <<<<<<<<<" |
<|file_name|>netmiko_sh_arp.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# Use Netmiko to execute 'show arp' on pynet-rtr1, pynet-rtr2, and juniper-srx.
from netmiko import ConnectHandler
def main():
# Definition of routers
rtr1 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
}
rtr2 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
'port': 8022,
}
srx = {
'device_type': 'juniper',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
'port': 9822,
}
# Create a list of all the routers.
all_routers = [rtr1, rtr2, srx]
# Loop through all the routers and show arp.
for a_router in all_routers:
net_connect = ConnectHandler(**a_router)
output = net_connect.send_command("show arp")
print "\n\n>>>>>>>>> Device {0} <<<<<<<<<".format(a_router['device_type'])
print output
print ">>>>>>>>> End <<<<<<<<<"
if __name__ == "__main__":
<|fim_middle|>
<|fim▁end|> | main() |
<|file_name|>netmiko_sh_arp.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# Use Netmiko to execute 'show arp' on pynet-rtr1, pynet-rtr2, and juniper-srx.
from netmiko import ConnectHandler
def <|fim_middle|>():
# Definition of routers
rtr1 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
}
rtr2 = {
'device_type': 'cisco_ios',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
'port': 8022,
}
srx = {
'device_type': 'juniper',
'ip': '50.76.53.27',
'username': 'pyclass',
'password': '88newclass',
'port': 9822,
}
# Create a list of all the routers.
all_routers = [rtr1, rtr2, srx]
# Loop through all the routers and show arp.
for a_router in all_routers:
net_connect = ConnectHandler(**a_router)
output = net_connect.send_command("show arp")
print "\n\n>>>>>>>>> Device {0} <<<<<<<<<".format(a_router['device_type'])
print output
print ">>>>>>>>> End <<<<<<<<<"
if __name__ == "__main__":
main()
<|fim▁end|> | main |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.