def load_VAE(): model = VAE() model.summary() #model.load_weights('saved_model/VAE2_epochs_weights.h5') model.load_weights('saved_model/VAE_weights.h5') return model
history = model.fit( x_train, x_train, initial_epoch=0, epochs=epochs, batch_size=batch_size, callbacks=callbacks, ) model.save_weights("model_weights_" + str(0) + ".h5") return history if __name__ == '__main__': x_train, y_train, x_test, y_test = prepare_dataset() model = VAE(img_shape, latent_dim) model.built = True weight_path = "model_weights.h5" if os.path.exists(weight_path): model.load_weights(weight_path) optimizer = Adam() history = train_model( model, x_train, optimizer, EPOCHS, batch_size=BATCH_SIZE, )
img_shape = (28, 28, 1) EPOCHS = 2 BATCH_SIZE = 64 # load the mnist Dataset x_train, y_train, x_test, y_test = prepare_dataset() # load model model = VAE(img_shape, latent_dim) optimizer = Adam() # Build the model model.built = True # load model weights if os.path.exists("model_weights.h5"): model.load_weights("model_weights.h5") else: train_model( model, x_train, optimizer, EPOCHS, batch_size=BATCH_SIZE, ) model.load_weights("model_weights_0.h5") '''Visualize the Latent Space Distribution''' def plot_clusters(data, labels): # visualising the latent space mean, _, _ = model.encoder.predict(data)