def functional(self, place): main = fluid.Program() start = fluid.Program() with fluid.unique_name.guard(): with fluid.program_guard(main, start): input_shape = (-1, -1, -1, -1, self.num_channels) \ if self.channel_last else (-1, self.num_channels, -1, -1, -1) x_var = fluid.data("input", input_shape, dtype=self.dtype) w_var = fluid.data("weight", self.weight_shape, dtype=self.dtype) b_var = fluid.data("bias", (self.num_filters, ), dtype=self.dtype) y_var = F.conv3d_transpose(x_var, w_var, None if self.no_bias else b_var, output_size=self.output_size, padding=self.padding, stride=self.stride, dilation=self.dilation, groups=self.groups, act=self.act, use_cudnn=self.use_cudnn, data_format=self.data_format) feed_dict = {"input": self.input, "weight": self.weight} if self.bias is not None: feed_dict["bias"] = self.bias exe = fluid.Executor(place) exe.run(start) y_np, = exe.run(main, feed=feed_dict, fetch_list=[y_var]) return y_np
def static_graph_case(self): main = fluid.Program() start = fluid.Program() with fluid.unique_name.guard(): with fluid.program_guard(main, start): self.channel_last = self.data_format == "NDHWC" if self.channel_last: x = x = fluid.data("input", (-1, -1, -1, -1, self.in_channels), dtype=self.dtype) else: x = fluid.data("input", (-1, self.in_channels, -1, -1, -1), dtype=self.dtype) weight = fluid.data("weight", self.weight_shape, dtype=self.dtype) if not self.no_bias: bias = fluid.data("bias", self.bias_shape, dtype=self.dtype) y = F.conv3d_transpose(x, weight, None if self.no_bias else bias, output_size=self.output_size, padding=self.padding, stride=self.stride, dilation=self.dilation, groups=self.groups, act=self.act, data_format=self.data_format, use_cudnn=self.use_cudnn)
def dygraph_case(self): with dg.guard(): x = dg.to_variable(self.input, dtype=paddle.float32) w = dg.to_variable(self.filter, dtype=paddle.float32) b = None if self.bias is None else dg.to_variable( self.bias, dtype=paddle.float32) y = F.conv3d_transpose(x, w, b, padding=self.padding, stride=self.stride, dilation=self.dilation, groups=self.groups, data_format=self.data_format)
def dygraph_case(self): with dg.guard(self.place): x = dg.to_variable(self.input) weight = dg.to_variable(self.weight) bias = None if self.no_bias else dg.to_variable(self.bias) y = F.conv3d_transpose(x, weight, bias, output_size=self.output_size, padding=self.padding, stride=self.stride, dilation=self.dilation, act=self.act, groups=self.groups, data_format=self.data_format, use_cudnn=self.use_cudnn) out = y.numpy() return out
def static_graph_case_2(self): main = fluid.Program() start = fluid.Program() with fluid.unique_name.guard(): with fluid.program_guard(main, start): if self.channel_last: x = x = fluid.data("input", (-1, -1, -1, -1, self.in_channels), dtype=self.dtype) else: x = fluid.data("input", (-1, self.in_channels, -1, -1, -1), dtype=self.dtype) weight = fluid.data("weight", self.weight.shape, dtype=self.dtype) if not self.no_bias: bias = fluid.data("bias", self.bias.shape, dtype=self.dtype) y = F.conv3d_transpose(x, weight, None if self.no_bias else bias, output_size=self.output_size, padding=self.padding, stride=self.stride, dilation=self.dilation, groups=self.groups, act=self.act, data_format=self.data_format, use_cudnn=self.use_cudnn) exe = fluid.Executor(self.place) exe.run(start) feed_dict = {"input": self.input, "weight": self.weight} if not self.no_bias: feed_dict["bias"] = self.bias out, = exe.run(main, feed=feed_dict, fetch_list=[y]) return out