parameters: (node, reverse_channels)
return_statement: return False
docstring: r"""
          For non grouped convolution:
          BEFORE                          AFTER
  
            previous_op                                   weights
                |                                          |
          ReverseChannels    weights   previous_op   ReverseChannels
                       \     /                 \     /
                        Conv                    Conv
  
          For grouped convolution:
          BEFORE                          AFTER
  
            previous_op                                   weights
                |                                          |
          ReverseChannels    weights   previous_op   ReverseChannels
                       \     /                 \     /
                        Conv                    Conv
                                                 |
                                          ReverseChannels
  
          returns boolean value whatever we should continue propagating current ReverseChannels operation down or not
docstring_summary: r"""
          For non grouped convolution:
          BEFORE                          AFTER
docstring_tokens: r For non grouped convolution : BEFORE AFTER
function: def pass_rc_through_conv(node, reverse_channels):
          r"""
          For non grouped convolution:
          BEFORE                          AFTER
  
            previous_op                                   weights
                |                                          |
          ReverseChannels    weights   previous_op   ReverseChannels
                       \     /                 \     /
                        Conv                    Conv
  
          For grouped convolution:
          BEFORE                          AFTER
  
            previous_op                                   weights
                |                                          |
          ReverseChannels    weights   previous_op   ReverseChannels
                       \     /                 \     /
                        Conv                    Conv
                                                 |
                                          ReverseChannels
  
          returns boolean value whatever we should continue propagating current ReverseChannels operation down or not
          """
          channel_idx = node.soft_get("input_feature_channel", None)
          if channel_idx is None:
              # unknown Convolution configuration, won't propagate reverse_channels down the network
              return False
          weights_shape = node.in_port(1).data.get_shape()
          if weights_shape is None or weights_shape[channel_idx] != reverse_channels.order.size:
              # unexpected Convolution configuration, won't propagate reverse_channels down the network
              return False
  
          # detaching reverse_channels node from the graph
          reverse_channels.out_port(0).get_connection().set_source(
              reverse_channels.in_port(0).get_connection().get_source())
          reverse_channels.in_port(0).disconnect()
  
          group = node.soft_get('group', 1)
  
          # insert ReverseChannels on weights port of Convolution
          ric_to_move_to_weights = reverse_channels if group == 1 else reverse_channels.copy_node()
          ric_to_move_to_weights['axis'] = mo_array(channel_idx)
          src = node.in_port(1).get_connection().get_source()
          node.in_port(1).get_connection().set_source(ric_to_move_to_weights.out_port(0))
          src.disconnect()
          src.connect(ric_to_move_to_weights.in_port(0))
  
          if group != 1 and group == reverse_channels.order.size:
              # grouped Convolution weights channel reversing is not enough to complete channel reversing procedure
              # we propagate ReverseChannels op through current Convolution with new order value for channel permutation
              bottom_channels = node.out_port(0).data.get_shape()[node.channel_dims[0]]
              assert bottom_channels % group == 0
              multiplier = int(bottom_channels / group)
              new_order = np.take(np.arange(bottom_channels).reshape((group, multiplier)),
                                  indices=reverse_channels.order, axis=0).flatten()
              reverse_channels['axis'] = mo_array(reverse_channels.axis.copy())
              reverse_channels['order'] = mo_array(new_order)
  
              node.out_port(0).get_connection().set_source(reverse_channels.out_port(0))
              node.out_port(0).disconnect()
              node.out_port(0).connect(reverse_channels.in_port(0))
  
              # as described above, we are not done reversing channels yet, so we should continue propagating
              # ReverseChannels operation down the network
              return True
          # we reversed channels for sure, nothing to propagate down the network
          return False
function_tokens: def pass_rc_through_conv ( node , reverse_channels ) : channel_idx = node . soft_get ( "input_feature_channel" , None ) if channel_idx is None : # unknown Convolution configuration, won't propagate reverse_channels down the network return False weights_shape = node . in_port ( 1 ) . data . get_shape ( ) if weights_shape is None or weights_shape [ channel_idx ] != reverse_channels . order . size : # unexpected Convolution configuration, won't propagate reverse_channels down the network return False # detaching reverse_channels node from the graph reverse_channels . out_port ( 0 ) . get_connection ( ) . set_source ( reverse_channels . in_port ( 0 ) . get_connection ( ) . get_source ( ) ) reverse_channels . in_port ( 0 ) . disconnect ( ) group = node . soft_get ( 'group' , 1 ) # insert ReverseChannels on weights port of Convolution ric_to_move_to_weights = reverse_channels if group == 1 else reverse_channels . copy_node ( ) ric_to_move_to_weights [ 'axis' ] = mo_array ( channel_idx ) src = node . in_port ( 1 ) . get_connection ( ) . get_source ( ) node . in_port ( 1 ) . get_connection ( ) . set_source ( ric_to_move_to_weights . out_port ( 0 ) ) src . disconnect ( ) src . connect ( ric_to_move_to_weights . in_port ( 0 ) ) if group != 1 and group == reverse_channels . order . size : # grouped Convolution weights channel reversing is not enough to complete channel reversing procedure # we propagate ReverseChannels op through current Convolution with new order value for channel permutation bottom_channels = node . out_port ( 0 ) . data . get_shape ( ) [ node . channel_dims [ 0 ] ] assert bottom_channels % group == 0 multiplier = int ( bottom_channels / group ) new_order = np . take ( np . arange ( bottom_channels ) . reshape ( ( group , multiplier ) ) , indices = reverse_channels . order , axis = 0 ) . flatten ( ) reverse_channels [ 'axis' ] = mo_array ( reverse_channels . axis . copy ( ) ) reverse_channels [ 'order' ] = mo_array ( new_order ) node . out_port ( 0 ) . get_connection ( ) . set_source ( reverse_channels . out_port ( 0 ) ) node . out_port ( 0 ) . disconnect ( ) node . out_port ( 0 ) . connect ( reverse_channels . in_port ( 0 ) ) # as described above, we are not done reversing channels yet, so we should continue propagating # ReverseChannels operation down the network return True # we reversed channels for sure, nothing to propagate down the network return False