为什么net.blobs ['fc7']。data [0]给出全零

时间:2016-01-26 15:15:51

标签: python opencv neural-network deep-learning caffe

我想从人物的照片中提取脸部描述符。这就是我到目前为止所做的:

  1. 首先使用python中的opencv库从照片中检测到面孔。
  2. 将这些脸部保存在另一张图片中。
  3. 接下来我必须从脸部图像中提取描述符。
  4. 为此,我从这里下载了vgg face caffemodel CNN:http://www.robots.ox.ac.uk/~vgg/software/vgg_face/

    要提取描述符,首先我这样做了:

     net = caffe.Net('CAFFE_FACE_deploy.prototxt','CAFFE_FACE.caffemodel',caffe.TEST)
     img = caffe.io.load_image( "detectedface.jpg" )
     img = img[:,:,::-1]*255.0 
     avg = np.array([129.1863,104.7624,93.5940])
     img = img - avg 
     img = img.transpose((2,0,1)) 
     img = img[None,:]
     out = net.forward_all( data = img )
    

    但是它会给出维度不匹配错误,即数据应该是维度(50,3,224,224)而不是(50,3,490,490)

    然后我尝试了这个:

      # input preprocessing: 'data' is the name of the input blob ==  net.inputs[0]
      transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
      transformer.set_transpose('data', (2,0,1))
      transformer.set_mean('data', np.load(caffe_root + 'python/caffe/imagenet/ilsvrc_2012_mean.npy').mean(1).mean(1)) # mean pixel
      transformer.set_raw_scale('data', 255)  # the reference model operates on   images in [0,255] range instead of [0,1]
      transformer.set_channel_swap('data', (2,1,0))  # the reference model has channels in BGR order instead of RGB
    
      net.blobs['data'].reshape(50,3,224,224)
    
      net.blobs['data'].data[...] = transformer.preprocess('data', caffe.io.load_image('detectedface.jpg'))
      out = net.forward()
    
      feats = net.blobs['fc7'].data[0]
    

    此时,当我print feats时,它会显示全部为零。为什么会这样?

0 个答案:

没有答案