質問編集履歴

2

コードの解釈自体が間違えていたのでコードの変更を行った

2022/02/03 14:45

投稿

hundred
hundred

スコア2

test CHANGED
@@ -1 +1 @@
1
- 3層のニューラルネットワークのエラーについて
1
+ ニューラルネットワークのエラーに中間層の追加のエラーについて
test CHANGED
@@ -1,19 +1,19 @@
1
1
 
2
2
 
3
- ### 3層のニューラルネットワークのプログラムで発生したエラーを直したい
3
+ ### 2層のニューラルネットワークのプログラムで発生したエラーを直したい
4
4
 
5
- 層のニューラルネットワークの構築を行っているのですが、層で行ったときは成功したのですが、層に変更した場合エラーが発生しました。どのように直せばいいか教えていただきたいです。
5
+ 2層のニューラルネットワークの構築を行っているのですが、1層で行ったときは成功したのですが、2層に変更した場合エラーが発生しました。どのように直せばいいか教えていただきたいです。
6
6
 
7
7
  ### 発生している問題・エラーメッセージ
8
8
 
9
9
  ```
10
10
  InvalidType Traceback (most recent call last)
11
- <ipython-input-1-11f6cd99191c> in <module>()
11
+ <ipython-input-7-613018698fb8> in <module>()
12
- 67 data = [xtrain, xtest, ttrain, ttest]
12
+ 68 data = [xtrain, xtest, ttrain, ttest]
13
- 68 result = [train_loss, test_loss]
13
+ 69 result = [train_loss, test_loss]
14
- ---> 69 learning_regression(model, optNN, data, result, 100)
14
+ ---> 70 learning_regression(model, optNN, data, result, 100)
15
- 70 plot_result2(result[0], result[1], "loss function", "step", "loss function", 0.0,3)
15
+ 71 plot_result2(result[0], result[1], "loss function", "step", "loss function", 0.0,3)
16
- 71 config.train = False
16
+ 72 config.train = False
17
17
 
18
18
  6 frames
19
19
  /usr/local/lib/python3.7/dist-packages/chainer/utils/type_check.py in expect(self)
@@ -27,15 +27,14 @@
27
27
  Invalid operation is performed in: MeanSquaredError (Forward)
28
28
 
29
29
  Expect: x0.shape == x1.shape
30
- Actual: (50, 20) != (50, 1)
30
+ Actual: (50, 2) != (50, 1)
31
+
31
32
  ```
32
33
 
33
34
  ### 該当のソースコード
34
35
 
35
36
  ```ここに言語名を入力
36
- #3層ニューラルネット
37
-
38
- !pip install chainer #(run it only the first time)
37
+ #!pip install chainer #(run it only the first time)
39
38
  import chainer.optimizers as Opt
40
39
  import chainer.functions as F
41
40
  import chainer.links as L
@@ -50,16 +49,19 @@
50
49
  tdata = (np.sin(ndata)+np.sin(2.0*ndata)).reshape(D,N).astype(np.float32)
51
50
  plt.plot(xdata, tdata)
52
51
  plt.show
53
- C=1
52
+ C=2
54
53
  H=20
55
- NN =Chain(l1=L.Linear(N,H),l2=L.Linear(H,C),bnorml=L.BatchNormalization(H))
54
+ NN=Chain(l1=L.Linear(N,H), l2=L.Linear(H,C),
56
-
55
+ bnorm1=L.BatchNormalization(H))
57
56
  def model(x):
58
57
  h=NN.l1(x)
58
+ # Confirm the difference between each function
59
+ h=F.relu(h) #case-1
60
+ # h=F.sigmoid(h) #case-2
59
- h=F.sin(h)
61
+ h=F.sin(h) #case-3
62
+ #
63
+ h=NN.bnorm1(h)
60
64
  y=NN.l2(h)
61
- h=NN.bnorml(h)
62
- y=NN.bnorml(h)
63
65
  return y
64
66
  def data_divide(Dtrain,D,xdata,tdata):
65
67
  index = np.random.permutation(range(D))
@@ -147,16 +149,8 @@
147
149
 
148
150
  ### 試したこと
149
151
 
150
- 2層の時では成功していたので、
151
- ```ここに言語を入力
152
- def model(x):
153
- h=NN.l1(x)
154
- h=F.sin(h)
155
- y=NN.l2(h)
156
- h=NN.bnorml(h)
157
- y=NN.bnorml(h)
158
- ```
159
- 部分が間違えていのでいかと考え数パターン入力ました。
152
+ 1層時では成功していので、def(x)の部分どを名をして数パターンした。
153
+
160
154
  ### 補足情報(FW/ツールのバージョンなど)
161
155
  python google colaboratryを使用しています。
162
156
 

1

エラーメッセージの追加

2022/02/01 11:11

投稿

hundred
hundred

スコア2

test CHANGED
File without changes
test CHANGED
@@ -7,9 +7,27 @@
7
7
  ### 発生している問題・エラーメッセージ
8
8
 
9
9
  ```
10
+ InvalidType Traceback (most recent call last)
11
+ <ipython-input-1-11f6cd99191c> in <module>()
12
+ 67 data = [xtrain, xtest, ttrain, ttest]
13
+ 68 result = [train_loss, test_loss]
14
+ ---> 69 learning_regression(model, optNN, data, result, 100)
15
+ 70 plot_result2(result[0], result[1], "loss function", "step", "loss function", 0.0,3)
16
+ 71 config.train = False
17
+
18
+ 6 frames
19
+ /usr/local/lib/python3.7/dist-packages/chainer/utils/type_check.py in expect(self)
20
+ 495 raise InvalidType(
21
+ 496 '{0} {1} {2}'.format(self.lhs, self.exp, self.rhs),
22
+ --> 497 '{0} {1} {2}'.format(left, self.inv, right))
23
+ 498
24
+ 499
25
+
10
26
  InvalidType:
11
27
  Invalid operation is performed in: MeanSquaredError (Forward)
12
28
 
29
+ Expect: x0.shape == x1.shape
30
+ Actual: (50, 20) != (50, 1)
13
31
  ```
14
32
 
15
33
  ### 該当のソースコード