<jupyter_start><jupyter_text>Experiment Config<jupyter_code>base_path = '/home/gsoc0/Adversarial_CapsNet_Pytorch/'
model_path = os.path.join(base_path, "weights")

args = {
    'DATASET_NAME':'mnist',
    'num_classes':10,
    
    
    'USE_CUDA': True if torch.cuda.is_available() else False,
    'BATCH_SIZE': 256,
    'N_EPOCHS': 30,
    'LEARNING_RATE_1': 1e-4,
    'LEARNING_RATE_2': 1e-4,
    'WEIGHTDECAY':5e-6,
    
    #Scheduler
    'USE_SCHEDULER':True,
    'sched_milestones':[8,20,30,40,50],
    'sched_gamma':0.1,
    
    #Loss Function
    'LAMBDA_recon': 1,
    'LAMBDA_class': 1,
    
    #For Decoder'
    'num_features':160,
    'LReLU_negative_slope':0.1,
    'input_height':28,
    'input_width':28,
    'input_channel':1,
    'type':'CapsNet',
    
}

#Setting Default Cuda Device
torch.cuda.set_device(0)<jupyter_output><empty_output><jupyter_text>Model Loading<jupyter_code># Config for 16 1d vectors in Capsule Layer. Set the Softmax Dimension to 1 in this case
class Config:
    def __init__(self, dataset='mnist'):
        # CNN (cnn)
        self.cnn_in_channels = 1
        self.cnn_out_channels = 12
        self.cnn_kernel_size = 15

        # Primary Capsule (pc)
        self.pc_num_capsules = 1
        self.pc_in_channels = 12
        self.pc_out_channels = 16
        self.pc_kernel_size = 8
        self.pc_num_routes = 1 * 7 * 7

        # Digit Capsule 1 (dc)
        self.dc_num_capsules = 49
        self.dc_num_routes = 7 * 7 #7*7*16
        self.dc_in_channels = 16
        self.dc_out_channels = 16 #1
        
        # Digit Capsule 2 (dc)
        self.dc_2_num_capsules = 10
        self.dc_2_num_routes = 7 * 7
        self.dc_2_in_channels = 16 #1
        self.dc_2_out_channels = 16


torch.manual_seed(2)
config = Config()
net = CapsNet(args, config)
# net = torch.nn.DataParallel(net)
net.load_state_dict(torch.load(os.path.join(model_path, 'CapsNet_mnist.pth'), map_location='cpu'))
    
if args['USE_CUDA']:
    net = net.cuda()<jupyter_output><empty_output><jupyter_text>Loading Dataset<jupyter_code>dataloader = {}
dataloader['train'], dataloader['val'] = dataset(args)<jupyter_output><empty_output><jupyter_text>Training CapsuleNet<jupyter_code>optimizer = torch.optim.Adam([
                {'params':net.decoder.parameters(), 'lr':args['LEARNING_RATE_2'], 'weight_decay':args['WEIGHTDECAY']},
                {'params': net.conv_layer.parameters()},
                {'params': net.primary_capsules.parameters()},
                {'params': net.digit_capsules_1.parameters()},
                {'params': net.digit_capsules_2.parameters()},
            ], lr=args['LEARNING_RATE_1'])

train_clean(net, optimizer, dataloader, args)
# torch.save(net.state_dict(), os.path.join(model_path, "./CapsNetMNIST_Recon_model2_iter2.pth"))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13454029108981186, 'fraction_numerical': 0.03301384451544196, 'mean_word_length': 3.263237518910741, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '69585', 'license': 'MIT', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1076, 'n_words': 162, 'path': 'Pretraining_Models/Pretrain_CapsNet_Network.ipynb', 'repo_name': 'dsgiitr/Adversarial_CapsNet_Pytorch', 'size': '2817'}