Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
x_test = np.random.random((100, 20))
y_test = keras.utils.to_categorical(
np.random.randint(10, size=(100, 1)), num_classes=10)
# Build model
model = Sequential()
model.add(Dense(64, input_dim=20, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(128))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(10))
model.add(Activation('softmax'))
# Delve-specific
tbCallBack = CustomTensorBoard(log_dir='./runs', user_defined_freq=1)
saturation_logger = SaturationLogger(
model, input_data=x_train[:2], print_freq=1)
# Train and evaluate model
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model = Model(model.get_input_at(0), outputs=model.output)
model.compile(
loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
# # Optional - save to csv
# csv_logger = keras.callbacks.CSVLogger('1.log')
model.fit(
x_train,
y_train,
epochs=100,
def on_epoch_begin(self, epoch, logs=None):
"""Add user-def. op to Model eval_function callbacks, reset batch count."""
# check if histogram summary should be run for this epoch
if self.user_defined_freq and epoch % self.user_defined_freq == 0:
self._epoch = epoch
# pylint: disable=protected-access
# add the user-defined summary ops if it should run this epoch
self.model._make_eval_function()
if self.merged not in self.model._eval_function.fetches:
self.model._eval_function.fetches.append(self.merged)
self.model._eval_function.fetch_callbacks[
self.merged] = self._fetch_callback
# pylint: enable=protected-access
super(CustomTensorBoard, self).on_epoch_begin(epoch, logs=None)