Caffe model gives same output for every image

心不动则不痛 提交于 2020-01-04 02:30:38

问题


I just loaded alexnet in caffe using predefined prototxt and caffemodel files. However sending any image to the model returns the same value as output of fc7 layer.

Here is the code snippet

net=caffe.Net('alexnet/train_val.prototxt','alexnet/bvlc_alexnet.caffemodel',caffe.TEST) 

for image in images:
    im = np.array(caffe.io.load_image(image))
    im = caffe.io.resize_image(im, (227, 227))
    im = np.array(im,dtype=np.float32)
    im =255*im;
    im = im[:,:,::-1]
    im -= np.array(((104.00698793,116.66876762,122.67891434)))
    im = im.transpose(2,0,1)
    net.blobs['data'].reshape(1,*im.shape)
    net.blobs['data'].data[...] = im
    net.forward()
    fc = net.blobs['fc7'].data #Always the same value

来源:https://stackoverflow.com/questions/44119176/caffe-model-gives-same-output-for-every-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!