在Python中如何提取多个图片的特征值

Python038

在Python中如何提取多个图片的特征值,第1张

import numpy as np

import matplotlib.pyplot as plt

import scipy

caffe_root = '/home/hduser/Project/caffe/'

import sys

sys.path.insert(0,caffe_root + 'python/')

import caffe

plt.rcParams['figure.figsize'] = (10, 10)

plt.rcParams['image.interpolation'] = 'nearest'

plt.rcParams['image.cmap'] = 'gray'

net = caffe.Classifier(caffe_root + 'models/bvlc_reference_caffenet/deploy.prototxt',

        caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel')

net.set_phase_test()

net.set_mode_cpu()

net.set_mean('data', np.load(caffe_root + 'python/caffe/imagenet/ilsvrc_2012_mean.npy'))

net.set_raw_scale('data', 255)

net.set_channel_swap('data', (2,1, 0))

#in fact, you can input a list of images.

scores = net.predict([caffe.io.load_image(caffe_root + "examples/yilin/data/building.jpg"), caffe.io.load_image(caffe_root + "examples/yilin/data/thumb.jpg")])

output = open("feature.txt", "w")

#print scores[0].argmax()

#print [(k, v.data.shape) for k, v in net.blobs.items()]

#the fc6 is the fc6 layer feature, data[4] means the five crop images, because each image will be crop to 10 sub-images.

#feat = net.blobs['fc6'].data[4]

feat = net.blobs['prob'].data[4]

plt.plot(feat.flat)

plt.show()

feat2 = net.blobs['fc6'].data[14]

plt.plot(feat2.flat)

plt.show()

使用python的数值计算库numpy来计算矩阵特征值,特征向量与标准正交向量组

1.求矩阵 的特征值和各特征值所对应的特征向量

2.求矩阵 的特征值和各特征值所对应的特征向量

3.由向量组 构造一组标准正交向量组