def compute_output_shape(self, input_shape):
        if isinstance(input_shape, list):
            input_shape = input_shape[0]

        cell = self.cell
        if cell.data_format == 'channels_first':
            rows = input_shape[3]
            cols = input_shape[4]
            depth = input_shape[5]
        elif cell.data_format == 'channels_last':
            rows = input_shape[2]
            cols = input_shape[3]
            depth = input_shape[4]
#         rows = conv_utils.conv_output_length(rows,
#                                              cell.kernel_size[0],
#                                              padding=cell.padding,
#                                              stride=cell.strides[0],
#                                              dilation=cell.dilation_rate[0])
#         cols = conv_utils.conv_output_length(cols,
#                                              cell.kernel_size[1],
#                                              padding=cell.padding,
#                                              stride=cell.strides[1],
#                                              dilation=cell.dilation_rate[1])
#         depth = conv_utils.conv_output_length(depth,
#                                              cell.kernel_size[2],
#                                              padding=cell.padding,
#                                              stride=cell.strides[2],
#                                              dilation=cell.dilation_rate[2])

        output_shape = input_shape[:2] + (rows, cols, depth, cell.filters)
        output_shape = transpose_shape(output_shape,
                                       cell.data_format,
                                       spatial_axes=(2, 3, 4))

        if not self.return_sequences:
            output_shape = output_shape[:1] + output_shape[2:]

        if self.return_state:
            output_shape = [output_shape]
            base = (input_shape[0], rows, cols, depth, cell.filters)
            base = transpose_shape(base,
                                   cell.data_format,
                                   spatial_axes=(1, 2, 3))
            output_shape += [base[:] for _ in range(2)]
        return output_shape
Exemplo n.º 2
0
 def compute_output_shape(self, input_shape):
     size_all_dims = (1, ) + self.size + (1, )
     spatial_axes = list(range(1, 1 + self.rank))
     size_all_dims = transpose_shape(size_all_dims, self.data_format,
                                     spatial_axes)
     output_shape = list(input_shape)
     for dim in range(len(output_shape)):
         if output_shape[dim] is not None:
             output_shape[dim] *= size_all_dims[dim]
     return tuple(output_shape)
 def compute_output_shape(self, input_shape):
     padding_all_dims = ((0, 0), ) + self.padding + ((0, 0), )
     spatial_axes = list(range(1, 1 + self.rank))
     padding_all_dims = transpose_shape(padding_all_dims, self.data_format,
                                        spatial_axes)
     output_shape = list(input_shape)
     for dim in range(len(output_shape)):
         if output_shape[dim] is not None:
             output_shape[dim] += sum(padding_all_dims[dim])
     return tuple(output_shape)
Exemplo n.º 4
0
def spatial_3d_padding(x, padding=((1, 1), (1, 1), (1, 1)), data_format=None):
    all_dims_padding = ((0, 0), ) + padding + ((0, 0), )
    all_dims_padding = transpose_shape(all_dims_padding,
                                       data_format,
                                       spatial_axes=(1, 2, 3))
    return np.pad(x, all_dims_padding, mode='constant')
Exemplo n.º 5
0
def spatial_3d_padding(x, padding=((1, 1), (1, 1), (1, 1)), data_format=None):
    all_dims_padding = ((0, 0),) + padding + ((0, 0),)
    all_dims_padding = transpose_shape(all_dims_padding, data_format,
                                       spatial_axes=(1, 2, 3))
    return np.pad(x, all_dims_padding, mode='constant')