Hi everybody. I tried Alexnet on my own data for a two-output classification problem.
# The train/test net protocol buffer definition
net: "/home/deepcuda/Scrivania/caffe/caffe/codice_retina/modifiche_riproduzione_esempio/prova3_new.prototxt"
base_lr: 0.001 # begin training at a learning rate of 0.01 = 1e-2
lr_policy: "step" # learning rate policy: drop the learning rate in "steps"
# by a factor of gamma every stepsize iterations
gamma: 0.1 # drop the learning rate by a factor of 10
# (i.e., multiply it by a factor of gamma = 0.1)
stepsize: 10000 # drop the learning rate every 100K iterations
#max_iter: 35000 # train for 350K iterations total
max_iter: 35000
momentum: 0.9
iter_size: 2
# snapshot intermediate results
snapshot: 5000
snapshot_prefix: "/home/deepcuda/Scrivania/caffe/caffe/codice_retina/modifiche_riproduzione_esempio/snapshot_prova3_new_not_skeleton/"
# solver mode: CPU or GPU
solver_mode: GPU
NOW I'M TRYING TO TEST THE NETWORK: I WANT TO OBTAIN THE OUTPUT PROBABILITY OF AN IMAGE (THAT IS DIFFERENT FROM THOSE OF THE TRAIN SET). I'M USING THIS PYTHON CODE :
import scipy
import numpy
from scipy import misc
import caffe
import sys
caffe_root = '/home/deepcuda/Scrivania/caffe/caffe/'
sys.path.insert(0, caffe_root + 'python')
####################################caricamento pathname################################
pathdir1="/home/deepcuda/Scrivania/dataset2/"
pathdir2="/home/deepcuda/Scrivania/dataset2/"
pathdir3="/home/deepcuda/Scrivania/dataset2/"
test_imgName=[]
test_maskName=[]
test_grtName=[]
for num in range(1,3):
string1=str(num)
string2="_image.jpg"
string=pathdir1+string1+string2
test_imgName.append(string)
test_maskName.append(string)
test_grtName.append(string)
print(test_imgName[num-1])
test_original_images=numpy.zeros((2,584,565))
test_grt_images=numpy.zeros((2,584,565))
test_mask_images=numpy.zeros((2,584,565))
for num in range(1,3):
test_original_images[num-1]=misc.imread(test_imgName[num-1])
test_grt_images[num-1]=misc.imread(test_maskName[num-1])
test_mask_images[num-1]=misc.imread(test_grtName[num-1])
print('test_original_images.shape')
print(test_original_images.shape)
caffe.set_mode_gpu()
model_def = caffe_root + 'codice_retina/modifiche_riproduzione_esempio/prova3_new.prototxt'
model_weights = caffe_root + 'codice_retina/modifiche_riproduzione_esempio/snapshot_prova3_new_not_skeleton/_iter_30000.caffemodel'
net = caffe.Net(model_def, # defines the structure of the model
model_weights, # contains the trained weights
caffe.TEST) # use test mode (e.g., don't perform dropout)
net.blobs['data'].reshape(1, # batch size
1, # 3-channel (BGR) images
65, 65) # image size is 227x227
mu = numpy.load(caffe_root + 'data/ilsvrc12/imagenet_mean_65_new_label.npy')
mu = mu.mean(1).mean(1) # average over pixels to obtain the mean (BGR) pixel values
print('mu.shape')
print(mu.shape)
mu=mu[0:1]
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
#transformer.set_transpose('data', (2,0,1)) # move image channels to outermost dimension
transformer.set_mean('data', mu) # subtract the dataset-mean value in each channel
#transformer.set_raw_scale('data', 255) # rescale from [0, 1] to [0, 255]
#transformer.set_channel_swap('data', (2,1,0)) # swap channels from RGB to BGR
print('net.blobs[data].data.shape')
print(net.blobs['data'].data.shape)
b=test_original_images[0:1,0:65,0:65]
print('b.shape')
print(b.shape)
transformed_image = transformer.preprocess('data', b)
print('shape immagine trasformata')
print(transformed_image.shape)
transformed_image=transformed_image[0]
print('shape immagine trasformata')
print(transformed_image.shape)
# copy the image data into the memory allocated for the net
net.blobs['data'].data[...] = transformed_image
### perform classification
output = net.forward()
output_prob = output['loss']
print(output_prob)
print(output_prob.shape)
Why are there 64(x2) values?? i want to obtain the output probabilities of a single image (that is the one i gave to the net in the forward pass). How can i do it?