问题描述
我正在使用 keras 并尝试使用张量板绘制日志.波纹管您可以找出我收到的错误以及我正在使用的软件包版本列表.我无法理解它给了我顺序"对象没有属性_get_distribution_strategy"的错误.
I am using keras and trying to plot the logs using tensorboard. Bellow you can find out the error I am getting and also the list of packages versions I am using. I can not understand it is giving me the error of 'Sequential' object has no attribute '_get_distribution_strategy'.
包装:凯拉斯 2.3.1Keras-应用程序 1.0.8Keras-预处理 1.1.0张量板 2.1.0张量流 2.1.0张量流估计器 2.1.0
Package:Keras 2.3.1Keras-Applications 1.0.8Keras-Preprocessing 1.1.0tensorboard 2.1.0tensorflow 2.1.0tensorflow-estimator 2.1.0
模型:
model = Sequential()
model.add(Embedding(MAX_NB_WORDS, EMBEDDING_DIM, input_shape=(X.shape[1],)))
model.add(GlobalAveragePooling1D())
#model.add(Dense(10, activation='sigmoid'))
model.add(Dense(len(CATEGORIES), activation='softmax'))
model.summary()
#opt = 'adam' # Here we can choose a certain optimizer for our model
opt = 'rmsprop'
model.compile(loss='categorical_crossentropy', optimizer=opt, metrics=['accuracy']) # Here we choose the loss function, input our optimizer choice, and set our metrics.
# Create a TensorBoard instance with the path to the logs directory
tensorboard = TensorBoard(log_dir='logs/{}'.format(time()),
histogram_freq = 1,
embeddings_freq = 1,
embeddings_data = X)
history = model.fit(X, Y, epochs=epochs, batch_size=batch_size, validation_split=0.1, callbacks=[tensorboard])
错误:
C:UsersBrunoAppDataLocalProgramsPythonPython37libsite-packageskerascallbacks ensorboard_v2.py:102: UserWarning: The TensorBoard callback does not support embeddings display when using TensorFlow 2.0. Embeddings-related arguments are ignored.
warnings.warn('The TensorBoard callback does not support '
C:UsersBrunoAppDataLocalProgramsPythonPython37libsite-packages ensorflow_corepythonframeworkindexed_slices.py:433: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.
"Converting sparse IndexedSlices to a dense Tensor of unknown shape. "
Train on 1123 samples, validate on 125 samples
Traceback (most recent call last):
File ".NN_Training.py", line 128, in <module>
history = model.fit(X, Y, epochs=epochs, batch_size=batch_size, validation_split=0.1, callbacks=[tensorboard]) # Feed in the train
set for X and y and run the model!!!
File "C:UsersBrunoAppDataLocalProgramsPythonPython37libsite-packageskerasengine raining.py", line 1239, in fit
validation_freq=validation_freq)
File "C:UsersBrunoAppDataLocalProgramsPythonPython37libsite-packageskerasengine raining_arrays.py", line 119, in fit_loop
callbacks.set_model(callback_model)
File "C:UsersBrunoAppDataLocalProgramsPythonPython37libsite-packageskerascallbackscallbacks.py", line 68, in set_model
callback.set_model(model)
File "C:UsersBrunoAppDataLocalProgramsPythonPython37libsite-packageskerascallbacks ensorboard_v2.py", line 116, in set_model
super(TensorBoard, self).set_model(model)
File "C:UsersBrunoAppDataLocalProgramsPythonPython37libsite-packages ensorflow_corepythonkerascallbacks.py", line 1532, in
set_model
self.log_dir, self.model._get_distribution_strategy()) # pylint: disable=protected-access
AttributeError: 'Sequential' object has no attribute '_get_distribution_strategy'```
推荐答案
你在 keras
和 tf.keras
之间混合导入,它们不是同一个库这不受支持.
You are mixing imports between keras
and tf.keras
, they are not the same library and doing this is not supported.
您应该从其中一个库中进行所有导入,keras
或 tf.keras
.
You should make all imports from one of the libraries, either keras
or tf.keras
.
这篇关于Keras 和 TensorBoard - AttributeError: 'Sequential' 对象没有属性 '_get_distribution_strategy'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!