質問編集履歴

6

文章修正

2020/11/08 15:45

投稿

yy-_.15
yy-_.15

スコア17

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
 
6
6
 
7
+ ```
8
+
7
- ```import imageio
9
+ import imageio
8
10
 
9
11
  import numpy as np
10
12
 
@@ -18,7 +20,9 @@
18
20
 
19
21
 
20
22
 
23
+ X = []
21
24
 
25
+ y = []
22
26
 
23
27
 
24
28
 
@@ -48,25 +52,27 @@
48
52
 
49
53
 
50
54
 
51
-
55
+
52
56
 
53
57
  p1 = imageio.imread(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png").reshape(150,150,4)
54
58
 
55
- X = np.expand_dims(p1, axis=-1)
59
+ X = np.append(X, p1)
56
60
 
57
61
  y = np.append(y, np.array([0], dtype = np.uint8)).reshape(-1,1)
58
62
 
59
-
63
+
64
+
65
+
60
66
 
61
67
 
62
68
 
63
69
  p2 =imageio.imread(f"/Users/K/Downloads/hifu_photos/normal/normal-{i:03d}.png").reshape(150,150,4)
64
70
 
65
- X = np.expand_dims(p2,axis=-1)
71
+ X = np.append(X, p2)
66
72
 
67
73
  y = np.append(y, np.array([1], dtype = np.uint8)).reshape(-1,1)
68
74
 
69
-
75
+
70
76
 
71
77
  X_train = X[:48]
72
78
 
@@ -76,11 +82,13 @@
76
82
 
77
83
  y_test = y[48:]
78
84
 
85
+
86
+
79
87
  print(X_train.shape)
80
88
 
81
89
 
82
90
 
83
- from keras.models import Sequential
91
+ rom keras.models import Sequential
84
92
 
85
93
  from keras.layers import Dense, Dropout, Flatten
86
94
 
@@ -96,7 +104,7 @@
96
104
 
97
105
  model.add(Conv2D(16, (3, 3),
98
106
 
99
- input_shape=(150, 150, 3), activation='relu'))
107
+ input_shape=(150, 150, 4), activation='relu'))
100
108
 
101
109
  model.add(Conv2D(32, (3, 3), activation='relu'))
102
110
 
@@ -142,36 +150,24 @@
142
150
 
143
151
  print("Computation time:{0:.3f} sec".format(time.time() - startTime))
144
152
 
153
+ ```
154
+
155
+
156
+
157
+ のようにコードを書くと
158
+
145
159
 
146
160
 
147
161
  ```
148
162
 
149
- `` ValueError: Input 0 of layer sequential_49 is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 1]``
163
+ ---> 26 history = model.fit(X_train, y_train, batch_size=1000, epochs=20,verbose=1, validation_data=(X_test, y_test))
150
-
151
- というエラーが出てきてしまいます。
152
-
153
- これはどういう意味でどう解決すれば良いのでしょうか?
154
164
 
155
165
 
156
166
 
167
+ ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 1]
168
+
169
+ ```
157
170
 
158
171
 
159
172
 
160
-
161
- ```ValueError Traceback (most recent call last)
162
-
163
- <ipython-input-250-ea0903ed1297> in <module>
164
-
165
- 24 startTime = time.time()
166
-
167
-
168
-
169
-
170
-
171
- → 26 history = model.fit(X_train, y_train, batch_size=1000, epochs=20,verbose=1, validation_data=(X_test, y_test))```
172
-
173
-
174
-
175
-
176
-
177
- ちなみこの26行でエラーが出ていると記述されております。
173
+ のようにエラーが出てしまます。どこかかしい場所はありますでしょうか。。

5

文章修正

2020/11/08 15:45

投稿

yy-_.15
yy-_.15

スコア17

test CHANGED
File without changes
test CHANGED
@@ -52,7 +52,7 @@
52
52
 
53
53
  p1 = imageio.imread(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png").reshape(150,150,4)
54
54
 
55
- X = p1
55
+ X = np.expand_dims(p1, axis=-1)
56
56
 
57
57
  y = np.append(y, np.array([0], dtype = np.uint8)).reshape(-1,1)
58
58
 
@@ -62,7 +62,7 @@
62
62
 
63
63
  p2 =imageio.imread(f"/Users/K/Downloads/hifu_photos/normal/normal-{i:03d}.png").reshape(150,150,4)
64
64
 
65
- X = p2
65
+ X = np.expand_dims(p2,axis=-1)
66
66
 
67
67
  y = np.append(y, np.array([1], dtype = np.uint8)).reshape(-1,1)
68
68
 
@@ -146,7 +146,7 @@
146
146
 
147
147
  ```
148
148
 
149
- ``` ValueError: Input 0 of layer sequential_38 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 150, 4]``
149
+ `` ValueError: Input 0 of layer sequential_49 is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 1]``
150
150
 
151
151
  というエラーが出てきてしまいます。
152
152
 

4

文章修正

2020/11/08 15:27

投稿

yy-_.15
yy-_.15

スコア17

test CHANGED
File without changes
test CHANGED
@@ -48,7 +48,7 @@
48
48
 
49
49
 
50
50
 
51
- a = np.ones(4)
51
+
52
52
 
53
53
  p1 = imageio.imread(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png").reshape(150,150,4)
54
54
 

3

コードの追記

2020/11/08 14:53

投稿

yy-_.15
yy-_.15

スコア17

test CHANGED
File without changes
test CHANGED
@@ -142,19 +142,15 @@
142
142
 
143
143
  print("Computation time:{0:.3f} sec".format(time.time() - startTime))
144
144
 
145
+
146
+
145
147
  ```
146
148
 
147
- ``` ValueError: Input 0 of layer sequential_38 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 150, 4]```
149
+ ``` ValueError: Input 0 of layer sequential_38 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 150, 4]``
148
-
149
-
150
-
151
-
152
150
 
153
151
  というエラーが出てきてしまいます。
154
152
 
155
-
156
-
157
- これはどういう意味のでしょうか?
153
+ これはどういう意味でどう解決すれば良いのでしょうか?
158
154
 
159
155
 
160
156
 

2

コードの追記

2020/11/08 14:31

投稿

yy-_.15
yy-_.15

スコア17

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- 深層学習をしているのですが
1
+ 深層学習で2つの画像見分けるというものを実装しているのですが
2
2
 
3
3
 
4
4
 
@@ -148,8 +148,34 @@
148
148
 
149
149
 
150
150
 
151
+
152
+
151
153
  というエラーが出てきてしまいます。
152
154
 
153
155
 
154
156
 
155
157
  これはどういう意味なのでしょうか?
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+ ```ValueError Traceback (most recent call last)
166
+
167
+ <ipython-input-250-ea0903ed1297> in <module>
168
+
169
+ 24 startTime = time.time()
170
+
171
+
172
+
173
+
174
+
175
+ → 26 history = model.fit(X_train, y_train, batch_size=1000, epochs=20,verbose=1, validation_data=(X_test, y_test))```
176
+
177
+
178
+
179
+
180
+
181
+ ちなみにこの26行でエラーが出ていると記述されております。

1

コードを追加

2020/11/08 14:27

投稿

yy-_.15
yy-_.15

スコア17

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,148 @@
1
1
  深層学習をしているのですが
2
2
 
3
3
 
4
+
5
+
6
+
7
+ ```import imageio
8
+
9
+ import numpy as np
10
+
11
+ from PIL import Image
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ for i in range(1, 61):
26
+
27
+
28
+
29
+ filepath = f"/Users/K/Downloads/hifu_photos/normal/normal-{i:03d}.png"
30
+
31
+ img = Image.open(filepath)
32
+
33
+ img = img.convert("RGBA")
34
+
35
+ img.save(f"/Users/K/Downloads/hifu_photos/normal/normal-{i:03d}.png")
36
+
37
+
38
+
39
+ filepath = f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png"
40
+
41
+ img = Image.open(filepath)
42
+
43
+ img = img.convert("RGBA") ## RGBAカラーに変換
44
+
45
+ img.save(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png")
46
+
47
+
48
+
49
+
50
+
51
+ a = np.ones(4)
52
+
53
+ p1 = imageio.imread(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png").reshape(150,150,4)
54
+
55
+ X = p1
56
+
57
+ y = np.append(y, np.array([0], dtype = np.uint8)).reshape(-1,1)
58
+
59
+
60
+
61
+
62
+
63
+ p2 =imageio.imread(f"/Users/K/Downloads/hifu_photos/normal/normal-{i:03d}.png").reshape(150,150,4)
64
+
65
+ X = p2
66
+
67
+ y = np.append(y, np.array([1], dtype = np.uint8)).reshape(-1,1)
68
+
69
+
70
+
71
+ X_train = X[:48]
72
+
73
+ y_train = y[:48]
74
+
75
+ X_test = X[48:]
76
+
77
+ y_test = y[48:]
78
+
79
+ print(X_train.shape)
80
+
81
+
82
+
83
+ from keras.models import Sequential
84
+
85
+ from keras.layers import Dense, Dropout, Flatten
86
+
87
+ from keras.layers import Conv2D, MaxPooling2D
88
+
89
+ from keras.optimizers import Adam
90
+
91
+ import time
92
+
93
+
94
+
95
+ model = Sequential()
96
+
97
+ model.add(Conv2D(16, (3, 3),
98
+
99
+ input_shape=(150, 150, 3), activation='relu'))
100
+
101
+ model.add(Conv2D(32, (3, 3), activation='relu'))
102
+
103
+ model.add(MaxPooling2D(pool_size=(2, 2))) # (A)
104
+
105
+ model.add(Conv2D(64, (3, 3), activation='relu'))
106
+
107
+ model.add(MaxPooling2D(pool_size=(2, 2))) # (B)
108
+
109
+ model.add(Dropout(0.25)) # (C)
110
+
111
+ model.add(Flatten())
112
+
113
+ model.add(Dense(128, activation='relu'))
114
+
115
+ model.add(Dropout(0.25)) # (D)
116
+
117
+ model.add(Dense(2, activation='softmax'))
118
+
119
+
120
+
121
+ model.compile(loss='categorical_crossentropy',
122
+
123
+ optimizer=Adam(),
124
+
125
+ metrics=['accuracy'])
126
+
127
+
128
+
129
+ startTime = time.time()
130
+
131
+
132
+
133
+ history = model.fit(X_train, y_train, batch_size=1000, epochs=20,verbose=1, validation_data=(X_test, y_test))
134
+
135
+
136
+
137
+
138
+
139
+ loss, accuracy = model.evaluate(X_test, y_test)
140
+
141
+ print("loss:{} accuracy:{}".format(loss, accuracy))
142
+
143
+ print("Computation time:{0:.3f} sec".format(time.time() - startTime))
144
+
145
+ ```
4
146
 
5
147
  ``` ValueError: Input 0 of layer sequential_38 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 150, 4]```
6
148