예제 #1
0
 def train_encoder_classifier(self, alpha=0):
     encoder_classifier, history = self.fit_encoder_classifier(alpha=alpha)
     plots.loss(history,
                self.image_directory,
                name="losses_encoder_classifier")
     self.save_model_weights(encoder_classifier, 'encoder_classifier')
     return encoder_classifier
예제 #2
0
    def train(self):
        """
        Begin logging, train the autoencoder, use the autoencoder's history to plot loss curves, and save the parameters of the autoencoder, encoder, and decoder (respectively) to .h5 files.
        :return: None
        """
        if self.enable_logging:
            logs.begin_logging(self.experiment_directory)

        auto_encoder, encoder, decoder, history = self.fit_autoencoder()

        plots.loss(history, self.image_directory)

        self.save_model_weights(auto_encoder, encoder, decoder)

        self.plot_results((encoder, decoder))
예제 #3
0
    def train_contrastive_mlp(self):
        """
        Begin logging, train the contrastive MLP, use the it's history to plot loss curves, and save the parameters
        to .h5 files.
        :return: None
        """
        if self.enable_logging:
            logs.begin_logging(self.directory)

        contrastive_mlp, history = self.fit_contrastive_mlp()

        plots.loss(history, self.image_directory)

        self.save_model_weights(contrastive_mlp, "contrastive_mlp")

        self.plot_logits(contrastive_mlp)
 def train_classifier(self, alpha=0, evaluate=True, report=True):
     if self.enable_logging:
         logs.begin_logging(self.experiment_directory)
     classifier, history = self.fit_classifier(alpha=alpha)
     self.print_settings()
     plots.loss(history, self.image_directory)
     plots.accuracy(history, self.image_directory)
     self.save_model_weights(classifier, 'classifier')
     if evaluate:
         print('Evaluation')
         result = classifier.evaluate(self.x_test, self.y_test_binary,
                                      batch_size=self.batch_size, )
         print(result)
     if evaluate and report:
         filepath = os.path.abspath(os.path.join(self.experiment_directory, 'report.txt'))
         report = open(filepath, 'w+')
         report.write(f'Loss: {result[0]}\nAccuracy: {result[1]}')
         report.close()
     return classifier
예제 #5
0
    def train(self):
        """
        Begin logging, train the autoencoder, use the autoencoder's history to plot loss curves, and save the parameters
        of the autoencoder, encoder, and decoder (respectively) to .h5 files.
        :return: None
        """
        t0 = time()
        if self.enable_logging:
            logs.begin_logging(self.experiment_directory)
        auto_encoder, encoder, decoder, history = self.fit_autoencoder()
        t1 = time()
        t = t1 - t0
        print(f"Variational autoencoder trained in {t} seconds.\n")
        self.print_settings()
        plots.loss(history, self.image_directory)
        self.save_model_weights(auto_encoder, 'auto_encoder')
        self.save_model_weights(encoder, 'encoder')
        self.save_model_weights(decoder, 'decoder')
        self.plot_results((encoder, decoder))
        self.report_latent_space_classifiers(encoder)

        return auto_encoder, encoder, decoder
예제 #6
0
파일: vae.py 프로젝트: admshumar/ct-vae
    def train(self):
        """
        Begin logging, train the autoencoder, use the autoencoder's history to plot loss curves, and save_all the parameters
        of the autoencoder, encoder, and decoder (respectively) to .h5 files.
        :return: None
        """
        t0 = time()
        if self.enable_logging:
            logs.begin_logging(self.experiment_directory)
        auto_encoder, encoder, decoder, history = self.fit_autoencoder()
        t1 = time()
        t = t1 - t0
        print(f"Variational autoencoder trained in {t} seconds.\n")

        plots.loss(history, self.image_directory)

        self.save_model_weights(auto_encoder, 'auto_encoder')
        self.save_model_weights(encoder, 'encoder')
        self.save_model_weights(decoder, 'decoder')

        #self.save_prediction(encoder, data_filename='x_train_latent.npy')
        self.save_prediction(encoder,
                             data=[self.gaussian_test, self.x_test],
                             data_filename='x_test_latent.npy')
        #self.save_prediction(auto_encoder, data_filename='x_train_predict.npy')
        self.save_prediction(auto_encoder,
                             data=[self.gaussian_test, self.x_test],
                             data_filename='x_test_predict.npy')
        self.save_experiment_settings()
        x_test_pred_file = os.path.abspath(
            os.path.join(self.experiment_directory, 'x_test_predict.npy'))
        x_test_pred = np.load(x_test_pred_file)
        self.save_input_output_comparison(self.x_test, x_test_pred)
        self.report_latent_space_classifiers(encoder)
        self.plot_results((encoder, decoder))

        return auto_encoder, encoder, decoder