回答編集履歴
1
推論時のみのsoftmax出力の取り出し
test
CHANGED
@@ -4,3 +4,34 @@
|
|
4
4
|
hidden_layer = base_network.get_layer(hidden_name)
|
5
5
|
```
|
6
6
|
|
7
|
+
## 2 追記 (2022-12-06)
|
8
|
+
学習しないのであれば以下のようにすることでsoftmax出力が取得できると思います。
|
9
|
+
```diff:create_model
|
10
|
+
- model = Model([input_a, input_b], distance)
|
11
|
+
+ model = Model(inputs=[input_a, input_b], outputs=[distance, processed_a, processed_b])
|
12
|
+
```
|
13
|
+
|
14
|
+
### 2.1 モデルの出力の確認
|
15
|
+
```python
|
16
|
+
input_shape = (224, 224, 3)
|
17
|
+
model = create_model(input_shape)
|
18
|
+
|
19
|
+
import pprint
|
20
|
+
pprint.pprint(model.output)
|
21
|
+
```
|
22
|
+
```console
|
23
|
+
[<KerasTensor: shape=(None, 29) dtype=float32 (created by layer 'lambda_2')>,
|
24
|
+
<KerasTensor: shape=(None, 29) dtype=float32 (created by layer 'model_3')>,
|
25
|
+
<KerasTensor: shape=(None, 29) dtype=float32 (created by layer 'model_3')>]
|
26
|
+
```
|
27
|
+
|
28
|
+
### 2.2 テスト
|
29
|
+
```python
|
30
|
+
import numpy as np
|
31
|
+
|
32
|
+
img1 = np.random.random((1, 224, 224, 3)).astype("float32")
|
33
|
+
img2 = np.random.random((1, 224, 224, 3)).astype("float32")
|
34
|
+
outs = model.predict([img1, img2])
|
35
|
+
distance, pred1, pred2 = outs
|
36
|
+
```
|
37
|
+
|