質問編集履歴

1

Carelessミスが重なりが重なり 入力のdimの設定を間違っていました。 今回修正にあたり、少しだけ見やすくしてみました。

2019/04/06 16:20

投稿

kuma1957
kuma1957

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,8 +1,4 @@
1
- [リンク内容](http://)大きなモデル中の一部を切り出して、load_weightsをby_name行っています。
1
+ siame_resnet()の入力のDimが4096なのですが、入力データDim(4069,)にしていたのが大きな要因でした。夜遅くDebugは禁です
2
-
3
- そこにLambdaで求めた値を入れたいのですが、ValueErrorがでてしまいます。
4
-
5
- 記述を変えてみたのですが、結果は同じで 力尽きて 皆さんの知恵を借りることにしました。よろしくお願いします。
6
2
 
7
3
 
8
4
 
@@ -28,11 +24,27 @@
28
24
 
29
25
 
30
26
 
27
+ def model_lambda(x,y):
28
+
29
+ x_=tf.convert_to_tensor(x)
30
+
31
+ y_=tf.convert_to_tensor(y)
32
+
33
+ _xy_result=Lambda(euclidean_distance2)([x_,y_])
34
+
35
+ _xy_result = tf.reshape(_xy_result,((1,4096)))
36
+
37
+ result=seq_model(_xy_result)
38
+
39
+ return result
40
+
41
+
42
+
31
43
  def siame_resnet_():
32
44
 
33
45
  seq = models.Sequential()
34
46
 
35
- seq.add(Dense(1024, activation='sigmoid', input_shape=(4069,)))
47
+ seq.add(Dense(1024, activation='sigmoid', input_shape=(4096,)))
36
48
 
37
49
  seq.add(Dropout(0.20))
38
50
 
@@ -44,22 +56,8 @@
44
56
 
45
57
 
46
58
 
47
- x=tf.convert_to_tensor(feature_4096[j])
59
+ 本体の関数読み出し
48
60
 
49
- y=tf.convert_to_tensor(pred[i])
61
+ result=model_lambda(A,B)
50
62
 
51
- xy_result=Lambda(euclidean_distance2)([x,y])
52
-
53
-
54
-
55
- result = seq_model(xy_result)
63
+ _result=K.get_value(result)
56
-
57
-
58
-
59
- ValueError: Shape must be rank 2 but is rank 1 for 'sequential_1/dense_1/MatMul' (op: 'MatMul') with input shapes: [4096], [4069,1024].
60
-
61
-
62
-
63
- ちなみに
64
-
65
- xy_result.shape → (4096,)になっています。