如何用python提取图片中数值?
发布网友
发布时间:2022-04-22 12:12
我来回答
共1个回答
热心网友
时间:2023-09-19 02:34
import numpy as np
import matplotlib.pyplot as plt
import scipy
caffe_root = '/home/hser/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()