質問編集履歴

2

エラーのプログラムをいれました

2020/07/25 04:24

投稿

milano
milano

スコア14

test CHANGED
File without changes
test CHANGED
@@ -104,6 +104,54 @@
104
104
 
105
105
  Google colaboratoryでプログラムをしています。
106
106
 
107
+ ```
108
+
109
+ <ipython-input-4-6bf313ee2707> in learner(x_traina, x_trainb, x_trainc, y_train, x_testa, x_testb, x_testc, y_test, y_test1, flag)
110
+
111
+ 44 x = Conv1D(filters, kernel_size2, strides=1, padding="valid",activation="relu")(x)
112
+
113
+ 45 x = Conv1D(filters, kernel_size2, strides=1, padding="valid",activation="relu")(x)
114
+
115
+ ---> 46 x = Flatten(x)
116
+
117
+ 47 x = Model(inputs=input1, outputs=x)
118
+
119
+ 48
120
+
121
+
122
+
123
+ /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/core.py in __init__(self, data_format, **kwargs)
124
+
125
+ 629 def __init__(self, data_format=None, **kwargs):
126
+
127
+ 630 super(Flatten, self).__init__(**kwargs)
128
+
129
+ --> 631 self.data_format = conv_utils.normalize_data_format(data_format)
130
+
131
+ 632 self.input_spec = InputSpec(min_ndim=1)
132
+
133
+ 633
134
+
135
+
136
+
137
+ /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/conv_utils.py in normalize_data_format(value)
138
+
139
+ 190 if value is None:
140
+
141
+ 191 value = backend.image_data_format()
142
+
143
+ --> 192 data_format = value.lower()
144
+
145
+ 193 if data_format not in {'channels_first', 'channels_last'}:
146
+
147
+ 194 raise ValueError('The `data_format` argument must be one of '
148
+
149
+
150
+
151
+ AttributeError: 'Tensor' object has no attribute 'lower'
152
+
153
+ ```
154
+
107
155
  ```Python
108
156
 
109
157
  import tensorflow.keras

1

Flattenを書き加えました

2020/07/25 04:24

投稿

milano
milano

スコア14

test CHANGED
File without changes
test CHANGED
@@ -99,3 +99,105 @@
99
99
  model.fit([x_traina,x_trainb,x_trainc], y_train, epochs=1, batch_size=1, validation_data=([x_testa,x_testb,x_testc], y_test))
100
100
 
101
101
  ```
102
+
103
+ ###編集した部分
104
+
105
+ Google colaboratoryでプログラムをしています。
106
+
107
+ ```Python
108
+
109
+ import tensorflow.keras
110
+
111
+ from tensorflow.keras.layers import Input, concatenate, Dense, Reshape, Conv1D, Flatten
112
+
113
+ from tensorflow.keras.models import Model
114
+
115
+
116
+
117
+ input1 = Input(shape=(90,))
118
+
119
+ input2 = Input(shape=(96,))
120
+
121
+ input3 = Input(shape=(96,))
122
+
123
+ hidden1 = Reshape((90, 1), input_shape = (90,))(input1)
124
+
125
+ hidden2 = Reshape((96, 1), input_shape = (96,))(input2)
126
+
127
+ hidden3 = Reshape((96, 1), input_shape = (96,))(input3)
128
+
129
+
130
+
131
+ filters = 8
132
+
133
+ kernel_size1 = 6
134
+
135
+ kernel_size2 = 3
136
+
137
+ x = Conv1D(filters, kernel_size1, strides=3, padding="valid",activation="relu")(hidden1)
138
+
139
+ x = Conv1D(filters, kernel_size2, strides=1, padding="valid",activation="relu")(x)
140
+
141
+ x = Conv1D(filters, kernel_size2, strides=1, padding="valid",activation="relu")(x)
142
+
143
+ x = Flatten(x)
144
+
145
+ x = Model(inputs=input1, outputs=x)
146
+
147
+
148
+
149
+ y = Conv1D(filters, kernel_size1, strides=3, padding="valid",activation="relu")(hidden2)
150
+
151
+ y = Conv1D(filters, kernel_size2, strides=1, padding="valid",activation="relu")(y)
152
+
153
+ y = Conv1D(filters, kernel_size2, strides=1, padding="valid",activation="relu")(y)
154
+
155
+ y = Flatten(y)
156
+
157
+ y = Model(inputs=input2, outputs=y)
158
+
159
+
160
+
161
+ z = Conv1D(filters, kernel_size1, strides=3, padding="valid",activation="relu")(hidden3)
162
+
163
+ z = Conv1D(filters, kernel_size2, strides=1, padding="valid",activation="relu")(z)
164
+
165
+ z = Conv1D(filters, kernel_size2, strides=1, padding="valid",activation="relu")(z)
166
+
167
+ z = Flatten(z)
168
+
169
+ z = Model(inputs=input3, outputs=z)
170
+
171
+
172
+
173
+ combined = concatenate([x.output, y.output, z.output])
174
+
175
+
176
+
177
+ d = Dense(30, activation="relu")(combined)
178
+
179
+
180
+
181
+ d = Dense(3, activation="softmax")(d)
182
+
183
+
184
+
185
+ model = Model(inputs=[input1, input2, input3], outputs=d)
186
+
187
+
188
+
189
+ model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
190
+
191
+ if flag:
192
+
193
+ pass
194
+
195
+ else:
196
+
197
+ model.load_weights('transfer0.h5')
198
+
199
+ model.fit([x_traina,x_trainb,x_trainc], y_train, epochs=1, batch_size=1, validation_data=([x_testa,x_testb,x_testc], y_test))
200
+
201
+ model.save_weights('transfer0.h5')
202
+
203
+ ```