예제 #1
0
def replay():
    """Loads training data into Replay object.
    """
    from deepreplay.replay import Replay
    return Replay(replay_filename=os.path.join(FIXTURE_DIR,
                                               'hyperparms_in_action.h5'),
                  group_name='part1_activation_functions',
                  model_filename=os.path.join(
                      FIXTURE_DIR, 'part1_activation_functions_model.h5'))
model = build_model(n_layers=5,
                    input_dim=10,
                    units=100,
                    activation=activation,
                    initializer=initializer)

# Since we only need initial weights, we don't even need to train the model!
# We still use the ReplayData callback, but we can pass the model as argument instead
replaydata = ReplayData(X,
                        y,
                        filename=filename,
                        group_name=group_name,
                        model=model)

# Now we feed the data to the actual Replay object so we can build the visualizations
replay = Replay(replay_filename=filename, group_name=group_name)

# Using subplot2grid to assemble a complex figure...
fig = plt.figure(figsize=(12, 6))
ax_zvalues = plt.subplot2grid((2, 2), (0, 0))
ax_weights = plt.subplot2grid((2, 2), (0, 1))
ax_activations = plt.subplot2grid((2, 2), (1, 0))
ax_gradients = plt.subplot2grid((2, 2), (1, 1))

wv = replay.build_weights(ax_weights)
gv = replay.build_gradients(ax_gradients)
# Z-values
zv = replay.build_outputs(ax_zvalues,
                          before_activation=True,
                          exclude_outputs=True,
                          include_inputs=False)
예제 #3
0
model.add(Dense(units=2,
                kernel_initializer=normal_initializer,
                activation='linear',
                name='hidden'))
model.add(Dense(units=1,
                kernel_initializer=normal_initializer,
                activation='sigmoid',
                name='output'))

model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['acc'])

model.fit(X, y, epochs=100, batch_size=16, callbacks=[replaydata])

replay = Replay(replay_filename='spambase_dataset.h5', group_name=group_name)

fig = plt.figure(figsize=(12, 6))
ax_fs = plt.subplot2grid((2, 4), (0, 0), colspan=2, rowspan=2)
ax_ph_neg = plt.subplot2grid((2, 4), (0, 2))
ax_ph_pos = plt.subplot2grid((2, 4), (1, 2))
ax_lm = plt.subplot2grid((2, 4), (0, 3))
ax_lh = plt.subplot2grid((2, 4), (1, 3))

fs = replay.build_feature_space(ax_fs, layer_name='hidden',
                                display_grid=False, scale_fixed=False)
ph = replay.build_probability_histogram(ax_ph_neg, ax_ph_pos)
lh = replay.build_loss_histogram(ax_lh)
lm = replay.build_loss_and_metric(ax_lm, 'acc')

sample_figure = compose_plots([fs, ph, lm, lh], 80)
예제 #4
0
model = Sequential()
model.add(Dense(input_dim=2, units=5, kernel_initializer=he_initializer))
model.add(Activation('relu'))
model.add(Dense(units=3, kernel_initializer=he_initializer))
model.add(Activation('relu'))
model.add(
    Dense(units=1,
          kernel_initializer=normal_initializer,
          activation='sigmoid',
          name='output'))

model.compile(loss='binary_crossentropy', optimizer=sgd, metrics=['acc'])

model.fit(X, y, epochs=200, batch_size=16, callbacks=[replaydata])

replay = Replay(replay_filename='circles_dataset.h5', group_name=group_name)

fig = plt.figure(figsize=(12, 6))
ax_fs = plt.subplot2grid((2, 4), (0, 0), colspan=2, rowspan=2)
ax_ph_neg = plt.subplot2grid((2, 4), (0, 2))
ax_ph_pos = plt.subplot2grid((2, 4), (1, 2))
ax_lm = plt.subplot2grid((2, 4), (0, 3))
ax_lh = plt.subplot2grid((2, 4), (1, 3))

fs = replay.build_decision_boundary(ax_fs, xlim=(-1.5, 1.5), ylim=(-1.5, 1.5))
ph = replay.build_probability_histogram(ax_ph_neg, ax_ph_pos)
lh = replay.build_loss_histogram(ax_lh)
lm = replay.build_loss_and_metric(ax_lm, 'acc')

sample_figure = compose_plots([fs, ph, lm, lh], 150)
sample_figure.savefig('circles.png', dpi=120, format='png')
model.add(
    Dense(input_dim=2,
          units=2,
          activation='sigmoid',
          kernel_initializer=glorot_normal(seed=42),
          name='hidden'))
model.add(
    Dense(units=1,
          activation='sigmoid',
          kernel_initializer=normal(seed=42),
          name='output'))

model.compile(loss='binary_crossentropy',
              optimizer=SGD(lr=0.05),
              metrics=['acc'])

model.fit(X, y, epochs=150, batch_size=16, callbacks=[replaydata])

from deepreplay.replay import Replay

replay = Replay(replay_filename='hyperparams_in_action.h5', group_name='part1')

import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 1, figsize=(5, 5))

fs = replay.build_feature_space(ax, layer_name='hidden')

fs.plot(epoch=60).savefig('feature_space_epoch60.png', dpi=120)
fs.animate().save('feature_space_animation.mp4', dpi=120, fps=5)
예제 #6
0
model.add(Activation('relu'))
model.add(Dense(units=3,
                kernel_initializer=he_initializer))
model.add(Activation('relu'))
model.add(Dense(units=1,
                kernel_initializer=normal_initializer,
                activation='sigmoid',
                name='output'))

model.compile(loss='binary_crossentropy',
              optimizer=sgd,
              metrics=['acc'])

model.fit(X, y, epochs=200, batch_size=16, callbacks=[replaydata])

replay = Replay(replay_filename='circles_dataset.h5', group_name=group_name)

fig = plt.figure(figsize=(12, 6))
ax_fs = plt.subplot2grid((2, 4), (0, 0), colspan=2, rowspan=2)
ax_ph_neg = plt.subplot2grid((2, 4), (0, 2))
ax_ph_pos = plt.subplot2grid((2, 4), (1, 2))
ax_lm = plt.subplot2grid((2, 4), (0, 3))
ax_lh = plt.subplot2grid((2, 4), (1, 3))

fs = replay.build_decision_boundary(ax_fs, xlim=(-1.5, 1.5), ylim=(-1.5, 1.5))
ph = replay.build_probability_histogram(ax_ph_neg, ax_ph_pos)
lh = replay.build_loss_histogram(ax_lh)
lm = replay.build_loss_and_metric(ax_lm, 'acc')

sample_figure = compose_plots([fs, ph, lm, lh], 150)
sample_figure.savefig('circles.png', dpi=120, format='png')
예제 #7
0
                kernel_initializer=glorot_initializer,
                activation='sigmoid',
                name='hidden'))

model.add(Dense(units=1,
                kernel_initializer=normal_initializer,
                activation='sigmoid',
                name='output'))

model.compile(loss='binary_crossentropy',
              optimizer=sgd,
              metrics=['acc'])

model.fit(X, y, epochs=150, batch_size=16, callbacks=[replaydata])

replay = Replay(replay_filename='hyperparms_in_action.h5', group_name=group_name)

fig = plt.figure(figsize=(12, 6))
ax_fs = plt.subplot2grid((2, 4), (0, 0), colspan=2, rowspan=2)
ax_ph_neg = plt.subplot2grid((2, 4), (0, 2))
ax_ph_pos = plt.subplot2grid((2, 4), (1, 2))
ax_lm = plt.subplot2grid((2, 4), (0, 3))
ax_lh = plt.subplot2grid((2, 4), (1, 3))

fs = replay.build_feature_space(ax_fs, layer_name='hidden')
ph = replay.build_probability_histogram(ax_ph_neg, ax_ph_pos)
lh = replay.build_loss_histogram(ax_lh)
lm = replay.build_loss_and_metric(ax_lm, 'acc')

sample_figure = compose_plots([fs, ph, lm, lh], 80)
sample_figure.savefig('part1.png', dpi=120, format='png')
예제 #8
0
model.add(
    Dense(units=2,
          kernel_initializer=normal_initializer,
          activation='linear',
          name='hidden'))
model.add(
    Dense(units=1,
          kernel_initializer=normal_initializer,
          activation='sigmoid',
          name='output'))

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['acc'])

model.fit(X, y, epochs=100, batch_size=16, callbacks=[replaydata])

replay = Replay(replay_filename='spambase_dataset.h5', group_name=group_name)

fig = plt.figure(figsize=(12, 6))
ax_fs = plt.subplot2grid((2, 4), (0, 0), colspan=2, rowspan=2)
ax_ph_neg = plt.subplot2grid((2, 4), (0, 2))
ax_ph_pos = plt.subplot2grid((2, 4), (1, 2))
ax_lm = plt.subplot2grid((2, 4), (0, 3))
ax_lh = plt.subplot2grid((2, 4), (1, 3))

fs = replay.build_feature_space(ax_fs,
                                layer_name='hidden',
                                display_grid=False,
                                scale_fixed=False)
ph = replay.build_probability_histogram(ax_ph_neg, ax_ph_pos)
lh = replay.build_loss_histogram(ax_lh)
lm = replay.build_loss_and_metric(ax_lm, 'acc')
예제 #9
0
    model.add(Dense(units=1,
                    kernel_initializer=normal_initializer,
                    activation='sigmoid',
                    name='output'))

    model.compile(loss='binary_crossentropy',
                  optimizer=sgd,
                  metrics=['acc'])

    model.fit(X, y, epochs=150, batch_size=16, callbacks=[replaydata])

fig, axs = plt.subplots(1, 3, figsize=(12, 4))

replays = []
for activation in ['sigmoid', 'tanh', 'relu']:
    replays.append(Replay(replay_filename='comparison_activation_functions.h5', group_name=activation))

spaces = []
for ax, replay, activation in zip(axs, replays, ['sigmoid', 'tanh', 'relu']):
    space = replay.build_feature_space(ax, layer_name='hidden')
    space.set_title(activation)
    spaces.append(space)

sample_figure = compose_plots(spaces, 80)
sample_figure.savefig('comparison.png', dpi=120, format='png')

#sample_anim = compose_animations(spaces)
#sample_anim.save(filename='comparison.mp4', dpi=120, fps=5)