zero output for non-last layers-python

15 views
Skip to first unread message

rahim entezari

unread,
Dec 27, 2016, 3:27:32 AM12/27/16
to Caffe Users

I get the output of the VGG-changed network(here is vectors of 3 float numbers)every thing is OK, but when I just want to get the output of other layers(e.g. last convolution layer conv5_4) instead of the last layer, the output vectors are all zero. This is the python code to get the output:

import sys
import cv2
import numpy as np
sys.path.insert(0, '/home/deep/rahim/caffe-master/python')
import caffe
input_image_file = sys.argv[1]
output_file = sys.argv[2]
model_file = '/home/deep/rahim/PGM/Final/feature/deep/snapshot_iter_355000.caffemodel'
deploy_prototxt = '/home/deep/rahim/PGM/Final/feature/deep/deploy.prototxt'
net = caffe.Net(deploy_prototxt, model_file, caffe.TEST)
layer = 'conv5_4'
transformer = caffe.io.Transformer({'data':       net.blobs['data'].data.shape})
transformer.set_transpose('data', (2,0,1))
transformer.set_raw_scale('data', 255.0)
net.blobs['data'].reshape(1,3,40,40)
img = caffe.io.load_image(input_image_file)
net.blobs['data'].data[...] = transformer.preprocess('data', img)
output = net.forward()
print '%s' %(net.blobs[layer].data[0])
Reply all
Reply to author
Forward
0 new messages