예제 #1
0
파일: layer.py 프로젝트: klee141/deepnet
    def ConvolveUp(self, inputs, edge, target):
        w = edge.params['weight']
        conv = edge.conv_params
        size = conv.size
        stride = conv.stride
        padding = conv.padding
        num_filters = conv.num_filters
        num_colors = conv.num_colors

        f, numdims = w.shape
        assert f == num_filters, 'f is %d but num_filters is %d' % (
            f, num_filters)
        assert numdims == size**2 * num_colors

        input_t = edge.input_t
        if conv.max_pool:
            output_t = edge.unpooled_layer
        else:
            output_t = edge.output_t
        numimages, numdims = input_t.shape
        numimages2, numdims2 = output_t.shape

        assert numimages == numimages2, '%d %d' % (numimages, numimages2)

        assert numdims % num_colors == 0
        x = int(np.sqrt(numdims / num_colors))
        assert x**2 == numdims / num_colors

        n_locs = (x + 2 * padding - size) / stride + 1

        inputs.transpose(input_t)
        cc.convUp(input_t, w, output_t, n_locs, padding, stride, num_colors)

        # Do maxpooling
        if conv.max_pool:
            n_locs = (n_locs + 2 * padding -
                      conv.pool_size) / conv.pool_stride + 1
            cc.MaxPool(output_t, edge.output_t, num_filters, conv.pool_size, 0,
                       conv.pool_stride, n_locs)
            output_t = edge.output_t
        output_t.transpose(target)
예제 #2
0
파일: layer.py 프로젝트: wOOL/deepnet
  def ConvolveUp(self, inputs, edge, target):
    w = edge.params['weight']
    conv = edge.conv_params
    size = conv.size
    stride = conv.stride
    padding = conv.padding
    num_filters = conv.num_filters
    num_colors = conv.num_colors

    f, numdims = w.shape
    assert f == num_filters, 'f is %d but num_filters is %d' % (f, num_filters)
    assert numdims == size**2 * num_colors

    input_t = edge.input_t
    if conv.max_pool:
      output_t = edge.unpooled_layer
    else:
      output_t = edge.output_t
    numimages, numdims = input_t.shape
    numimages2, numdims2 = output_t.shape

    assert numimages == numimages2, '%d %d' % (numimages, numimages2)

    assert numdims % num_colors == 0
    x = int(np.sqrt(numdims / num_colors))
    assert x**2 == numdims/num_colors

    n_locs = (x + 2 * padding - size) / stride + 1

    inputs.transpose(input_t)
    cc.convUp(input_t, w, output_t, n_locs, padding, stride, num_colors)

    # Do maxpooling
    if conv.max_pool:
      n_locs = (n_locs + 2 * padding - conv.pool_size) / conv.pool_stride + 1
      cc.MaxPool(output_t, edge.output_t, num_filters, conv.pool_size, 0, conv.pool_stride, n_locs)
      output_t = edge.output_t
    output_t.transpose(target)
예제 #3
0
파일: layer.py 프로젝트: wqren/deepnet
    def ConvolveUp(self, inputs, edge, target):
        w = edge.params["weight"]
        conv = edge.conv_params
        size = conv.size
        stride = conv.stride
        padding = conv.padding
        num_filters = conv.num_filters
        num_colors = conv.num_colors

        f, numdims = w.shape
        assert f == num_filters, "f is %d but num_filters is %d" % (f, num_filters)
        if edge.conv:
            assert numdims == size ** 2 * num_colors

        input_t = edge.input_t
        inputs.transpose(input_t)
        # Convolve Up.
        if conv.max_pool:
            output_t = edge.unpooled_layer
        elif conv.rnorm:
            output_t = edge.unrnormalized_layer
        else:
            output_t = edge.output_t

        numimages, numdims = input_t.shape
        numimages2, numdims2 = output_t.shape
        assert numimages == numimages2, "%d %d." % (numimages, numimages2)
        assert numdims % num_colors == 0
        x = int(np.sqrt(numdims / num_colors))
        assert x ** 2 == numdims / num_colors
        n_locs = (x + 2 * padding - size) / stride + 1
        if edge.conv:
            cc.convUp(input_t, w, output_t, n_locs, padding, stride, num_colors)
        else:
            cc.localUp(input_t, w, output_t, n_locs, padding, stride, num_colors)

        # Do maxpooling
        if conv.max_pool:
            input_t = output_t
            if conv.rnorm:
                output_t = edge.unrnormalized_layer
            else:
                output_t = edge.output_t
            n_locs = (n_locs - conv.pool_size) / conv.pool_stride + 1
            if conv.prob:
                # Get Gumbel variates.
                rnd = edge.rnd
                rnd.fill_with_rand()
                cm.log(rnd)
                rnd.mult(-1)
                cm.log(rnd)
                rnd.mult(-1)
                cc.ProbMaxPool(input_t, rnd, output_t, num_filters, conv.pool_size, 0, conv.pool_stride, n_locs)
            else:
                cc.MaxPool(input_t, output_t, num_filters, conv.pool_size, 0, conv.pool_stride, n_locs)
        if conv.rnorm:
            input_t = output_t
            output_t = edge.output_t
            denoms = edge.denoms
            sizeX = conv.norm_size
            add_scale = conv.add_scale
            pow_scale = conv.pow_scale
            cc.ResponseNorm(input_t, denoms, output_t, num_filters, sizeX, add_scale, pow_scale)
        output_t.transpose(target)
예제 #4
0
def ConvolveUp(inputs, edge, target):
  w = edge.params['weight']
  conv = edge.conv_params
  size = conv.size
  stride = conv.stride
  padding = conv.padding
  num_filters = conv.num_filters
  num_colors = conv.num_colors

  f, numdims = w.shape
  assert f == num_filters, 'f is %d but num_filters is %d' % (f, num_filters)
  if edge.conv:
    assert numdims == size**2 * num_colors

  input_t = edge.input_t
  inputs.transpose(input_t)
  # Convolve Up.
  if conv.max_pool:
    output_t = edge.unpooled_layer
  elif conv.rnorm:
    output_t = edge.unrnormalized_layer
  else:
    output_t = edge.output_t

  numimages, numdims = input_t.shape
  numimages2, numdims2 = output_t.shape
  assert numimages == numimages2, '%d %d.' % (numimages, numimages2)
  assert numdims % num_colors == 0
  x = int(math.sqrt(numdims / num_colors))
  assert x**2 == numdims/num_colors
  n_locs = (x + 2 * padding - size) / stride + 1
  if edge.conv:
    cc.convUp(input_t, w, output_t, n_locs, padding, stride, num_colors)
  else:
    cc.localUp(input_t, w, output_t, n_locs, padding, stride, num_colors)

  # Do maxpooling
  if conv.max_pool:
    input_t = output_t
    if conv.rnorm:
      output_t = edge.unrnormalized_layer
    else:
      output_t = edge.output_t
    n_locs = (n_locs - conv.pool_size) / conv.pool_stride + 1
    if conv.prob:
      rnd = edge.rnd
      rnd.fill_with_rand()
      cm.log(rnd)
      rnd.mult(-1)
      #cm.log(rnd)
      #rnd.mult(-1)
      cc.ProbMaxPool(input_t, rnd, output_t, num_filters, conv.pool_size, 0, conv.pool_stride, n_locs)
    else:
      cc.MaxPool(input_t, output_t, num_filters, conv.pool_size, 0, conv.pool_stride, n_locs)
  if conv.rnorm:
    input_t = output_t
    output_t = edge.output_t
    denoms = edge.denoms
    sizeX = conv.norm_size
    add_scale = conv.add_scale
    pow_scale = conv.pow_scale
    cc.ResponseNorm(input_t, denoms, output_t, num_filters, sizeX, add_scale, pow_scale)
  output_t.transpose(target)