def convert_conv(params, w_name, scope_name, inputs, layers, weights, names):
print('<STR_LIT>')<EOL>if names == '<STR_LIT>':<EOL><INDENT>tf_name = '<STR_LIT:C>' + random_string(<NUM_LIT:7>)<EOL><DEDENT>elif names == '<STR_LIT>':<EOL><INDENT>tf_name = w_name<EOL><DEDENT>else:<EOL><INDENT>tf_name = w_name + str(random.random())<EOL><DEDENT>bias_name = '<STR_LIT>'.format(w_name)<EOL>weights_name = '<STR_LIT>'.format(w_name)<EOL>input_name = inputs[<NUM_LIT:0>]<EOL>if len(weights[weights_name].numpy().shape) == <NUM_LIT:5>:  <EOL><INDENT>W = weights[weights_name].numpy().transpose(<NUM_LIT:2>, <NUM_LIT:3>, <NUM_LIT:4>, <NUM_LIT:1>, <NUM_LIT:0>)<EOL>height, width, channels, n_layers, n_filters = W.shape<EOL>if bias_name in weights:<EOL><INDENT>biases = weights[bias_name].numpy()<EOL>has_bias = True<EOL><DEDENT>else:<EOL><INDENT>biases = None<EOL>has_bias = False<EOL><DEDENT>if params['<STR_LIT>'][<NUM_LIT:0>] > <NUM_LIT:0> or params['<STR_LIT>'][<NUM_LIT:1>] > <NUM_LIT:0>:<EOL><INDENT>padding_name = tf_name + '<STR_LIT>'<EOL>padding_layer = keras.layers.ZeroPadding3D(<EOL>padding=(params['<STR_LIT>'][<NUM_LIT:0>],<EOL>params['<STR_LIT>'][<NUM_LIT:1>],<EOL>params['<STR_LIT>'][<NUM_LIT:2>]),<EOL>name=padding_name<EOL>)<EOL>layers[padding_name] = padding_layer(layers[input_name])<EOL>input_name = padding_name<EOL><DEDENT>if has_bias:<EOL><INDENT>weights = [W, biases]<EOL><DEDENT>else:<EOL><INDENT>weights = [W]<EOL><DEDENT>conv = keras.layers.Conv3D(<EOL>filters=n_filters,<EOL>kernel_size=(channels, height, width),<EOL>strides=(params['<STR_LIT>'][<NUM_LIT:0>],<EOL>params['<STR_LIT>'][<NUM_LIT:1>],<EOL>params['<STR_LIT>'][<NUM_LIT:2>]),<EOL>padding='<STR_LIT>',<EOL>weights=weights,<EOL>use_bias=has_bias,<EOL>activation=None,<EOL>dilation_rate=params['<STR_LIT>'][<NUM_LIT:0>],<EOL>bias_initializer='<STR_LIT>', kernel_initializer='<STR_LIT>',<EOL>name=tf_name<EOL>)<EOL>layers[scope_name] = conv(layers[input_name])<EOL><DEDENT>elif len(weights[weights_name].numpy().shape) == <NUM_LIT:4>:  <EOL><INDENT>if params['<STR_LIT>'][<NUM_LIT:0>] > <NUM_LIT:0> or params['<STR_LIT>'][<NUM_LIT:1>] > <NUM_LIT:0>:<EOL><INDENT>padding_name = tf_name + '<STR_LIT>'<EOL>padding_layer = keras.layers.ZeroPadding2D(<EOL>padding=(params['<STR_LIT>'][<NUM_LIT:0>], params['<STR_LIT>'][<NUM_LIT:1>]),<EOL>name=padding_name<EOL>)<EOL>layers[padding_name] = padding_layer(layers[input_name])<EOL>input_name = padding_name<EOL><DEDENT>W = weights[weights_name].numpy().transpose(<NUM_LIT:2>, <NUM_LIT:3>, <NUM_LIT:1>, <NUM_LIT:0>)<EOL>height, width, channels_per_group, out_channels = W.shape<EOL>n_groups = params['<STR_LIT>']<EOL>in_channels = channels_per_group * n_groups<EOL>if n_groups == in_channels and n_groups != <NUM_LIT:1>:<EOL><INDENT>if bias_name in weights:<EOL><INDENT>biases = weights[bias_name].numpy()<EOL>has_bias = True<EOL><DEDENT>else:<EOL><INDENT>biases = None<EOL>has_bias = False<EOL><DEDENT>W = W.transpose(<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:3>, <NUM_LIT:2>)<EOL>if has_bias:<EOL><INDENT>weights = [W, biases]<EOL><DEDENT>else:<EOL><INDENT>weights = [W]<EOL><DEDENT>conv = keras.layers.DepthwiseConv2D(<EOL>kernel_size=(height, width),<EOL>strides=(params['<STR_LIT>'][<NUM_LIT:0>], params['<STR_LIT>'][<NUM_LIT:1>]),<EOL>padding='<STR_LIT>',<EOL>use_bias=has_bias,<EOL>activation=None,<EOL>depth_multiplier=<NUM_LIT:1>,<EOL>weights = weights,<EOL>dilation_rate=params['<STR_LIT>'][<NUM_LIT:0>],<EOL>bias_initializer='<STR_LIT>', kernel_initializer='<STR_LIT>'<EOL>)<EOL>layers[scope_name] = conv(layers[input_name])<EOL><DEDENT>elif n_groups != <NUM_LIT:1>:<EOL><INDENT>def target_layer(x, groups=params['<STR_LIT>'], stride_y=params['<STR_LIT>'][<NUM_LIT:0>], stride_x=params['<STR_LIT>'][<NUM_LIT:1>]):<EOL><INDENT>x = tf.transpose(x, [<NUM_LIT:0>, <NUM_LIT:2>, <NUM_LIT:3>, <NUM_LIT:1>])<EOL>def convolve_lambda(i, k):<EOL><INDENT>return tf.nn.conv2d(i, k, strides=[<NUM_LIT:1>, stride_y, stride_x, <NUM_LIT:1>], padding='<STR_LIT>')<EOL><DEDENT>input_groups = tf.split(axis=<NUM_LIT:3>, num_or_size_splits=groups, value=x)<EOL>weight_groups = tf.split(axis=<NUM_LIT:3>, num_or_size_splits=groups, value=W.transpose(<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:3>))<EOL>output_groups = [convolve_lambda(i, k) for i, k in zip(input_groups, weight_groups)]<EOL>layer = tf.concat(axis=<NUM_LIT:3>, values=output_groups)<EOL>layer = tf.transpose(layer, [<NUM_LIT:0>, <NUM_LIT:3>, <NUM_LIT:1>, <NUM_LIT:2>])<EOL>return layer<EOL><DEDENT>lambda_layer = keras.layers.Lambda(target_layer)<EOL>layers[scope_name] = lambda_layer(layers[input_name])<EOL><DEDENT>else:<EOL><INDENT>if bias_name in weights:<EOL><INDENT>biases = weights[bias_name].numpy()<EOL>has_bias = True<EOL><DEDENT>else:<EOL><INDENT>biases = None<EOL>has_bias = False<EOL><DEDENT>if has_bias:<EOL><INDENT>weights = [W, biases]<EOL><DEDENT>else:<EOL><INDENT>weights = [W]<EOL><DEDENT>conv = keras.layers.Conv2D(<EOL>filters=out_channels,<EOL>kernel_size=(height, width),<EOL>strides=(params['<STR_LIT>'][<NUM_LIT:0>], params['<STR_LIT>'][<NUM_LIT:1>]),<EOL>padding='<STR_LIT>',<EOL>weights=weights,<EOL>use_bias=has_bias,<EOL>activation=None,<EOL>dilation_rate=params['<STR_LIT>'][<NUM_LIT:0>],<EOL>bias_initializer='<STR_LIT>', kernel_initializer='<STR_LIT>',<EOL>name=tf_name<EOL>)<EOL>layers[scope_name] = conv(layers[input_name])<EOL><DEDENT><DEDENT>else:  <EOL><INDENT>W = weights[weights_name].numpy().transpose(<NUM_LIT:2>, <NUM_LIT:1>, <NUM_LIT:0>)<EOL>width, channels, n_filters = W.shape<EOL>n_groups = params['<STR_LIT>']<EOL>if n_groups > <NUM_LIT:1>:<EOL><INDENT>raise AssertionError('<STR_LIT>')<EOL><DEDENT>if bias_name in weights:<EOL><INDENT>biases = weights[bias_name].numpy()<EOL>has_bias = True<EOL><DEDENT>else:<EOL><INDENT>biases = None<EOL>has_bias = False<EOL><DEDENT>padding_name = tf_name + '<STR_LIT>'<EOL>padding_layer = keras.layers.ZeroPadding1D(<EOL>padding=params['<STR_LIT>'][<NUM_LIT:0>],<EOL>name=padding_name<EOL>)<EOL>layers[padding_name] = padding_layer(layers[inputs[<NUM_LIT:0>]])<EOL>input_name = padding_name<EOL>if has_bias:<EOL><INDENT>weights = [W, biases]<EOL><DEDENT>else:<EOL><INDENT>weights = [W]<EOL><DEDENT>conv = keras.layers.Conv1D(<EOL>filters=channels,<EOL>kernel_size=width,<EOL>strides=params['<STR_LIT>'],<EOL>padding='<STR_LIT>',<EOL>weights=weights,<EOL>use_bias=has_bias,<EOL>activation=None,<EOL>data_format='<STR_LIT>',<EOL>dilation_rate=params['<STR_LIT>'],<EOL>bias_initializer='<STR_LIT>', kernel_initializer='<STR_LIT>',<EOL>name=tf_name<EOL>)<EOL>layers[scope_name] = conv(layers[input_name])<EOL><DEDENT>
Convert convolution layer.

Args:
    params: dictionary with layer parameters
    w_name: name prefix in state_dict
    scope_name: pytorch scope name
    inputs: pytorch node inputs
    layers: dictionary with keras tensors
    weights: pytorch state_dict
    names: use short names for keras layers