質問編集履歴
1
修正依頼があったため
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -12,7 +12,39 @@
|
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
### 該当のソースコード
|
|
15
|
+
```python
|
|
16
|
+
import numpy as np
|
|
17
|
+
import sys
|
|
15
18
|
|
|
19
|
+
from keras.preprocessing import image
|
|
20
|
+
from keras_vggface.vggface import VGGFace
|
|
21
|
+
from keras_vggface import utils
|
|
22
|
+
from keras import backend as K
|
|
23
|
+
from keras.models import Model
|
|
24
|
+
|
|
25
|
+
# Based on VGG16 architecture -> old paper(2015)
|
|
26
|
+
model = VGGFace(model='vgg16') # or VGGFace() as default
|
|
27
|
+
# Based on RESNET50 architecture -> new paper(2017)
|
|
28
|
+
#vggface = VGGFace(model='resnet50')
|
|
29
|
+
# Based on SENET50 architecture -> new paper(2017)
|
|
30
|
+
#vggface = VGGFace(model='senet50')
|
|
31
|
+
model.summary()
|
|
32
|
+
|
|
33
|
+
# Change the image path with yours.
|
|
34
|
+
|
|
35
|
+
img = image.load_img(sys.argv[1], target_size=(224, 224))
|
|
36
|
+
x = image.img_to_array(img)
|
|
37
|
+
x = np.expand_dims(x, axis=0)
|
|
38
|
+
x = utils.preprocess_input(x, version=1) # or version=2
|
|
39
|
+
model_extractfeatures = Model(inputs=model.input, output=model.get_layer('fc8').output)
|
|
40
|
+
fc8_features = model_extractfeatures.predict(x)
|
|
41
|
+
preds = model.predict(x)
|
|
42
|
+
np.set_printoptions(threshold=np.inf)
|
|
43
|
+
#print (fc8_features.transpose())
|
|
44
|
+
print ("\n".join([str(x) for x in fc8_features]))
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
|
|
16
48
|
```python
|
|
17
49
|
print ("\n".join([str(x) for x in fc8_features]))
|
|
18
50
|
```
|