使用Caffe批量提取特征
本Markdown编辑器使用[StackEdit][6]修改而来,用它写博客,将会带来全新的体验哦:
在使用caffe时候,到官网看啦如何提取一张图片特征,但是,图片很多,如何批量提取呢?
这里,先获取图像的文件列表。在获取文件列表后,提取每一张图片特征,然后组合成Pandas的DataFrame,写入csv文件。
不废话,直接上代码:
引用的一些包。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import sys
caffe_root = '../' # this file should be run from {caffe_root}/examples (otherwise change this line)
sys.path.insert(0, caffe_root + 'python')
import caffe
import os
if os.path.isfile(caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'):
print 'CaffeNet found.'
else:
print 'Downloading pre-trained CaffeNet model...'
!../scripts/download_model_binary.py ../models/bvlc_reference_caffenet
这里,先根据图像列表文件,读一张张图像。每50张图片中断一下,电脑不行。。。。
##读取文件列表
图像的文件列表和图像的基础路径,根据自己的修改
imageListFile =