質問編集履歴

4

誤字

2022/11/07 02:52

投稿

Daiking0215
Daiking0215

スコア0

test CHANGED
File without changes
test CHANGED
@@ -93,7 +93,11 @@
93
93
  self.conv8_6 = nn.Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=1)
94
94
  self.conv8_7 = nn.Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=1)
95
95
 
96
- self.max_pool = nn.MaxPool2d(kernel_size=(2, 2), stride=(2, 2))
96
+ self.max_pool_1 = nn.MaxPool2d(kernel_size=(2, 2), stride=(2, 2))
97
+ self.max_pool_2 = nn.MaxPool2d(kernel_size=(2, 2), stride=(2, 2))
98
+ self.max_pool_3 = nn.MaxPool2d(kernel_size=(2, 2), stride=(2, 2))
99
+ self.max_pool_4 = nn.MaxPool2d(kernel_size=(2, 2), stride=(2, 2))
100
+ self.max_pool_5 = nn.MaxPool2d(kernel_size=(2, 2), stride=(2, 2))
97
101
 
98
102
  # self.bn1 = nn.BatchNorm2d(64)
99
103
  # self.bn2 = nn.BatchNorm2d(128)
@@ -109,29 +113,29 @@
109
113
  def forward(self, x):
110
114
  x = F.relu(self.conv1(x))
111
115
  x = F.relu(self.conv2(x))
112
- x = self.max_pool(x)
116
+ x = self.max_pool_1(x)
113
117
 
114
118
  x = F.relu(self.conv3(x))
115
119
  x = F.relu(self.conv4(x))
116
- x = self.max_pool(x)
120
+ x = self.max_pool_2(x)
117
121
 
118
122
  x = F.relu(self.conv5(x))
119
123
  x = F.relu(self.conv6_1(x))
120
124
  x = F.relu(self.conv6_2(x))
121
125
  x = F.relu(self.conv6_3(x))
122
- x = self.max_pool(x)
126
+ x = self.max_pool_3(x)
123
127
 
124
128
  x = F.relu(self.conv7(x))
125
129
  x = F.relu(self.conv8_1(x))
126
130
  x = F.relu(self.conv8_2(x))
127
131
  x = F.relu(self.conv8_3(x))
128
- x = self.max_pool(x)
132
+ x = self.max_pool_4(x)
129
133
 
130
134
  x = F.relu(self.conv8_4(x))
131
135
  x = F.relu(self.conv8_5(x))
132
136
  x = F.relu(self.conv8_6(x))
133
137
  x = F.relu(self.conv8_7(x))
134
- x = self.max_pool(x)
138
+ x = self.max_pool_5(x)
135
139
 
136
140
  x = x.view(-1, 56*56*128)
137
141
  x = F.relu(self.fc1(x))

3

コード変更

2022/11/07 02:48

投稿

Daiking0215
Daiking0215

スコア0

test CHANGED
File without changes
test CHANGED
@@ -81,22 +81,30 @@
81
81
  self.conv3 = nn.Conv2d(64, 128, kernel_size=(3, 3), stride=(1, 1), padding=1)
82
82
  self.conv4 = nn.Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=1)
83
83
  self.conv5 = nn.Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=1)
84
- self.conv6 = nn.Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=1)
84
+ self.conv6_1 = nn.Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=1)
85
+ self.conv6_2 = nn.Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=1)
86
+ self.conv6_3 = nn.Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=1)
85
87
  self.conv7 = nn.Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=1)
86
- self.conv8 = nn.Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=1)
88
+ self.conv8_1 = nn.Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=1)
89
+ self.conv8_2 = nn.Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=1)
90
+ self.conv8_3 = nn.Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=1)
91
+ self.conv8_4 = nn.Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=1)
92
+ self.conv8_5 = nn.Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=1)
93
+ self.conv8_6 = nn.Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=1)
94
+ self.conv8_7 = nn.Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=1)
87
95
 
88
96
  self.max_pool = nn.MaxPool2d(kernel_size=(2, 2), stride=(2, 2))
89
97
 
90
- self.bn1 = nn.BatchNorm2d(64)
98
+ # self.bn1 = nn.BatchNorm2d(64)
91
- self.bn2 = nn.BatchNorm2d(128)
99
+ # self.bn2 = nn.BatchNorm2d(128)
92
- self.bn3 = nn.BatchNorm2d(256)
100
+ # self.bn3 = nn.BatchNorm2d(256)
93
- self.bn4 = nn.BatchNorm2d(512)
101
+ # self.bn4 = nn.BatchNorm2d(512)
94
-
102
+
95
- self.fc1 = nn.Linear(7*7*512, 512)
103
+ self.fc1 = nn.Linear(56*56*128, 1000)
96
- self.fc2 = nn.Linear(512, 256)
104
+ self.fc2 = nn.Linear(1000, 100)
97
- self.fc3 = nn.Linear(256, 64)
105
+ self.fc3 = nn.Linear(100, 10)
98
- self.fc4 = nn.Linear(64, 16)
106
+ self.fc4 = nn.Linear(10, 1)
99
- self.fc5 = nn.Linear(16, 1)
107
+ # self.fc5 = nn.Linear(16, 1)
100
108
 
101
109
  def forward(self, x):
102
110
  x = F.relu(self.conv1(x))
@@ -106,31 +114,30 @@
106
114
  x = F.relu(self.conv3(x))
107
115
  x = F.relu(self.conv4(x))
108
116
  x = self.max_pool(x)
109
-
117
+
110
118
  x = F.relu(self.conv5(x))
111
- x = F.relu(self.conv6(x))
119
+ x = F.relu(self.conv6_1(x))
112
- x = F.relu(self.conv6(x))
120
+ x = F.relu(self.conv6_2(x))
113
- x = F.relu(self.conv6(x))
121
+ x = F.relu(self.conv6_3(x))
114
122
  x = self.max_pool(x)
115
123
 
116
124
  x = F.relu(self.conv7(x))
117
- x = F.relu(self.conv8(x))
125
+ x = F.relu(self.conv8_1(x))
118
- x = F.relu(self.conv8(x))
126
+ x = F.relu(self.conv8_2(x))
119
- x = F.relu(self.conv8(x))
127
+ x = F.relu(self.conv8_3(x))
120
- x = self.max_pool(x)
128
+ x = self.max_pool(x)
121
-
129
+
122
- x = F.relu(self.conv8(x))
130
+ x = F.relu(self.conv8_4(x))
123
- x = F.relu(self.conv8(x))
131
+ x = F.relu(self.conv8_5(x))
124
- x = F.relu(self.conv8(x))
132
+ x = F.relu(self.conv8_6(x))
125
- x = F.relu(self.conv8(x))
133
+ x = F.relu(self.conv8_7(x))
126
- x = self.max_pool(x)
134
+ x = self.max_pool(x)
127
-
135
+
128
- x = x.view(-1, 7*7*512)
136
+ x = x.view(-1, 56*56*128)
129
137
  x = F.relu(self.fc1(x))
130
138
  x = F.relu(self.fc2(x))
131
139
  x = F.relu(self.fc3(x))
132
- x = F.relu(self.fc4(x))
133
- x = self.fc5(x)
140
+ x = self.fc4(x)
134
141
  return x
135
142
 
136
143
  class MAELoss(nn.Module):
@@ -192,37 +199,6 @@
192
199
  print(y_eval)
193
200
  print('#EPOCH:{}\ttrain loss: {}\tvalid loss: {}\ttime: {}'.format(epoch, running_train_loss * BATCH_SIZE / len(train_dataset), running_test_loss * BATCH_SIZE / len(test_dataset), elapsed_time))
194
201
 
195
- # Plot history
196
- fig,[ax1,ax2] =plt.subplots(1,2,figsize=(12.5,5))
197
- fontsize = 16
198
- labelsize = 15
199
- c1, c2, c3, c4 = "blue", "red", "blue", "red"
200
- l1, l2,l3, l4 = "train", "validation", "train", "validation"
201
- epoch_list = np.arange(EPOCH) + 1
202
-
203
- ax1.plot(epoch_list, train_loss_value, color=c1, label=l1)
204
- ax1.plot(epoch_list, test_loss_value, color=c2, label=l2)
205
- ax1.set_title("Loss Function", fontsize=fontsize)
206
- ax1.set_xlabel('Epoch', fontsize=fontsize)
207
- ax1.set_ylabel('MAE', fontsize=fontsize)
208
- ax1.legend(loc = 'upper right')
209
- ax1.tick_params(axis='x', labelsize=labelsize)
210
- ax1.tick_params(axis='y', labelsize=labelsize)
211
- ax1.grid()
212
-
213
- # ax2.plot(epoch_list, train_eval_value, color=c3, label=l3)
214
- # ax2.plot(epoch_list, test_eval_value, color=c4, label=l4)
215
- ax2.set_title("Evaluate Function", fontsize=fontsize)
216
- ax2.set_xlabel('Epoch', fontsize=fontsize)
217
- ax2.set_ylabel('MAPE[%]', fontsize=fontsize)
218
- ax2.legend(loc = 'upper right')
219
- ax2.tick_params(axis='x', labelsize=labelsize)
220
- ax2.tick_params(axis='y', labelsize=labelsize)
221
- ax2.grid()
222
-
223
- plt.show()
224
-
225
-
226
202
  model.eval()
227
203
  y_eval = model(X.to(device))
228
204
  print(y_eval)
@@ -235,3 +211,4 @@
235
211
  PyTorch 1.12.0+cu116
236
212
  Python 3.8.10
237
213
 
214
+

2

試したことの追記

2022/11/05 06:56

投稿

Daiking0215
Daiking0215

スコア0

test CHANGED
File without changes
test CHANGED
@@ -229,7 +229,7 @@
229
229
  ```
230
230
 
231
231
  ### 試したこと
232
- 構造を2層の全結合層からなる簡単なNNに変更したり,最適化手法・損失関数等を変更したりさまざまなパラメータをいじりましたが,出力値はすべてのデータに対して同じになってしまいました.おそらく学習の過程でパラメータの更新がうまく行っていないのだと予測してはいますがどこで問題が起きているのか皆目検討も付きません.よろしくお願いいたします.
232
+ 構造を2層の全結合層からなる簡単なNNに変更したり,最適化手法・損失関数等を変更したりさまざまなパラメータをいじりましたが,出力値はすべてのデータに対して同じになってしまいました.そのときの重みやバイアスを見たところ最後のバイアスのみ値が変化し,それ以外の重みやバイアスは全て0となっていました.おそらく学習の過程でパラメータの更新がうまく行っていないのだと予測してはいますがどこで問題が起きているのか皆目検討も付きません.よろしくお願いいたします.
233
233
 
234
234
  ### 補足情報(FW/ツールのバージョンなど)
235
235
  PyTorch 1.12.0+cu116

1

誤字の修正

2022/11/04 13:04

投稿

Daiking0215
Daiking0215

スコア0

test CHANGED
File without changes
test CHANGED
@@ -11,7 +11,7 @@
11
11
  各入力に対して異なる出力値を受け取ること.
12
12
 
13
13
  ### 発生している問題・エラーメッセージ
14
- ですせん
14
+ 以下はいくつかのデーを使って推論した出力です.複数のデータに対して同じ出力となってい
15
15
  ```
16
16
  >>> y_eval
17
17
  tensor([[-0.0040],
@@ -26,7 +26,7 @@
26
26
  ```
27
27
 
28
28
  ### 該当のソースコード
29
-
29
+ ベタ付ですみません..
30
30
  ```Python
31
31
  import numpy as np
32
32
  import torch