Why the deployment of the model failed ?

40 views
Skip to first unread message

jaba marwen

unread,
May 12, 2017, 6:59:41 AM5/12/17
to Caffe Users

Hi every one ,

I have a data set of 6000 image of three objects (lamborghini ,cylinder head and a piece of palne ) link to view the dataset. I split my data set 5000 for training  and 1000 for testing.The architecture of CNN is modified version of AlexNet . In fact , I have modified num_out of fc6 and fc7 to 1000. Also , the batch size of training is 50 and for test is 20.

the parameters of solver.prototxt are :

test_iter:100
test_interval:500
base_lr:0.001
lr_policy:"step"
gamma:0.1
stepsize:500
display:500
max_iter:40000
weight_decay:0.0005
solver_mode:GPU

After the training , I got accuracy 92% .But when I try to deploy the model I got the following error:
F0511 17:41:25.456792  8522 net.cpp:757] Cannot copy param 0 weights from layer 'fc8'; shape mismatch.  Source param shape is 2 1000 (2000); target param shape is 3 1000 (3000). To learn this layer's parameters from scratch rather than copying from a saved net, rename the layer.
*** Check failure stack trace: ***
Aborted (core dumped)

this my code for to deploy the model:
import os
import glob
import cv2
import caffe
import lmdb
import numpy as np
from caffe.proto import caffe_pb2

MODEL_FILE
='deploy_ex0.prototxt'
PRETRAINED
='snap_shot_model_iter_4000.caffemodel'

caffe
.set_mode_cpu()
net
= caffe.Net(MODEL_FILE, PRETRAINED, caffe.TEST)
mean_blob
= caffe_pb2.BlobProto()
with open('mean.binaryproto') as f:
    mean_blob
.ParseFromString(f.read())

mean_array
= np.asarray(mean_blob.data, dtype=np.float32).reshape(
(mean_blob.channels, mean_blob.height, mean_blob.width))

transformer
= caffe.io.Transformer({'data': net.blobs['data'].data.shape})
transformer
.set_mean('data',mean_array)
transformer
.set_transpose('data',(2,0,1))
img
=cv2.imread("lambo.jpg",cv2.IMREAD_COLOR)
img_out
=cv2.resize(img,(227,227))

net
.blobs['data'].data[...] = transformer.preprocess('data', img_out)
out=net.forward()
print out['prob'].argmax()


I attached the files deploy_ex0.prototxt and train_val.prototxt

Thanks
deploy_ex0.prototxt
train_val.prototxt

Przemek D

unread,
May 12, 2017, 7:16:52 AM5/12/17
to Caffe Users
Your fc8 layers differ between train (num_output: 2) and deploy (num_output: 3), hence a shape mismatch on weights import.
Reply all
Reply to author
Forward
0 new messages