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
}
}