前提・実現したいこと
現在、kerasを用いてVggfaceというものに画像を通して似ている確率を出力しています。
この時に、Softmax関数を用いて確率に変換する前の値を出力したいのですがうまく行きません。
どのようなコードを追加すれば良いでしょうか。
該当のソースコード
python
1import numpy as np 2import sys 3 4from keras.preprocessing import image 5from keras_vggface.vggface import VGGFace 6from keras_vggface import utils 7from keras import backend as K 8 9# Based on VGG16 architecture -> old paper(2015) 10model = VGGFace(model='vgg16') # or VGGFace() as default 11# Based on RESNET50 architecture -> new paper(2017) 12#vggface = VGGFace(model='resnet50') 13# Based on SENET50 architecture -> new paper(2017) 14#vggface = VGGFace(model='senet50') 15model.summary() 16 17# Change the image path with yours. 18 19img = image.load_img(sys.argv[1], target_size=(224, 224)) 20x = image.img_to_array(img) 21x = np.expand_dims(x, axis=0) 22x = utils.preprocess_input(x, version=1) # or version=2 23#model_extractfeatures = model(inputs=model.input, output=model.get_layer('fc8').output) 24#fc8_features = model_extractfeatures.predict(x) 25preds = model.predict(x) 26np.set_printoptions(threshold=np.inf) 27#print (fc8_features.transpose()) 28print (preds.transpose()) 29#print('Predicted:', utils.decode_predictions(preds))
試したこと
以下のコードを追加してみました。
python
1model_extractfeatures = model(inputs=model.input, output=model.get_layer('fc8').output) 2fc8_features = model_extractfeatures.predict(x) 3print (fc8_features.transpose())
補足情報(FW/ツールのバージョンなど)
出したい部分はいかのLayerのfc8の値です。
Layer (type) Output Shape Param # ================================================================= input_1 (InputLayer) (None, 224, 224, 3) 0 _________________________________________________________________ conv1_1 (Conv2D) (None, 224, 224, 64) 1792 _________________________________________________________________ conv1_2 (Conv2D) (None, 224, 224, 64) 36928 _________________________________________________________________ pool1 (MaxPooling2D) (None, 112, 112, 64) 0 _________________________________________________________________ conv2_1 (Conv2D) (None, 112, 112, 128) 73856 _________________________________________________________________ conv2_2 (Conv2D) (None, 112, 112, 128) 147584 _________________________________________________________________ pool2 (MaxPooling2D) (None, 56, 56, 128) 0 _________________________________________________________________ conv3_1 (Conv2D) (None, 56, 56, 256) 295168 _________________________________________________________________ conv3_2 (Conv2D) (None, 56, 56, 256) 590080 _________________________________________________________________ conv3_3 (Conv2D) (None, 56, 56, 256) 590080 _________________________________________________________________ pool3 (MaxPooling2D) (None, 28, 28, 256) 0 _________________________________________________________________ conv4_1 (Conv2D) (None, 28, 28, 512) 1180160 _________________________________________________________________ conv4_2 (Conv2D) (None, 28, 28, 512) 2359808 _________________________________________________________________ conv4_3 (Conv2D) (None, 28, 28, 512) 2359808 _________________________________________________________________ pool4 (MaxPooling2D) (None, 14, 14, 512) 0 _________________________________________________________________ conv5_1 (Conv2D) (None, 14, 14, 512) 2359808 _________________________________________________________________ conv5_2 (Conv2D) (None, 14, 14, 512) 2359808 _________________________________________________________________ conv5_3 (Conv2D) (None, 14, 14, 512) 2359808 _________________________________________________________________ pool5 (MaxPooling2D) (None, 7, 7, 512) 0 _________________________________________________________________ flatten (Flatten) (None, 25088) 0 _________________________________________________________________ fc6 (Dense) (None, 4096) 102764544 _________________________________________________________________ fc6/relu (Activation) (None, 4096) 0 _________________________________________________________________ fc7 (Dense) (None, 4096) 16781312 _________________________________________________________________ fc7/relu (Activation) (None, 4096) 0 _________________________________________________________________ fc8 (Dense) (None, 2622) 10742334 _________________________________________________________________ fc8/softmax (Activation) (None, 2622) 0 =================================================================
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/12/18 02:51