svm = train_svm(dae=dae, svm=svm, trainLoader=trainLoader, testLoader=testLoader, exDir=opts.load_DAE_from, lr=opts.svmLR) if opts.evalMode: assert opts.loadDAE == True eval_mode(dae, opts.load_DAE_from, opts.M, testLoader, svm=svm) exit() else: #Create a folder for this experiment exDir = make_new_folder(opts.outDir) print 'Outputs will be saved to:', exDir save_input_args(exDir, opts) #save training opts #Create optimizers optimDAE = optim.RMSprop(dae.parameters(), lr=opts.lr) optimDIS = optim.RMSprop(dis.parameters(), lr=opts.lr, momentum=opts.momentum) #Keeping track of training losses = {'enc': [], 'rec': [], 'dis': [], 'test rec': []} #Start training for e in range(opts.maxEpochs): epochEncLoss = 0 epochRecLoss = 0
vae.cuda() classer.cuda() else: print '\n *** NOT USING CUDA ***\n' #eval or train if opts.evalMode: opts.loadCLASSER = True opts.loadDELTAZ = True opts.loadVAE = True else: #create a folder to save the exp exDir = make_new_folder( opts.outDir) # Create a new folder to save results and model info print 'Outputs will be saved to:', exDir save_input_args(exDir, opts) ####### Load pre-trained model or train a model ####### #Load pre-trained nets if available if opts.loadVAE: print 'loadding vae...' vae.load_params(opts.load_VAE_from) if opts.loadCLASSER: print 'loadding classer...' classer.load_params(opts.load_CLASSER_from) if opts.loadDELTAZ: print 'loading deltaZ...' deltaZ = torch.load(join(opts.load_DELTAZ_from, 'deltaZ')) else: if vae.useCUDA: deltaZ = Variable(torch.randn(1, opts.nz).cuda(),