Пример #1
0
				print('=============== Start Test ===============')
				acc_tmp1 = 0
				acc_tmp2 = 0
				acc_tmp3 = 0
				
				acc_tmp1 = val(test_loader1)
				if args.test_2!=None:
				acc_tmp2 = val(test_loader2)
				if args.test_3!=None:
				acc_tmp3 = val(test_loader3)

			for p in MODEL.parameters():
				p.requires_grad = True
			MODEL.train()

			train_batch()
			
			## show the result on train dataset  while after how many batch 
			#  the result include acc and loss
			if i % args.displayInterval == 0 and i!=0:
				t1 = time.time()            
				print ('Epoch: %d/%d; iter: %d/%d;  Loss: %.2f; time: %.2f s;' %
						(epoch, args.niter, i, len(train_loader),  loss_avg.val(), t1-t0)),

				loss_avg.reset()
				t0 = time.time()
				torch.save(MODEL.state_dict(), '{0}/latest.pth'.format(args.experiment))
			i += 1
		

	
Пример #2
0
    while i < training_iters:

        adjust_lr_exp(optimizer, opt.lr, i + training_iters * epoch,
                      training_iters * opt.niter)

        if i % opt.valInterval == 0 and epoch + float(
                i) / training_iters >= opt.val_start_epoch:
            for p in MODEL.parameters():
                p.requires_grad = False
            MODEL.eval()
            print('=============== Start val (beam size:' + str(opt.n_bm) +
                  ') ===============')

            acc = val_beam(test_dataset1)
            if acc >= 0.945:
                torch.save(MODEL.state_dict(), 'output/acc_%.3f.pth' % (acc))

        for p in MODEL.parameters():
            p.requires_grad = True
        MODEL.train()

        cost = trainBatch()

        if i % opt.displayInterval == 0 and i != 0:
            t1 = time.time()
            ADDEOS_acc = np.mean(train_ADDEOS_correct)
            if opt.LR is True:
                print ('Epoch: %d/%d; iter: %d/%d; Pred1Loss: %.2f; Pred2Loss: %.2f; TotalLoss: %.2f; time: %.2f s;' % \
                      (epoch, opt.niter, i, training_iters, loss_pred_avg1.val(), loss_pred_avg2.val(),  loss_avg.val(), t1-t0)),
            else:
                print ('Epoch: %d/%d; iter: %d/%d; PredLoss: %.2f;  TotalLoss: %.2f; time: %.2f s;' % \
Пример #3
0
            # the result include acc
            # if i % args.valInterval == 0 and epoch+float(i)/len(train_loader)>=args.val_start_epoch:
            if i % 20 == 0:
                for p in MODEL.parameters():
                    p.requires_grad = False
                MODEL.eval()
                print('=============== Start Test ===============')
                acc_tmp1 = 0
                acc_tmp2 = 0
                acc_tmp3 = 0

                acc_tmp1 = val(test_loader1)
                print('step ', i, '/ ', length, ' acc is ', acc_tmp1)
                if acc_tmp1 > acc:
                    acc = acc_tmp1
                    torch.save(MODEL.state_dict(),
                               '{0}/latest.pth'.format(args.output))

                # if args.test_2!=None:
                #     acc_tmp2 = val(test_loader2)
                # if args.test_3!=None:
                #     acc_tmp3 = val(test_loader3)

            for p in MODEL.parameters():
                p.requires_grad = True
            MODEL.train()

            train_batch()

            # if i % args.displayInterval == 0 and i!=0:
            #     t1 = time.time()