質問編集履歴

4

タイトル修正

2018/06/26 04:54

投稿

yohehe
yohehe

スコア48

test CHANGED
@@ -1 +1 @@
1
- kerasを使用してtensorboard上にenbedding visualizationの表示は可能でしょうか?
1
+ kerasを使用してtensorboard上にembedding visualizationのエラーについて
test CHANGED
File without changes

3

プログラム編集

2018/06/26 04:54

投稿

yohehe
yohehe

スコア48

test CHANGED
File without changes
test CHANGED
@@ -82,7 +82,7 @@
82
82
 
83
83
 
84
84
 
85
- logdir="/Users/kayanoyohei/Dropbox/python/"
85
+ logdir="/Users/name/Dropbox/python/"
86
86
 
87
87
 
88
88
 

2

stackoverflowのコードを試してみました

2018/06/26 04:53

投稿

yohehe
yohehe

スコア48

test CHANGED
File without changes
test CHANGED
@@ -61,3 +61,139 @@
61
61
  何度か試してみてはいるのですが、model.fitの時点でエラーが出てしまいます。
62
62
 
63
63
  間違いなどがあれば教えていただけますと幸いです。よろしくお願いいたします。
64
+
65
+
66
+
67
+
68
+
69
+ #stackoverflowで教えていただいた手法の追記
70
+
71
+ ```python
72
+
73
+ import keras
74
+
75
+ from keras.datasets import mnist
76
+
77
+ from keras.models import Sequential
78
+
79
+ from keras.layers import Dense, Dropout
80
+
81
+ from keras import callbacks
82
+
83
+
84
+
85
+ logdir="/Users/kayanoyohei/Dropbox/python/"
86
+
87
+
88
+
89
+ batch_size = 100
90
+
91
+ num_classes = 10
92
+
93
+ epochs = 20
94
+
95
+
96
+
97
+
98
+
99
+ # the data, shuffled and split between train and test sets
100
+
101
+ (x_train, y_train), (x_test, y_test) = mnist.load_data()
102
+
103
+
104
+
105
+ x_train = x_train.reshape(60000, 784)
106
+
107
+ x_test = x_test.reshape(10000, 784)
108
+
109
+ x_train = x_train.astype('float32')
110
+
111
+ x_test = x_test.astype('float32')
112
+
113
+ x_train /= 255
114
+
115
+ x_test /= 255
116
+
117
+ print(x_train.shape[0], 'train samples')
118
+
119
+ print(x_test.shape[0], 'test samples')
120
+
121
+
122
+
123
+ # convert class vectors to binary class matrices
124
+
125
+ y_train = keras.utils.to_categorical(y_train, num_classes)
126
+
127
+ y_test = keras.utils.to_categorical(y_test, num_classes)
128
+
129
+
130
+
131
+ model = Sequential()
132
+
133
+ model.add(Dense(200, activation='relu', input_shape=(784,)))
134
+
135
+ model.add(Dropout(0.2))
136
+
137
+ model.add(Dense(100, activation='relu'))
138
+
139
+ model.add(Dropout(0.2))
140
+
141
+ model.add(Dense(60, activation='relu'))
142
+
143
+ model.add(Dropout(0.2))
144
+
145
+ model.add(Dense(30, activation='relu'))
146
+
147
+ model.add(Dropout(0.2))
148
+
149
+ model.add(Dense(10, activation='softmax'))
150
+
151
+ embedding_layer_names = set(layer.name
152
+
153
+ for layer in model.layers
154
+
155
+ if layer.name.startswith('dense_'))
156
+
157
+ tb = callbacks.TensorBoard(log_dir=log_dir, histogram_freq=10, batch_size=32,write_graph=True, write_grads=True, write_images=True,embeddings_freq=10, embeddings_metadata=None,
158
+
159
+ embeddings_layer_names=embedding_layer_names)
160
+
161
+
162
+
163
+ model.compile(loss='categorical_crossentropy',
164
+
165
+ optimizer='adam',
166
+
167
+ metrics=['accuracy'])
168
+
169
+ history = model.fit(x_train, y_train,
170
+
171
+ callbacks=[tb,early_stop],
172
+
173
+ batch_size=batch_size,
174
+
175
+ epochs=epochs,
176
+
177
+ verbose=1,
178
+
179
+ validation_data=(x_test, y_test))
180
+
181
+ score = model.evaluate(x_test, y_test, verbose=0)
182
+
183
+ print('Test loss:', score[0])
184
+
185
+ print('Test accuracy:', score[1])
186
+
187
+ コード
188
+
189
+ ```
190
+
191
+ 上記サイトに記載されているコードを試したのですが、
192
+
193
+ To visualize embeddings, embeddings_data must be provided.
194
+
195
+
196
+
197
+ model.fitは進行するのですが、上記のエラーが最後に出力されます。
198
+
199
+ embeddings_data=None,[]などで定義したとしても上記のエラーがでてしまいます。すみませんが、embeddings_dataを与えておくということはどういうことなのでしょうか。

1

タイトルを修正しました。

2018/06/26 04:48

投稿

yohehe
yohehe

スコア48

test CHANGED
@@ -1 +1 @@
1
- kerastensorboardenbedding visualizationは可能でしょうか
1
+ kerasを使用してtensorboard上にenbedding visualizationの表示は可能でしょうか?
test CHANGED
File without changes