input_channel = 1 conv_architecture=[input_channel,12,24,48] #specify encoder #with convolutional layers and hidden dense layer encoder = Encoder([ConvLayers(input_dim=input_dim,conv_architecture=conv_architecture, conv_kernel=[4,4,4], conv_stride=[2,2,2], last_activation="sigmoid"), DenseLayers(architecture=[],output_size=latent_dim)]) #specify decoder-mu decoder_mu = infer_decoder(encoder,last_activation="sigmoid") #symmetrical to encoder #combine them into autoencoder autoencoder = Autoencoder(encoder, decoder_mu) #convert into BAE-Ensemble bae_ensemble = BAE_Ensemble(autoencoder=autoencoder, use_cuda=use_cuda, anchored=True, weight_decay=1, num_samples=5) #train mu network run_auto_lr_range(train_loader, bae_ensemble) bae_ensemble.fit(train_loader,num_epochs=1) #for each model, evaluate and plot: bae_models = [bae_ensemble] id_data_test = test_loader ood_data_list = [ood_loader] train_set_name = "FashionMNIST" #run evaluation test of model on ood data set run_test_model(bae_models=bae_models, id_data_test=test_loader, ood_data_list=ood_data_list, id_data_name=train_set_name, output_reshape_size=(28, 28))
last_activation="sigmoid") #symmetrical to encoder #combine them into autoencoder autoencoder = Autoencoder(encoder, decoder_mu) #convert into VAE bae_model = VAE( autoencoder=autoencoder, num_train_samples=5, num_samples=25, #during prediction only use_cuda=use_cuda, weight_decay=0.001, likelihood="bernoulli") #train mu network run_auto_lr_range(train_loader, bae_model) bae_model.fit(train_loader, num_epochs=10) #for each model, evaluate and plot: bae_models = [bae_model] id_data_test = test_loader ood_data_list = [ood_loader] train_set_name = "CIFAR" #run evaluation test of model on ood data set run_test_model(bae_models=bae_models, id_data_test=test_loader, ood_data_list=ood_data_list, id_data_name=train_set_name, output_reshape_size=(32, 32, 3))
#specify decoder-mu decoder_mu = infer_decoder(encoder, last_activation="sigmoid") #symmetrical to encoder #combine them into autoencoder autoencoder = Autoencoder(encoder, decoder_mu) #convert into BAE-MCDropout bae_mcdropout = BAE_MCDropout(autoencoder=autoencoder, dropout_p=0.2, num_train_samples=5, num_samples=50, use_cuda=use_cuda) #train mu network run_auto_lr_range(train_loader, bae_mcdropout) bae_mcdropout.fit(train_loader, num_epochs=1) #for each model, evaluate and plot: bae_models = [bae_mcdropout] id_data_test = test_loader ood_data_list = [ood_loader] train_set_name = "FashionMNIST" #run evaluation test of model on ood data set run_test_model(bae_models=bae_models, id_data_test=test_loader, ood_data_list=ood_data_list, id_data_name=train_set_name, output_reshape_size=(28, 28))