def func(self, place): shape = [2, 2, 2, 2, 3] eps = 0.005 dtype = np.float32 if fluid.core.is_compiled_with_rocm( ) else np.float64 x = layers.data('x', shape, False, dtype) y = layers.conv3d(input=x, num_filters=2, filter_size=1, padding=[1, 0, 1, 0, 1, 0], bias_attr=False, use_cudnn=True, groups=1, data_format="NDHWC") x_arr = np.random.uniform(-1, 1, shape).astype(dtype) w = fluid.default_main_program().global_block().all_parameters() w_arr = [] for p in w: w_arr.append(np.random.uniform(-1, 1, p.shape).astype(dtype)) gradient_checker.double_grad_check([x] + w, y, x_init=[x_arr] + w_arr, place=place, eps=eps)
def func(self, place): shape = [2, 4, 5, 3, 2] eps = 0.005 dtype = np.float64 x = layers.data('x', shape, False, dtype) y = layers.conv3d(x, 2, 1, padding=1, bias_attr=False) x_arr = np.random.uniform(-1, 1, shape).astype(dtype) w = fluid.default_main_program().global_block().all_parameters() w_arr = [] for p in w: w_arr.append(np.random.uniform(-1, 1, p.shape).astype(dtype)) gradient_checker.double_grad_check( [x] + w, y, x_init=[x_arr] + w_arr, place=place, eps=eps)
def _build_net(self): # ConvLSTM2D rnn_out, last_hidden = ConvLSTM.convlstm2d_rnn( rnn_input=self.input, init_hidden=None, init_cell=None, padding=1, hidden_h=self.h, hidden_w=self.w, filters=self.filters, filter_size=self.filter_size, sequence_length=self.input_seqlen) # Batch Norm bn = layers.layer_norm(rnn_out, begin_norm_axis=4) # ConvLSTM2D rnn_out, last_hidden = ConvLSTM.convlstm2d_rnn( rnn_input=bn, init_hidden=None, init_cell=None, padding=1, hidden_h=self.h, hidden_w=self.w, filters=self.filters, filter_size=self.filter_size, sequence_length=self.input_seqlen) # Batch Norm bn = layers.layer_norm(rnn_out, begin_norm_axis=4) # ConvLSTM2D rnn_out, last_hidden = ConvLSTM.convlstm2d_rnn( rnn_input=bn, init_hidden=None, init_cell=None, padding=1, hidden_h=self.h, hidden_w=self.w, filters=self.filters, filter_size=self.filter_size, sequence_length=self.input_seqlen) # Batch Norm bn = layers.layer_norm(rnn_out, begin_norm_axis=4) # ConvLSTM2D rnn_out, last_hidden = ConvLSTM.convlstm2d_rnn( rnn_input=bn, init_hidden=None, init_cell=None, padding=1, hidden_h=self.h, hidden_w=self.w, filters=self.filters, filter_size=self.filter_size, sequence_length=self.input_seqlen) # Batch Norm bn = layers.layer_norm(rnn_out, begin_norm_axis=4) # Transpose : (batch x C x D x H x W) tr = layers.transpose(bn, [0, 4, 1, 2, 3]) # Conv3D conv3d = layers.conv3d(input=tr, num_filters=2, filter_size=3, padding=1) # conv3d : (batch x C x D x H x W) conv3d = layers.transpose(conv3d, [0, 2, 3, 4, 1]) # conv3d: (batch x D x H x W x C) return conv3d