forked from kevinlin311tw/Caffe-DeepBinaryCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
53 lines (34 loc) · 1.45 KB
/
test.py
File metadata and controls
53 lines (34 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
import sys
import PIL
from PIL import Image
caffe_root = '../../'
sys.path.insert(0, caffe_root + 'python')
import caffe
import extractBatch
import numpy as np
def doFeaExtraction(filename):
caffeModelDefinitionFileName = 'models/KevinNet_Yahoo1M_128_deploy.prototxt';
caffePretrainedModelFileName = 'models/KevinNet_Yahoo1M_128_iter_750000.caffemodel';
imageDims = [256,256];
gpuId = -1;
meanFileName = 'ilsvrc_2012_mean.npy';
inputScale = None;
rawScale = 255.0;
channelSwap = [2,1,0];
featureExtractor = extractBatch.init(caffeModelDefinitionFileName,
caffePretrainedModelFileName,
image_dims=imageDims,
gpu_id=gpuId,
mean_file=np.load(meanFileName),
input_scale=inputScale,
raw_scale=rawScale,
channel_swap=channelSwap)
queryFeatureVectors = extractBatch.extractFile(filename, featureExtractor, True, layer_name = 'fc7')
print queryFeatureVectors;
print 'len(queryFeatureVectors):' + str(len(queryFeatureVectors[0]));
def main(argv):
filename = sys.argv[1]
doFeaExtraction(filename);
if __name__ == '__main__':
main(sys.argv)