def test_saved_iter_jVAE(model): X, _ = gen_image_data() X = X[:, 0, ...] vae_model = model((8, 8)) vae_model.fit(X, training_cycles=4, batch_size=2, filename="jvae_metadict") num_iter = vae_model.kdict_["num_iter"] loaded_model = load_model("jvae_metadict.tar") assert_equal(num_iter, loaded_model.kdict_["num_iter"])
def test_saved_optimizer_imspec(): X, X_test = gen_image_data() y, y_test = gen_spectra() i2s_model = ImSpec((8, 8), (16, )) i2s_model.fit(X, y, X_test, y_test, training_cycles=4, batch_size=2) opt1 = i2s_model.optimizer loaded_model = load_model("model_metadict_final.tar") opt2 = loaded_model.optimizer compare_optimizers(opt1, opt2)
def test_saved_optimizer_VAE(model): X, _ = gen_image_data() X = X[:, 0, ...] vae_model = model((8, 8)) vae_model.fit(X, training_cycles=4, batch_size=2, filename="vae_metadict") opt1 = vae_model.optim loaded_model = load_model("vae_metadict.tar") opt2 = loaded_model.optim compare_optimizers(opt1, opt2)
def test_io_imspec(): X, X_test = gen_image_data() y, y_test = gen_spectra() i2s_model = ImSpec((8, 8), (16, )) i2s_model.fit(X, y, X_test, y_test, training_cycles=4, batch_size=2) loaded_model = load_model("model_metadict_final.tar") for p1, p2 in zip(loaded_model.net.parameters(), i2s_model.net.parameters()): assert_array_equal(p1.detach().cpu().numpy(), p2.detach().cpu().numpy())
def test_io_segmentor(model): X, X_test = gen_image_data() y, y_test = gen_image_labels() segmodel = Segmentor(model, nb_classes=3) segmodel.fit(X, y, X_test, y_test, training_cycles=4, batch_size=2) loaded_model = load_model("model_metadict_final.tar") for p1, p2 in zip(loaded_model.net.parameters(), segmodel.net.parameters()): assert_array_equal(p1.detach().cpu().numpy(), p2.detach().cpu().numpy())
def test_resume_training(model): X, _ = gen_image_data() X = X[:, 0, ...] vae_model = model((8, 8)) vae_model.fit(X, training_cycles=4, batch_size=2, filename="vae_metadict") loss0 = abs(vae_model.loss_history["train_loss"][0]) loaded_model = load_model("vae_metadict.tar") loaded_model.fit(X, training_cycles=4, batch_size=2, filename="vae_metadict") loss1 = abs(loaded_model.loss_history["train_loss"][0]) assert_(not np.isnan(loss1)) assert_(loss1 < loss0)
def test_io_VAE(model): X, _ = gen_image_data() X = X[:, 0, ...] vae_model = model((8, 8)) vae_model.fit(X, training_cycles=4, batch_size=2, filename="vae_metadict") loaded_model = load_model("vae_metadict.tar") for p1, p2 in zip(loaded_model.encoder_net.parameters(), vae_model.encoder_net.parameters()): assert_array_equal(p1.detach().cpu().numpy(), p2.detach().cpu().numpy()) for p1, p2 in zip(loaded_model.decoder_net.parameters(), vae_model.decoder_net.parameters()): assert_array_equal(p1.detach().cpu().numpy(), p2.detach().cpu().numpy())
def test_saved_optimizer_segmentor(model): X, X_test = gen_image_data() y, y_test = gen_image_labels() segmodel = Segmentor(model, nb_classes=3) segmodel.fit(X, y, X_test, y_test, training_cycles=4, batch_size=2, filename="segmodel") opt1 = segmodel.optimizer loaded_model = load_model("segmodel_metadict_final.tar") opt2 = loaded_model.optimizer compare_optimizers(opt1, opt2)