예제 #1
0
config.epochs = 10

(X_train, _), (X_test, _) = mnist.load_data()

X_train = X_train.astype('float32') / 255.
X_test = X_test.astype('float32') / 255.

model = Sequential()
model.add(Reshape((28, 28, 1), input_shape=(28, 28)))
model.add(Conv2D(8, (3, 3), activation='relu', padding='same'))
model.add(MaxPooling2D(2, 2))
model.add(Conv2D(4, (3, 3), activation='relu', padding='same'))
model.add(MaxPooling2D(2, 2))
model.add(Conv2D(1, (3, 3), activation='relu', padding='same'))
model.add(UpSampling2D((2, 2)))
model.add(Conv2D(12, (3, 3), activation='relu', padding='same'))
model.add(UpSampling2D((2, 2)))
model.add(Conv2D(1, (3, 3), activation='relu', padding='same'))
model.add(Reshape((28, 28)))

model.compile(optimizer='adam', loss='mse')

model.fit(X_train,
          X_train,
          epochs=config.epochs,
          validation_data=(X_test, X_test),
          callbacks=[Images(), WandbCallback(save_model=False)])

model.save('auto-cnn.h5')
# Load and normalize data
(x_train, _), (x_test, _) = tf.keras.datasets.mnist.load_data()
x_train = x_train.astype('float32') / 255.
x_test = x_test.astype('float32') / 255.
(x_train_noisy, x_test_noisy) = add_noise(x_train, x_test)

model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Reshape((28, 28, 1), input_shape=(28, 28)))
model.add(tf.keras.layers.Conv2D(32, (3, 3), padding='same',
                                 activation='relu'))
model.add(tf.keras.layers.MaxPooling2D((2, 2)))
model.add(tf.keras.layers.Conv2D(16, (3, 3), padding='same',
                                 activation='relu'))
model.add(tf.keras.layers.UpSampling2D())
model.add(
    tf.keras.layers.Conv2D(1, (3, 3), padding='same', activation='sigmoid'))
model.add(tf.keras.layers.Reshape((28, 28)))
model.compile(optimizer='adam', loss='mse')

model.fit(x_train_noisy,
          x_train,
          epochs=config.epochs,
          validation_data=(x_test_noisy, x_test),
          callbacks=[
              Images(x_test_noisy),
              wandb.keras.WandbCallback(save_model=False)
          ])

model.save("auto-denoise.h5")
예제 #3
0

# Set Hyper-parameters
run = wandb.init()
config = run.config
config.encoding_dim = 32
config.epochs = 10

# Load and normalize data
(X_train, _), (X_test, _) = tf.keras.datasets.mnist.load_data()
X_train = X_train.astype('float32') / 255.
X_test = X_test.astype('float32') / 255.
(X_train_noisy, X_test_noisy) = add_noise(X_train, X_test)

model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Flatten(input_shape=(28, 28)))
model.add(tf.keras.layers.Dense(config.encoding_dim, activation='relu'))
model.add(tf.keras.layers.Dense(784, activation='sigmoid'))
model.add(tf.keras.layers.Reshape((28, 28)))
model.compile(optimizer='adam', loss='binary_crossentropy')

model.fit(
    X_train_noisy,
    X_train,
    epochs=config.epochs,
    validation_data=(X_test_noisy, X_test),
    callbacks=[Images(X_test),
               wandb.keras.WandbCallback(save_model=False)])

model.save("auto-denoise.h5")
예제 #4
0
X_test = X_test.astype('float32') / 255.

encoder = tf.keras.models.Sequential()
encoder.add(tf.keras.layers.Flatten(input_shape=(28, 28)))
encoder.add(tf.keras.layers.Dense(128, activation="relu"))
encoder.add(tf.keras.layers.Dense(64, activation="relu"))\

encoder.add(tf.keras.layers.Dense(config.encoding_dim, activation="relu"))

decoder = tf.keras.models.Sequential()
decoder.add(tf.keras.layers.Dense(64, activation="relu",
                                  input_shape=(config.encoding_dim,)))
decoder.add(tf.keras.layers.Dense(128, activation="relu"))
decoder.add(tf.keras.layers.Dense(28*28, activation="sigmoid"))
decoder.add(tf.keras.layers.Reshape((28, 28)))

model = tf.keras.models.Sequential()
model.add(encoder)
model.add(decoder)

model.compile(optimizer='adam', loss='mse')

model.fit(X_train, X_train,
          epochs=config.epochs,
          validation_data=(X_test, X_test),
          callbacks=[Images(X_test), wandb.keras.WandbCallback(save_model="false")])


encoder.save('auto-encoder.h5')
decoder.save('auto-decoder.h5')
예제 #5
0
x_test = x_test.astype('float32') / 255.

encoder = Sequential()
encoder.add(Flatten(input_shape=(28,28)))
encoder.add(Dense(64, activation="relu"))
encoder.add(Dense(32, activation="relu"))
encoder.add(Dense(config.encoding_dim, activation="relu"))

decoder = Sequential()
decoder.add(Dense(32, activation="relu", input_shape=(config.encoding_dim,)))
decoder.add(Dense(64, activation="relu"))
decoder.add(Dense(28*28, activation="sigmoid"))
decoder.add(Reshape((28,28)))

model = Sequential()
model.add(encoder)
model.add(decoder)

model.compile(optimizer='adam', loss='mse')


model.fit(x_train, x_train,
            epochs=config.epochs,
            validation_data=(x_test, x_test), 
            callbacks=[Images(), WandbCallback(save_model="false")])

encoder.save('auto-encoder.h5')
decoder.save('auto-decoder.h5')


예제 #6
0
config.epochs = 10

# Load and normalize data
(x_train, _), (x_test, _) = tf.keras.datasets.mnist.load_data()
x_train = x_train.astype('float32') / 255.
x_test = x_test.astype('float32') / 255.
(x_train_noisy, x_test_noisy) = add_noise(x_train, x_test)

model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Reshape((28, 28, 1), input_shape=(28, 28)))
model.add(tf.keras.layers.Conv2D(32, (3, 3), padding='same',
                                 activation='relu'))
model.add(tf.keras.layers.MaxPooling2D((2, 2)))
model.add(tf.keras.layers.Conv2D(16, (3, 3), padding='same',
                                 activation='relu'))
model.add(tf.keras.layers.UpSampling2D())
model.add(
    tf.keras.layers.Conv2D(1, (3, 3), padding='same', activation='sigmoid'))
model.add(tf.keras.layers.Reshape((28, 28)))
model.compile(optimizer='adam', loss='mse')

model.fit(
    x_train_noisy,
    x_train,
    epochs=config.epochs,
    validation_data=(x_test_noisy, x_test),
    callbacks=[Images(X_train),
               wandb.keras.WandbCallback(save_model=False)])

model.save("auto-denoise.h5")