import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Make sure that caffe is on the python path:
#caffe_root = './caffe/' # this file is expected to be in {caffe_root}/examples
#import sys
#sys.path.append(caffe_root + 'python')
import caffe
# Set the right path to your model definition file, pretrained model weights,
# and the image you would like to classify.
MODEL_FILE = './facialkp.prototxt'
PRETRAINED = './tmp_iter_1000_1.94e.caffemodel'
net = caffe.Classifier(MODEL_FILE, PRETRAINED,
None,
None,
image_dims=(96, 96)
)
caffe.set_phase_test()
caffe.set_mode_cpu()
df = pd.read_csv('test.csv',header=0)
df['Image'] = df['Image'].apply(lambda im: np.fromstring(im, sep=' ') )
X = np.vstack (df['Image'].values) / 255
X = X.astype(np.float32)
X = X.reshape((-1,1,96,96))
for k in xrange(len(X)):
input = X[k]
prediction = net.predict([input])
print 'Predicted:', prediction
pbu@pbu-OptiPlex-740-Enhanced:~/Desktop$ python output.py
Traceback (most recent call last):
File "output.py", line 22, in <module>
image_dims=(96, 96)
TypeError: __init__() got multiple values for keyword argument 'image_dims'
None, from
Classifier consturctor callnet = caffe.Classifier(MODEL_FILE, PRETRAINED, image_dims=(96,96) )
Traceback (most recent call last):
File "output.py", line 19, in <module>
net = caffe.Classifier(MODEL_FILE, PRETRAINED, image_dims=(96, 96) )
File "/home/pbu/Desktop/caffe/python/caffe/classifier.py", line 43, in __init__
self.crop_dims = np.array(self.blobs[self.inputs[0]].data.shape[2:])
IndexError: list index out of range
To view this discussion on the web visit https://groups.google.com/d/msgid/caffe-users/299e89f9-00d6-43dc-b502-ed405d0b4db7%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "Caffe Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caffe-users...@googlegroups.com.
To post to this group, send email to caffe...@googlegroups.com.
Oh, the list index out of range is because `net.inputs` is the list of *inputs* defined by the input fields like here: https://github.com/BVLC/caffe/blob/master/examples/mnist/lenet.prototxt#L2-L6.
name: "FKPReg"
layers {
name: "fkp"
top: "data"
top: "label"
type: HDF5_DATA
hdf5_data_param {
source: "train.txt"
batch_size: 100
}
include: { phase: TRAIN }
}
layers {
name: "data"
type: HDF5_DATA
top: "data"
top: "label"
hdf5_data_param {
source: "test.txt"
batch_size: 100
}
include: { phase: TEST }
}
layers {
name: "conv1"
type: CONVOLUTION
bottom: "data"
top: "conv1"
convolution_param {
num_output: 96
kernel_size: 11
stride: 4
}
}
layers {
name: "relu1"
type: RELU
bottom: "conv1"
top: "conv1"
}
layers {
name: "pool1"
type: POOLING
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layers {
name: "norm1"
type: LRN
bottom: "pool1"
top: "norm1"
lrn_param {
local_size: 5
alpha: 0.0001
beta: 0.75
}
}
layers {
name: "conv2"
type: CONVOLUTION
bottom: "norm1"
top: "conv2"
convolution_param {
num_output: 256
pad: 2
kernel_size: 5
group: 2
}
}
layers {
name: "relu2"
type: RELU
bottom: "conv2"
top: "conv2"
}
layers {
name: "pool2"
type: POOLING
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layers {
name: "norm2"
type: LRN
bottom: "pool2"
top: "norm2"
lrn_param {
local_size: 5
alpha: 0.0001
beta: 0.75
}
}
layers {
name: "conv3"
type: CONVOLUTION
bottom: "norm2"
top: "conv3"
convolution_param {
num_output: 384
pad: 1
kernel_size: 3
}
}
layers {
name: "relu3"
type: RELU
bottom: "conv3"
top: "conv3"
}
layers {
name: "conv4"
type: CONVOLUTION
bottom: "conv3"
top: "conv4"
convolution_param {
num_output: 384
pad: 1
kernel_size: 3
group: 2
}
}
layers {
name: "relu4"
type: RELU
bottom: "conv4"
top: "conv4"
}
layers {
name: "conv5"
type: CONVOLUTION
bottom: "conv4"
top: "conv5"
convolution_param {
num_output: 256
pad: 1
kernel_size: 3
group: 2
}
}
layers {
name: "relu5"
type: RELU
bottom: "conv5"
top: "conv5"
}
layers {
name: "ip1"
type: INNER_PRODUCT
bottom: "conv5"
top: "ip1"
inner_product_param {
num_output: 30
}
}
layers {
name: "loss"
type: HINGE_LOSS
bottom: "ip1"
bottom: "label"
top: "loss"
}
You cannot combine a data layer with the Python preprocessing code. Your model has an HDF5 layer that doesn't count as a bare input. The Python preprocessing coded can be called to make a blob to give to the network, but can't be called on a blob from a data layer during forward.
No i dont explicity define the dims in prototxt
ARe you are saying that i have to write a new layer file for this and load it to predict??
What is the difference between caffe.Classifier() and caffe.Net() ???
--
You received this message because you are subscribed to the Google Groups "Caffe Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to caffe-users...@googlegroups.com.
To post to this group, send email to caffe...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/caffe-users/9875309b-4e3d-4460-94f8-f76191ad9f3d%40googlegroups.com.
print out['prob'].argmax()
according to your requirement. Let me know if it helps
Best Regards,
Shruti
Hello Mr Prabhu,