У меня проблема со вчерашнего дня, и я не понимаю, почему. Я прочитал много подобных тем здесь, но я не нашел никакого решения в моем случае.
Мой импорт следующий:
import numpy as np
import librosa.display
import utils
import librosa
import os
import keras
from keras.callbacks import TensorBoard
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D, BatchNormalization
from keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
Моя модель:
model = keras.Sequential()
model.add(Conv2D(32, kernel_size=(2, 2), activation='relu', input_shape=input_shape))
model.add(BatchNormalization())
model.add(Conv2D(48, kernel_size=(2, 2), activation='relu'))
model.add(BatchNormalization())
model.add(Conv2D(120, kernel_size=(2, 2), activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(BatchNormalization())
model.add(Dropout(0.25))
model.add(Dense(64, activation='relu'))
model.add(BatchNormalization())
model.add(Dropout(0.4))
model.add(Dense(num_classes, activation='softmax'))
model.compile(loss=keras.losses.categorical_crossentropy,
optimizer=keras.optimizers.Adadelta(),
metrics=['accuracy'])
return model
И, наконец:
keras_callback = keras.callbacks.TensorBoard(log_dir='./Graph',
histogram_freq=1,
write_graph=True,
write_images=True)
cnn_model.fit(X_train,
y_train,
batch_size=64,
epochs=1,
verbose=1,
validation_split=0.1,
callbacks=[keras_callback])
Моя ошибка:
AttributeError Traceback (most recent call last)
<ipython-input-31-e1e874d24f0c> in <module>
11 verbose=1,
12 validation_split=0.1,
---> 13 callbacks=[keras_callback])
c:\users\antoine\appdata\local\programs\python\python37\lib\site-packages\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
1237 steps_per_epoch=steps_per_epoch,
1238 validation_steps=validation_steps,
-> 1239 validation_freq=validation_freq)
1240
1241 def evaluate(self,
c:\users\antoine\appdata\local\programs\python\python37\lib\site-packages\keras\engine\training_arrays.py in fit_loop(model, fit_function, fit_inputs, out_labels, batch_size, epochs, verbose, callbacks, val_function, val_inputs, shuffle, initial_epoch, steps_per_epoch, validation_steps, validation_freq)
117 callback_metrics += ['val_' + n for n in model.metrics_names]
118
--> 119 callbacks.set_model(callback_model)
120 callbacks.set_params({
121 'batch_size': batch_size,
c:\users\antoine\appdata\local\programs\python\python37\lib\site-packages\keras\callbacks\callbacks.py in set_model(self, model)
66 self.model = model
67 for callback in self.callbacks:
---> 68 callback.set_model(model)
69
70 def _call_batch_hook(self, mode, hook, batch, logs=None):
c:\users\antoine\appdata\local\programs\python\python37\lib\site-packages\keras\callbacks\tensorboard_v2.py in set_model(self, model)
114 """Sets Keras model and writes graph if specified."""
115 model.run_eagerly = False
--> 116 super(TensorBoard, self).set_model(model)
c:\users\antoine\appdata\local\programs\python\python37\lib\site-packages\tensorflow_core\python\keras\callbacks.py in set_model(self, model)
1530 # possibly distributed settings.
1531 self._log_write_dir = distributed_file_utils.write_dirpath(
-> 1532 self.log_dir, self.model._get_distribution_strategy()) # pylint: disable=protected-access
1533
1534 with context.eager_mode():
AttributeError: 'Sequential' object has no attribute '_get_distribution_strategy'
Я использую Tensorboard 2.1.0, тензор потока 2.1.0, Керас 2.3.1.
Спасибо, вы можете спросить меня, если вы хотите больше деталей!