* doc and style fix

This commit is contained in:
tboquet
2017-02-26 14:39:31 -05:00
parent 2b0092da2e
commit 0eb0a0b08f
+22 -18
View File
@@ -58,7 +58,8 @@ def deconv3d(x, kernel, output_shape, strides=(1, 1, 1),
raise ValueError('Unknown dim_ordering ' + str(dim_ordering))
x = _preprocess_conv3d_input(x, dim_ordering)
output_shape = _preprocess_deconv_output_shape(x, output_shape, dim_ordering)
output_shape = _preprocess_deconv_output_shape(x, output_shape,
dim_ordering)
kernel = _preprocess_conv3d_kernel(kernel, dim_ordering)
kernel = tf.transpose(kernel, (0, 1, 2, 4, 3))
padding = _preprocess_border_mode(border_mode)
@@ -69,32 +70,35 @@ def deconv3d(x, kernel, output_shape, strides=(1, 1, 1),
return _postprocess_conv3d_output(x, dim_ordering)
def extract_image_patches(X, ksizes, ssizes, border_mode="same", dim_ordering="tf"):
def extract_image_patches(x, ksizes, ssizes, border_mode="same",
dim_ordering="tf"):
'''
Extract the patches from an image
Parameters
----------
X : The input image
ksizes : 2-d tuple with the kernel size
ssizes : 2-d tuple with the strides size
border_mode : 'same' or 'valid'
dim_ordering : 'tf' or 'th'
Returns
-------
The (k_w,k_h) patches extracted
TF ==> (batch_size,w,h,k_w,k_h,c)
TH ==> (batch_size,w,h,c,k_w,k_h)
# Parameters
x : The input image
ksizes : 2-d tuple with the kernel size
ssizes : 2-d tuple with the strides size
border_mode : 'same' or 'valid'
dim_ordering : 'tf' or 'th'
# Returns
The (k_w,k_h) patches extracted
TF ==> (batch_size,w,h,k_w,k_h,c)
TH ==> (batch_size,w,h,c,k_w,k_h)
'''
kernel = [1, ksizes[0], ksizes[1], 1]
strides = [1, ssizes[0], ssizes[1], 1]
padding = _preprocess_border_mode(border_mode)
if dim_ordering == "th":
X = KTF.permute_dimensions(X, (0, 2, 3, 1))
bs_i, w_i, h_i, ch_i = KTF.int_shape(X)
patches = tf.extract_image_patches(X, kernel, strides, [1, 1, 1, 1], padding)
x = KTF.permute_dimensions(x, (0, 2, 3, 1))
bs_i, w_i, h_i, ch_i = KTF.int_shape(x)
patches = tf.extract_image_patches(x, kernel, strides, [1, 1, 1, 1],
padding)
# Reshaping to fit Theano
bs, w, h, ch = KTF.int_shape(patches)
patches = tf.reshape(tf.transpose(tf.reshape(patches, [bs, w, h, -1, ch_i]), [0, 1, 2, 4, 3]),
patches = tf.reshape(tf.transpose(
tf.reshape(patches, [bs, w, h, -1, ch_i]), [0, 1, 2, 4, 3]),
[bs, w, h, ch_i, ksizes[0], ksizes[1]])
if dim_ordering == "tf":
patches = KTF.permute_dimensions(patches, [0, 1, 2, 4, 5, 3])