Ejemplo n.º 1
0
def slice(net, input_blob, slice_point, axis=1):
    return Layers.Slice(net,
                        input_blob,
                        nout=len(slice_point)+1 if tb.isList(slice_point) else 2,
                        slice_param={
                          'slice_point': slice_point if tb.isList(slice_point) else (slice_point,) ,
                          'axis': axis
                        })
Ejemplo n.º 2
0
def slice(net, input_blob, slice_point, axis=1):
    return Layers.Slice(
        net,
        input_blob,
        nout=len(slice_point) + 1 if tb.isList(slice_point) else 2,
        slice_param={
            'slice_point':
            slice_point if tb.isList(slice_point) else (slice_point, ),
            'axis':
            axis
        })
Ejemplo n.º 3
0
def scale(net, image_blob, factor):
    if tb.isList(factor):
        return Layers.Convolution(net,
                                  image_blob,
                                  nout=1,
                                  convolution_param={
                                      'num_output': len(factor),
                                      'pad': 0,
                                      'kernel_size': 1,
                                      'stride': 1,
                                      'weight_filler': {
                                          'type': 'diagonal',
                                          'diag_val': factor
                                      },
                                      'bias_filler': {
                                          'type': 'constant'
                                      }
                                  })
    else:
        return Layers.Eltwise(net,
                              image_blob,
                              nout=1,
                              eltwise_param={
                                  'operation': Params.Eltwise.SUM,
                                  'coeff': (factor, )
                              })
Ejemplo n.º 4
0
def concat(net, *args, **kwargs):
    '''
    @brief Setup a ConcatLayer that takes all ARGS and throws them together along the first dimension
    @param net Current network
    @returns A new blob (concatenation of all blobs in ARGS)
    '''
    axis = 1
    if 'axis' in kwargs:
        axis = int(kwargs['axis'])
        del kwargs['axis']
    if len(kwargs):
        raise Exception('Cannot handle kwargs %s' % kwargs)

    inputs = []
    for arg in args:
        if tb.isList(arg): inputs += arg
        else: inputs.append(arg)

    return Layers.Concat(net, inputs, nout=1, concat_param={'axis': axis})
Ejemplo n.º 5
0
def scale(net, image_blob, factor):
    if tb.isList(factor):
      return Layers.Convolution(net,
                                image_blob,
                                nout=1,
                                convolution_param={
                                  'num_output': len(factor),
                                  'pad': 0,
                                  'kernel_size': 1,
                                  'stride': 1,
                                  'weight_filler': {'type': 'diagonal', 'diag_val': factor},
                                  'bias_filler': {'type': 'constant'}
                                })
    else:
      return Layers.Eltwise(net,
                            image_blob,
                            nout=1,
                            eltwise_param={
                              'operation': Params.Eltwise.SUM,
                              'coeff': (factor,)
                            })
Ejemplo n.º 6
0
def concat(net, *args, **kwargs):
    '''
    @brief Setup a ConcatLayer that takes all ARGS and throws them together along the first dimension
    @param net Current network
    @returns A new blob (concatenation of all blobs in ARGS)
    '''
    axis = 1
    if 'axis' in kwargs:
        axis = int(kwargs['axis'])
        del kwargs['axis']
    if len(kwargs):
        raise Exception('Cannot handle kwargs %s' % kwargs)

    inputs = []
    for arg in args:
        if tb.isList(arg): inputs += arg
        else: inputs.append(arg)

    return Layers.Concat(net,
                         inputs,
                         nout=1,
                         concat_param={'axis': axis})