質問編集履歴
1
文の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,32 +1,195 @@
|
|
1
1
|
### 前提
|
2
2
|
|
3
|
-
|
3
|
+
3入力1出力のCNNを構築しています。
|
4
|
-
(例)
|
5
|
-
|
4
|
+
今回はmodel.fitの段階でエラーが生じたため質問させていただきます。
|
6
|
-
■■な機能を実装中に以下のエラーメッセージが発生しました。
|
7
5
|
|
8
6
|
### 実現したいこと
|
9
7
|
|
10
|
-
|
8
|
+
構築したCNNで正常に学習させたい
|
11
|
-
- [ ] ▲▲機能を動作するようにする
|
12
9
|
|
13
10
|
### 発生している問題・エラーメッセージ
|
14
11
|
|
15
|
-
|
12
|
+
Traceback (most recent call last):
|
13
|
+
File "C:\dl\data\3input.py", line 128, in <module>
|
14
|
+
hist = model.fit([train_generator1,train_generator2,train_generator3],
|
15
|
+
File "C:\Users\sherl\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
|
16
|
+
raise e.with_traceback(filtered_tb) from None
|
17
|
+
File "C:\Users\sherl\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\engine\data_adapter.py", line 1083, in select_data_adapter
|
16
|
-
|
18
|
+
raise ValueError(
|
17
|
-
|
19
|
+
ValueError: Failed to find data adapter that can handle input: (<class 'list'> containing values of types {"<class 'keras.preprocessing.image.DirectoryIterator'>"}), <class 'NoneType'>
|
18
20
|
|
19
21
|
### 該当のソースコード
|
20
22
|
|
23
|
+
from keras.layers import Input, Dense, concatenate
|
24
|
+
from keras.models import Model
|
25
|
+
from keras.optimizers import SGD
|
26
|
+
from keras.preprocessing.image import ImageDataGenerator
|
27
|
+
from PIL import Image
|
21
|
-
|
28
|
+
import keras
|
29
|
+
import glob
|
30
|
+
import numpy as np
|
31
|
+
import os
|
32
|
+
|
33
|
+
num_classes = 3
|
34
|
+
batch_size = 16
|
35
|
+
epochs = 100
|
36
|
+
data_dir = './comp'
|
37
|
+
filename = '3inputs'
|
38
|
+
|
39
|
+
inputs1 = Input(shape=(256,256,3))
|
40
|
+
inputs2 = Input(shape=(256,256,3))
|
41
|
+
inputs3 = Input(shape=(256,256,3))
|
42
|
+
|
22
|
-
|
43
|
+
X = []
|
23
|
-
|
44
|
+
Y = []
|
45
|
+
|
46
|
+
#for Dimple
|
47
|
+
for f in glob.glob('/comp/D/*.jpg'):
|
48
|
+
fname = os.path.split(f)[1]
|
49
|
+
file_path = '/comp/D/'+ fname
|
50
|
+
im = np.assary(Image.open(file_path))
|
51
|
+
X.append(im)
|
52
|
+
label = [0]
|
53
|
+
Y.append(label)
|
54
|
+
|
55
|
+
#for QC
|
56
|
+
for f in glob.glob('/comp/QC/*.jpg'):
|
57
|
+
fname = os.path.split(f)[1]
|
58
|
+
file_path = '/comp/QC/'+ fname
|
59
|
+
im = np.assary(Image.open(file_path))
|
60
|
+
X.append(im)
|
61
|
+
label = [1]
|
62
|
+
Y.append(label)
|
63
|
+
|
64
|
+
#for IG
|
65
|
+
for f in glob.glob('/comp/IG/*.jpg'):
|
66
|
+
fname = os.path.split(f)[1]
|
67
|
+
file_path = '/comp/IG/'+ fname
|
68
|
+
im = np.assary(Image.open(file_path))
|
69
|
+
X.append(im)
|
70
|
+
label = [2]
|
71
|
+
Y.append(label)
|
72
|
+
|
73
|
+
X = np.array(X)
|
74
|
+
Y = np.array(Y)
|
75
|
+
|
76
|
+
X_train = X.astype('float32') / 256
|
77
|
+
|
78
|
+
Y_train = keras.utils.to_categorical(Y, num_classes)
|
79
|
+
|
80
|
+
x = Dense(64, activation = "relu")(inputs1)
|
81
|
+
x = Dense(64, activation = "relu")(x)
|
82
|
+
|
83
|
+
y = Dense(64, activation = "relu")(inputs2)
|
84
|
+
y = Dense(64, activation = "relu")(y)
|
85
|
+
|
86
|
+
z = Dense(64, activation = "relu")(inputs3)
|
87
|
+
z = Dense(64, activation = "relu")(z)
|
88
|
+
|
89
|
+
combined = concatenate([x, y, z])
|
90
|
+
|
91
|
+
prediction = Dense(10, activation = "softmax")(combined)
|
92
|
+
|
93
|
+
model = Model(inputs = [inputs1, inputs2, inputs3], outputs = prediction)
|
94
|
+
model.compile(optimizer = SGD(lr = 0.0001, momentum = 0.9),
|
95
|
+
loss = 'categorical_crossentropy',
|
96
|
+
metrics = ['accuracy'],
|
97
|
+
)
|
98
|
+
model.summary()
|
99
|
+
|
100
|
+
|
101
|
+
#//------Generator1-------//
|
102
|
+
train_datagen1 = ImageDataGenerator(
|
103
|
+
rescale= 1./255,
|
104
|
+
shear_range = 0.2,
|
105
|
+
zoom_range = 0.2,
|
106
|
+
horizontal_flip= True
|
107
|
+
)
|
108
|
+
|
109
|
+
validation_datagen1 = ImageDataGenerator(rescale = 1./255)
|
110
|
+
|
111
|
+
train_generator1 = train_datagen1.flow_from_directory(
|
112
|
+
data_dir,
|
113
|
+
target_size = (256,256),
|
114
|
+
batch_size = batch_size,
|
115
|
+
class_mode = 'categorical',
|
116
|
+
shuffle = True
|
117
|
+
)
|
118
|
+
|
119
|
+
|
120
|
+
validation_generator1 = validation_datagen1.flow_from_directory(
|
121
|
+
data_dir,
|
122
|
+
target_size = (256,256),
|
123
|
+
batch_size = batch_size,
|
124
|
+
class_mode = 'categorical',
|
125
|
+
shuffle = True
|
126
|
+
)
|
127
|
+
|
128
|
+
#//------Generator2-------//
|
129
|
+
train_datagen2 = ImageDataGenerator(
|
130
|
+
rescale= 1./255,
|
131
|
+
shear_range = 0.2,
|
132
|
+
zoom_range = 0.2,
|
133
|
+
horizontal_flip= True
|
134
|
+
)
|
135
|
+
|
136
|
+
validation_datagen2 = ImageDataGenerator(rescale = 1./255)
|
137
|
+
|
138
|
+
train_generator2 = train_datagen2.flow_from_directory(
|
139
|
+
data_dir,
|
140
|
+
target_size = (256,256),
|
141
|
+
batch_size = batch_size,
|
142
|
+
class_mode = 'categorical',
|
143
|
+
shuffle = True
|
144
|
+
)
|
145
|
+
|
146
|
+
validation_generator2 = validation_datagen2.flow_from_directory(
|
147
|
+
data_dir,
|
148
|
+
target_size = (256,256),
|
149
|
+
batch_size = batch_size,
|
150
|
+
class_mode = 'categorical',
|
151
|
+
shuffle = True
|
152
|
+
)
|
153
|
+
|
154
|
+
#//------Generator3-------//
|
155
|
+
train_datagen3 = ImageDataGenerator(
|
156
|
+
rescale= 1./255,
|
157
|
+
shear_range = 0.2,
|
158
|
+
zoom_range = 0.2,
|
159
|
+
horizontal_flip= True
|
160
|
+
)
|
161
|
+
|
162
|
+
validation_datagen3 = ImageDataGenerator(rescale = 1./255)
|
163
|
+
|
164
|
+
train_generator3 = train_datagen3.flow_from_directory(
|
165
|
+
data_dir,
|
166
|
+
target_size = (256,256),
|
167
|
+
batch_size = batch_size,
|
168
|
+
class_mode = 'categorical',
|
169
|
+
shuffle = True
|
170
|
+
)
|
171
|
+
|
172
|
+
validation_generator3 = validation_datagen3.flow_from_directory(
|
173
|
+
data_dir,
|
174
|
+
target_size = (256,256),
|
175
|
+
batch_size = batch_size,
|
176
|
+
class_mode = 'categorical',
|
177
|
+
shuffle = True
|
178
|
+
)
|
179
|
+
#//-------Generator END-------//
|
180
|
+
|
181
|
+
|
182
|
+
hist = model.fit([train_generator1,train_generator2,train_generator3],
|
183
|
+
epochs = epochs,
|
184
|
+
verbose= 1,
|
185
|
+
validation_data = [validation_generator1, validation_generator2, validation_generator3]
|
186
|
+
)
|
24
187
|
|
25
188
|
### 試したこと
|
26
189
|
|
27
|
-
|
190
|
+
エラー文を見る限り、データ前処理の段階で不具合があるようなので、色々書き換えてみましたが、現状は迷走してしまっています、、、。
|
28
191
|
|
29
192
|
### 補足情報(FW/ツールのバージョンなど)
|
30
193
|
|
31
|
-
|
194
|
+
python
|
32
195
|
|