def __define_grouped_convolutions(self, input_shape, n_groups, n_channels_per_branch, is_dilated, layer_num): """ Define layers inside grouped convolutional block. """ n_channels_in = input_shape[1] n_branches = 5 n_channels_per_group_in = int(n_channels_in / n_groups) # 每一个group的输入通道数 n_channels_out = int(n_groups * n_branches * n_channels_per_branch) # timeception的输出总通道数 n_channels_per_group_out = int(n_channels_out / n_groups) # 每一个group的输出通道数 # 通道数要能被group整除 assert n_channels_in % n_groups == 0 assert n_channels_out % n_groups == 0 # type of multi-scale kernels to use: either multi_kernel_sizes or multi_dilation_rates if is_dilated: # 固定尺度的卷积核,多尺度的空洞卷积 kernel_sizes = (3, 3, 3) dilation_rates = (1, 2, 3) else: kernel_sizes = (3, 5, 7) # 多尺度的卷积核 dilation_rates = (1, 1, 1) input_shape_per_group = list(input_shape) # (N,C,T,H,W) input_shape_per_group[1] = n_channels_per_group_in # loop on groups, and define convolutions in each group for idx_group in range(n_groups): group_num = idx_group + 1 self.__define_temporal_convolutional_block(input_shape_per_group, n_channels_per_branch, kernel_sizes, dilation_rates, layer_num, group_num) # activation layer_name = 'relu_tc%d' % (layer_num) layer = ReLU() layer._name = layer_name setattr(self, layer_name, layer) # shuffle channels layer_name = 'shuffle_tc%d' % (layer_num) layer = ChannelShuffleLayer(n_channels_out, n_groups) layer._name = layer_name setattr(self, layer_name, layer)
def __define_grouped_convolutions(self, input_shape, n_groups, n_channels_per_branch, is_dilated, layer_num): ''' Define layers inside grouped convolutional block. 定义timeception中的操作 :param input_shape: (32, 1024, 128, 7, 7):1024输入的通道数 :param n_groups: 8 :param n_channels_per_branch: [32,40,50,62] :param is_dilated: :param layer_num: 当前的层数 :return: ''' n_channels_in = input_shape[1] n_branches = 5 n_channels_per_group_in = int(n_channels_in / n_groups) #每个group输入通道的个数 = 128 n_channels_out = int(n_groups * n_branches * n_channels_per_branch) #整个temporal层的输出通道数 n_channels_per_group_out = int(n_channels_out / n_groups) #每个group的输出通道的个数 assert n_channels_in % n_groups == 0 #断言表达式,否的话抛出异常 assert n_channels_out % n_groups == 0 # type of multi-scale kernels to use: either multi_kernel_sizes or multi_dilation_rates # 设置膨胀与核大小已应对多变的复杂动作时长 if is_dilated: kernel_sizes = (3, 3, 3) dilation_rates = (1, 2, 3) else: kernel_sizes = (3, 5, 7) dilation_rates = (1, 1, 1) input_shape_per_group = list(input_shape) input_shape_per_group[ 1] = n_channels_per_group_in #(32, 128, 128, 7, 7) # loop on groups, and define convolutions in each group # 对每一层的每一个group进行定义具体的操作 for idx_group in range(n_groups): group_num = idx_group + 1 #当前的group数 #定义每个group的操作 self.__define_temporal_convolutional_block(input_shape_per_group, n_channels_per_branch, kernel_sizes, dilation_rates, layer_num, group_num) # activation 定义激活操作 layer_name = 'relu_tc%d' % (layer_num) layer = ReLU() layer._name = layer_name setattr(self, layer_name, layer) # shuffle channels 定义混洗操作 layer_name = 'shuffle_tc%d' % (layer_num) layer = ChannelShuffleLayer(n_channels_out, n_groups) layer._name = layer_name setattr(self, layer_name, layer)