質問編集履歴

1

修正依頼があったため

2019/12/18 03:14

投稿

satoUmino
satoUmino

スコア19

test CHANGED
File without changes
test CHANGED
@@ -26,6 +26,70 @@
26
26
 
27
27
  ### 該当のソースコード
28
28
 
29
+ ```python
30
+
31
+ import numpy as np
32
+
33
+ import sys
34
+
35
+
36
+
37
+ from keras.preprocessing import image
38
+
39
+ from keras_vggface.vggface import VGGFace
40
+
41
+ from keras_vggface import utils
42
+
43
+ from keras import backend as K
44
+
45
+ from keras.models import Model
46
+
47
+
48
+
49
+ # Based on VGG16 architecture -> old paper(2015)
50
+
51
+ model = VGGFace(model='vgg16') # or VGGFace() as default
52
+
53
+ # Based on RESNET50 architecture -> new paper(2017)
54
+
55
+ #vggface = VGGFace(model='resnet50')
56
+
57
+ # Based on SENET50 architecture -> new paper(2017)
58
+
59
+ #vggface = VGGFace(model='senet50')
60
+
61
+ model.summary()
62
+
63
+
64
+
65
+ # Change the image path with yours.
66
+
67
+
68
+
69
+ img = image.load_img(sys.argv[1], target_size=(224, 224))
70
+
71
+ x = image.img_to_array(img)
72
+
73
+ x = np.expand_dims(x, axis=0)
74
+
75
+ x = utils.preprocess_input(x, version=1) # or version=2
76
+
77
+ model_extractfeatures = Model(inputs=model.input, output=model.get_layer('fc8').output)
78
+
79
+ fc8_features = model_extractfeatures.predict(x)
80
+
81
+ preds = model.predict(x)
82
+
83
+ np.set_printoptions(threshold=np.inf)
84
+
85
+ #print (fc8_features.transpose())
86
+
87
+ print ("\n".join([str(x) for x in fc8_features]))
88
+
89
+ ```
90
+
91
+
92
+
29
93
 
30
94
 
31
95
  ```python