L.Tile layer in Caffe

test_tile_layer.py

#coding=gbk
import numpy as np

import caffe
# weight_file can be any prtrained models
weight_file = '../attention_network/snapshots_aflw_vgg16_klLoss_finetune_attention1/cross1/vgg_iter_10000.caffemodel'
deploy_file = 'deploy.prototxt'
net = caffe.Net(deploy_file,weight_file,caffe.TEST)  

arr0 = np.array([[11,12,13],[21,22,23]]) # w11 w12 w13 for sample1, w21 w22 w23 for sample2
print(arr0.shape) # (2,3),2 stand for sample, 3 stand for channel
print(arr0)

arr = np.reshape(arr0,(arr0.shape[0],arr0.shape[1],1,1))

net.blobs['Features'].data[...] = arr 

net.forward()

feat = net.blobs['Features'].data

tile1 = net.blobs['tile1'].data

tile2 = net.blobs['tile2'].data

print('feat: ',feat.shape)
print('tile1: ',tile1.shape)
print('tile2: ',tile2.shape)

# check values, check tiles

print(tile2[0,0,:,:]) # all same values with arr0[0,0]

deploy.prototxt


layer {
  name: "data"
  type: "Input"
  top: "Features"
  input_param {
    shape {
      dim: 2
      dim: 3
 	  dim: 1
 	  dim: 1
    }
  }
}

layer {
  name: "tile1"
  type: "Tile"
  bottom: "Features"
  top: "tile1"
  tile_param {
    axis: 2
    tiles: 2
  }
}

layer {
  name: "tile1"
  type: "Tile"
  bottom: "tile1"
  top: "tile2"
  tile_param {
    axis: 3
    tiles: 2
  }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值