teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

エラーコードの修正、ソースコードの修正

2024/03/31 13:46

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -10,11 +10,11 @@
10
10
 
11
11
  ### エラーメッセージ
12
12
  ```error
13
- (0,)
13
+ (56, 225, 300, 3)
14
14
  Epoch 1/50
15
15
  ---------------------------------------------------------------------------
16
16
  ValueError Traceback (most recent call last)
17
- Cell In[3], line 76
17
+ Cell In[4], line 76
18
18
  74 # 学習実行
19
19
  75 print(train.shape)
20
20
  ---> 76 model.fit(
@@ -32,25 +32,13 @@
32
32
  123 finally:
33
33
  124 del filtered_tb
34
34
 
35
- File ~\anaconda3\Lib\site-packages\keras\src\models\functional.py:280, in Functional._adjust_input_rank(self, flat_inputs)
35
+ Cell In[4], line 70, in r_loss(y_true, y_pred)
36
+ 69 def r_loss(y_true, y_pred):
36
- 278 adjusted.append(ops.expand_dims(x, axis=-1))
37
+ ---> 70 return K.mean(K.square(y_true - y_pred), axis=[1,2,3])
37
- 279 continue
38
- --> 280 raise ValueError(
39
- 281 f"Invalid input shape for input {x}. Expected shape "
40
- 282 f"{ref_shape}, but input has incompatible shape {x.shape}"
41
- 283 )
42
- 284 # Add back metadata.
43
- 285 for i in range(len(flat_inputs)):
44
38
 
45
- ValueError: Exception encountered when calling Functional.call().
39
+ ValueError: Dimensions must be equal, but are 225 and 228 for '{{node compile_loss/r_loss/sub}} = Sub[T=DT_FLOAT](data_1, functional_23_1/functional_21_1/activation_3_1/Sigmoid)' with input shapes: [1,225,300,3], [1,228,300,3].
46
40
 
47
- Invalid input shape for input Tensor("data:0", shape=(8,), dtype=float32). Expected shape (None, 300, 225, 3), but input has incompatible shape (8,)
48
-
49
- Arguments received by Functional.call():
50
- • inputs=tf.Tensor(shape=(8,), dtype=float32)
51
- • training=True
52
- • mask=None
41
+
53
-
54
42
  ```
55
43
 
56
44
  ### 該当のソースコード
@@ -65,7 +53,7 @@
65
53
  import glob
66
54
 
67
55
  # 学習データの読み込み&前処理
68
- train_images = glob.glob('retraining_images/*')
56
+ train_images = glob.glob('train_image/*')
69
57
  train = []
70
58
  for i in train_images:
71
59
  image = cv2.imread(i)
@@ -82,7 +70,7 @@
82
70
  EPOCHS = 50
83
71
 
84
72
  # エンコーダ
85
- encoder_input = Input(shape=(300,225,3), name='encoder_input')
73
+ encoder_input = Input(shape=(225,300,3), name='encoder_input')
86
74
  x = encoder_input
87
75
  x = Conv2D(filters=32, kernel_size=3, strides=1, padding='same', name='encoder_conv_0')(x)
88
76
  x = LeakyReLU()(x)
@@ -147,7 +135,7 @@
147
135
  - [ ] その他
148
136
 
149
137
  ##### 上記の詳細・結果
150
- サイトでは300×300の画像を使用しているので自分が使用したい画像(300×225)に合わせて変更しました。
138
+ サイトでは300×300の画像を使用しているので自分が使用したい画像(幅300×高さ225)に合わせて変更しました。
151
139
 
152
140
  ### 補足
153
141
  opencv-python:4.9.0.80