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

質問編集履歴

6

文章修正

2020/11/08 15:45

投稿

yy-_.15
yy-_.15

スコア17

title CHANGED
File without changes
body CHANGED
@@ -1,15 +1,17 @@
1
1
  深層学習で2つの画像を見分けるというものを実装しているのですが
2
2
 
3
3
 
4
+ ```
4
- ```import imageio
5
+ import imageio
5
6
  import numpy as np
6
7
  from PIL import Image
7
8
 
8
9
 
9
10
 
10
11
 
12
+ X = []
13
+ y = []
11
14
 
12
-
13
15
  for i in range(1, 61):
14
16
 
15
17
  filepath = f"/Users/K/Downloads/hifu_photos/normal/normal-{i:03d}.png"
@@ -23,23 +25,25 @@
23
25
  img.save(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png")
24
26
 
25
27
 
26
-
28
+
27
29
  p1 = imageio.imread(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png").reshape(150,150,4)
28
- X = np.expand_dims(p1, axis=-1)
30
+ X = np.append(X, p1)
29
31
  y = np.append(y, np.array([0], dtype = np.uint8)).reshape(-1,1)
30
-
32
+
31
33
 
34
+
32
35
  p2 =imageio.imread(f"/Users/K/Downloads/hifu_photos/normal/normal-{i:03d}.png").reshape(150,150,4)
33
- X = np.expand_dims(p2,axis=-1)
36
+ X = np.append(X, p2)
34
37
  y = np.append(y, np.array([1], dtype = np.uint8)).reshape(-1,1)
35
-
38
+
36
39
  X_train = X[:48]
37
40
  y_train = y[:48]
38
41
  X_test = X[48:]
39
42
  y_test = y[48:]
43
+
40
44
  print(X_train.shape)
41
45
 
42
- from keras.models import Sequential
46
+ rom keras.models import Sequential
43
47
  from keras.layers import Dense, Dropout, Flatten
44
48
  from keras.layers import Conv2D, MaxPooling2D
45
49
  from keras.optimizers import Adam
@@ -47,7 +51,7 @@
47
51
 
48
52
  model = Sequential()
49
53
  model.add(Conv2D(16, (3, 3),
50
- input_shape=(150, 150, 3), activation='relu'))
54
+ input_shape=(150, 150, 4), activation='relu'))
51
55
  model.add(Conv2D(32, (3, 3), activation='relu'))
52
56
  model.add(MaxPooling2D(pool_size=(2, 2))) # (A)
53
57
  model.add(Conv2D(64, (3, 3), activation='relu'))
@@ -70,20 +74,14 @@
70
74
  loss, accuracy = model.evaluate(X_test, y_test)
71
75
  print("loss:{} accuracy:{}".format(loss, accuracy))
72
76
  print("Computation time:{0:.3f} sec".format(time.time() - startTime))
73
-
74
77
  ```
75
- `` ValueError: Input 0 of layer sequential_49 is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 1]``
76
- というエラーが出てきてしまいます。
77
- これはどういう意味でどう解決すれば良いのでしょうか?
78
78
 
79
+ のようにコードを書くと
79
80
 
81
+ ```
82
+ ---> 26 history = model.fit(X_train, y_train, batch_size=1000, epochs=20,verbose=1, validation_data=(X_test, y_test))
80
83
 
81
- ```ValueError Traceback (most recent call last)
82
- <ipython-input-250-ea0903ed1297> in <module>
83
- 24 startTime = time.time()
84
-
85
-
86
- 26 history = model.fit(X_train, y_train, batch_size=1000, epochs=20,verbose=1, validation_data=(X_test, y_test))```
84
+ ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 1]
85
+ ```
87
86
 
88
-
89
- ちなみにこ26行でエラーが出ていると記述されております。
87
+ ようにエラーが出てしまます。どこかかしい場所はありますでしょうか。。

5

文章修正

2020/11/08 15:45

投稿

yy-_.15
yy-_.15

スコア17

title CHANGED
File without changes
body CHANGED
@@ -25,12 +25,12 @@
25
25
 
26
26
 
27
27
  p1 = imageio.imread(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png").reshape(150,150,4)
28
- X = p1
28
+ X = np.expand_dims(p1, axis=-1)
29
29
  y = np.append(y, np.array([0], dtype = np.uint8)).reshape(-1,1)
30
30
 
31
31
 
32
32
  p2 =imageio.imread(f"/Users/K/Downloads/hifu_photos/normal/normal-{i:03d}.png").reshape(150,150,4)
33
- X = p2
33
+ X = np.expand_dims(p2,axis=-1)
34
34
  y = np.append(y, np.array([1], dtype = np.uint8)).reshape(-1,1)
35
35
 
36
36
  X_train = X[:48]
@@ -72,7 +72,7 @@
72
72
  print("Computation time:{0:.3f} sec".format(time.time() - startTime))
73
73
 
74
74
  ```
75
- ``` 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]``
75
+ `` ValueError: Input 0 of layer sequential_49 is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: [None, 1]``
76
76
  というエラーが出てきてしまいます。
77
77
  これはどういう意味でどう解決すれば良いのでしょうか?
78
78
 

4

文章修正

2020/11/08 15:27

投稿

yy-_.15
yy-_.15

スコア17

title CHANGED
File without changes
body CHANGED
@@ -23,7 +23,7 @@
23
23
  img.save(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png")
24
24
 
25
25
 
26
- a = np.ones(4)
26
+
27
27
  p1 = imageio.imread(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png").reshape(150,150,4)
28
28
  X = p1
29
29
  y = np.append(y, np.array([0], dtype = np.uint8)).reshape(-1,1)

3

コードの追記

2020/11/08 14:53

投稿

yy-_.15
yy-_.15

スコア17

title CHANGED
File without changes
body CHANGED
@@ -70,16 +70,14 @@
70
70
  loss, accuracy = model.evaluate(X_test, y_test)
71
71
  print("loss:{} accuracy:{}".format(loss, accuracy))
72
72
  print("Computation time:{0:.3f} sec".format(time.time() - startTime))
73
+
73
74
  ```
74
- ``` 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]```
75
+ ``` 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]``
75
-
76
-
77
76
  というエラーが出てきてしまいます。
77
+ これはどういう意味でどう解決すれば良いのでしょうか?
78
78
 
79
- これはどういう意味なのでしょうか?
80
79
 
81
80
 
82
-
83
81
  ```ValueError Traceback (most recent call last)
84
82
  <ipython-input-250-ea0903ed1297> in <module>
85
83
  24 startTime = time.time()

2

コードの追記

2020/11/08 14:31

投稿

yy-_.15
yy-_.15

スコア17

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- 深層学習をしているのですが
1
+ 深層学習で2つの画像見分けるというものを実装しているのですが
2
2
 
3
3
 
4
4
  ```import imageio
@@ -73,6 +73,19 @@
73
73
  ```
74
74
  ``` 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]```
75
75
 
76
+
76
77
  というエラーが出てきてしまいます。
77
78
 
78
- これはどういう意味なのでしょうか?
79
+ これはどういう意味なのでしょうか?
80
+
81
+
82
+
83
+ ```ValueError Traceback (most recent call last)
84
+ <ipython-input-250-ea0903ed1297> in <module>
85
+ 24 startTime = time.time()
86
+
87
+
88
+ → 26 history = model.fit(X_train, y_train, batch_size=1000, epochs=20,verbose=1, validation_data=(X_test, y_test))```
89
+
90
+
91
+ ちなみにこの26行でエラーが出ていると記述されております。

1

コードを追加

2020/11/08 14:27

投稿

yy-_.15
yy-_.15

スコア17

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,76 @@
1
1
  深層学習をしているのですが
2
2
 
3
+
4
+ ```import imageio
5
+ import numpy as np
6
+ from PIL import Image
7
+
8
+
9
+
10
+
11
+
12
+
13
+ for i in range(1, 61):
14
+
15
+ filepath = f"/Users/K/Downloads/hifu_photos/normal/normal-{i:03d}.png"
16
+ img = Image.open(filepath)
17
+ img = img.convert("RGBA")
18
+ img.save(f"/Users/K/Downloads/hifu_photos/normal/normal-{i:03d}.png")
19
+
20
+ filepath = f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png"
21
+ img = Image.open(filepath)
22
+ img = img.convert("RGBA") ## RGBAカラーに変換
23
+ img.save(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png")
24
+
25
+
26
+ a = np.ones(4)
27
+ p1 = imageio.imread(f"/Users/K/Downloads/hifu_photos/melano/melano-{i:03d}.png").reshape(150,150,4)
28
+ X = p1
29
+ y = np.append(y, np.array([0], dtype = np.uint8)).reshape(-1,1)
30
+
31
+
32
+ p2 =imageio.imread(f"/Users/K/Downloads/hifu_photos/normal/normal-{i:03d}.png").reshape(150,150,4)
33
+ X = p2
34
+ y = np.append(y, np.array([1], dtype = np.uint8)).reshape(-1,1)
35
+
36
+ X_train = X[:48]
37
+ y_train = y[:48]
38
+ X_test = X[48:]
39
+ y_test = y[48:]
40
+ print(X_train.shape)
41
+
42
+ from keras.models import Sequential
43
+ from keras.layers import Dense, Dropout, Flatten
44
+ from keras.layers import Conv2D, MaxPooling2D
45
+ from keras.optimizers import Adam
46
+ import time
47
+
48
+ model = Sequential()
49
+ model.add(Conv2D(16, (3, 3),
50
+ input_shape=(150, 150, 3), activation='relu'))
51
+ model.add(Conv2D(32, (3, 3), activation='relu'))
52
+ model.add(MaxPooling2D(pool_size=(2, 2))) # (A)
53
+ model.add(Conv2D(64, (3, 3), activation='relu'))
54
+ model.add(MaxPooling2D(pool_size=(2, 2))) # (B)
55
+ model.add(Dropout(0.25)) # (C)
56
+ model.add(Flatten())
57
+ model.add(Dense(128, activation='relu'))
58
+ model.add(Dropout(0.25)) # (D)
59
+ model.add(Dense(2, activation='softmax'))
60
+
61
+ model.compile(loss='categorical_crossentropy',
62
+ optimizer=Adam(),
63
+ metrics=['accuracy'])
64
+
65
+ startTime = time.time()
66
+
67
+ history = model.fit(X_train, y_train, batch_size=1000, epochs=20,verbose=1, validation_data=(X_test, y_test))
68
+
69
+
70
+ loss, accuracy = model.evaluate(X_test, y_test)
71
+ print("loss:{} accuracy:{}".format(loss, accuracy))
72
+ print("Computation time:{0:.3f} sec".format(time.time() - startTime))
73
+ ```
3
74
  ``` 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]```
4
75
 
5
76
  というエラーが出てきてしまいます。