图像质量评价

图像质量评价

邀请共同入坑好玩的东西:MEMNET评价照片好坏的开源caffe代码

图像分类xiesiyuan 回复了问题 • 4 人关注 • 3 个回复 • 726 次浏览 • 2016-09-12 00:23 • 来自相关话题

条新动态, 点击查看
1.下载:
利用wget 或其他命令从 http://memorability.csail.mit.edu/download.html   下载  memnet.tar.gz 到caffe根目录下,并用tar 解压缩之。

2. 调试
我的系统是u... 显示全部 »
1.下载:
利用wget 或其他命令从 http://memorability.csail.mit.edu/download.html   下载  memnet.tar.gz 到caffe根目录下,并用tar 解压缩之。

2. 调试
我的系统是ubuntu 16.04,GTX940,caffe cuDnn v4.
再caffe/python目录下打开gedit,保存如下代码的文件,并命名为memnet.py
注意,
1)MODEL_FILE
DEPLOY_FILE
MEAN_FILE
要根据你电脑上的caffe路径来做修改,我是存储在~/caffe/memnet下的
2)test1.jpg -test8.jpg是我从Demo中扣下来做测试的8张图片,你可以选择为任意图片,但要把caffe.io.Transformer后面的地址更新一下。
3)备注:前提,你的机器要是安装过基于cuDnn的caffe[code]#!/usr/bin/python

import caffe
import numpy as np

MODEL_FILE="/home/linuxhost/caffe/memnet/memnet.caffemodel"
DEPLOY_FILE="/home/linuxhost/caffe/memnet/deploy.prototxt"
MEAN_FILE="/home/linuxhost/caffe/memnet/mean.npy"
net=caffe.Net(DEPLOY_FILE,MODEL_FILE,caffe.TEST)

imagemean=np.load(MEAN_FILE)
imagemean=imagemean.mean(1).mean(1)
print('mean-subtracted values:',zip('BGR',imagemean))

# create transformer for the input called 'data'
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', imagemean) # 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


# set the size of the input (we can skip this if we're happy
# with the default; we can also change it later, e.g., for different batch sizes)
#net.blobs['data'].reshape(50, # batch size
# 3, # 3-channel (BGR) images
# 227, 227) # image size is 227x227

caffe.set_device(0)
caffe.set_mode_gpu()

input_image1=caffe.io.load_image("/home/linuxhost/caffe/memnet/test/test1.jpg")

transformed_image = transformer.preprocess('data', input_image1)
net.blobs['data'].data[...] = transformed_image

output=net.forward()

print(output)

input_image2=caffe.io.load_image("/home/linuxhost/caffe/memnet/test/test2.jpg")

transformed_image = transformer.preprocess('data', input_image2)
net.blobs['data'].data[...] = transformed_image

output=net.forward()

print(output)

input_image3=caffe.io.load_image("/home/linuxhost/caffe/memnet/test/test3.jpg")

transformed_image = transformer.preprocess('data', input_image3)
net.blobs['data'].data[...] = transformed_image

output=net.forward()

print(output)

input_image4=caffe.io.load_image("/home/linuxhost/caffe/memnet/test/test4.jpg")

transformed_image = transformer.preprocess('data', input_image4)
net.blobs['data'].data[...] = transformed_image

output=net.forward()

print(output)

input_image5=caffe.io.load_image("/home/linuxhost/caffe/memnet/test/test5.jpg")

transformed_image = transformer.preprocess('data', input_image5)
net.blobs['data'].data[...] = transformed_image

output=net.forward()

print(output)

input_image6=caffe.io.load_image("/home/linuxhost/caffe/memnet/test/test6.jpg")

transformed_image = transformer.preprocess('data', input_image6)
net.blobs['data'].data[...] = transformed_image

output=net.forward()

print(output)

input_image7=caffe.io.load_image("/home/linuxhost/caffe/memnet/test/test7.jpg")

transformed_image = transformer.preprocess('data', input_image7)
net.blobs['data'].data[...] = transformed_image

output=net.forward()

print(output)

input_image8=caffe.io.load_image("/home/linuxhost/caffe/memnet/test/test8.jpg")

transformed_image = transformer.preprocess('data', input_image8)
net.blobs['data'].data = transformed_image

output=net.forward()

print(output)
3. 开始运行 cd ~/caffe/python
python memnet.py
输出是一列数字都一样的向量,其中的向量值就是检测这张图片有多么吸引人的打分。

314

4 附注
代码中有一行
imagemean=imagemean.mean(1).mean(1)
是因为如果不这样做,会报错:
'Mean shape incompatible with input shape.'

另一种更合理的做法其实是把caffe/python/caffe/io.py文件中的[code] if ms != self.inputs[in_] :
raise ValueError('Mean shape incompatible with input shape.') 改为[code] if ms != self.inputs[in_][1:]:
print(self.inputs[in_])
in_shape = self.inputs[in_][1:]
m_min, m_max = mean.min(), mean.max()
normal_mean = (mean - m_min) / (m_max - m_min)
mean = resize_image(normal_mean.transpose((1,2,0)),
in_shape ).transpose((2,0,1)) * \
(m_max - m_min) + m_min
# raise ValueError('Mean shape incompatible with input shape.')
并把memnet.py中的 imagemean=imagemean.mean(1).mean(1) 改为 #imagemean=imagemean.mean(1).mean(1) 因为io.py的模块好像在这个部分是有Bug的。

邀请共同入坑好玩的东西:MEMNET评价照片好坏的开源caffe代码

回复

图像分类xiesiyuan 回复了问题 • 4 人关注 • 3 个回复 • 726 次浏览 • 2016-09-12 00:23 • 来自相关话题