Python utils.AvgrageMeter() Examples
The following are 30
code examples of utils.AvgrageMeter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
utils
, or try the search function
.
Example #1
Source File: train_search.py From NAS-Benchmark with GNU General Public License v3.0 | 6 votes |
def infer(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(valid_queue): input = input.cuda() target = target.cuda(non_blocking=True) with torch.no_grad(): logits = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data.item(), n) top1.update(prec1.data.item(), n) top5.update(prec5.data.item(), n) if step % args.report_freq == 0: logging.info('valid %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #2
Source File: train_cifar.py From NAO_pytorch with GNU General Public License v3.0 | 6 votes |
def valid(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() with torch.no_grad(): model.eval() for step, (input, target) in enumerate(valid_queue): input = input.cuda() target = target.cuda() logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data, n) top1.update(prec1.data, n) top5.update(prec5.data, n) if (step+1) % 100 == 0: logging.info('valid %03d %e %f %f', step+1, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #3
Source File: train_cifar.py From NAS-Benchmark with GNU General Public License v3.0 | 6 votes |
def infer(test_iterator, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() model.eval() for step in test_iterator.yield_steps(): input_, target = test_iterator.__next__() input_ = input_.cuda(non_blocking=True) target = target.cuda(non_blocking=True) with torch.no_grad(): logits, _ = model(input_) loss = criterion(logits, target) prec1, _ = utils.accuracy(logits, target, topk=(1, 5)) n = input_.size(0) objs.update(loss.data.item(), n) top1.update(prec1.data.item(), n) if step % args.report_freq == 0: logging.info('Test Step: %03d Objs: %e Acc: %f', step, objs.avg, top1.avg) return top1.avg, objs.avg
Example #4
Source File: train_controller.py From NAO_pytorch with GNU General Public License v3.0 | 6 votes |
def nao_valid(queue, model): pa = utils.AvgrageMeter() hs = utils.AvgrageMeter() mse = utils.AvgrageMeter() with torch.no_grad(): model.eval() for step, sample in enumerate(queue): encoder_input = sample['encoder_input'] encoder_target = sample['encoder_target'] decoder_target = sample['decoder_target'] encoder_input = encoder_input.cuda() encoder_target = encoder_target.cuda() decoder_target = decoder_target.cuda() predict_value, logits, arch = model(encoder_input) n = encoder_input.size(0) pairwise_acc = utils.pairwise_accuracy(encoder_target.data.squeeze().tolist(), predict_value.data.squeeze().tolist()) hamming_dis = utils.hamming_distance(decoder_target.data.squeeze().tolist(), arch.data.squeeze().tolist()) mse.update(F.mse_loss(predict_value.data.squeeze(), encoder_target.data.squeeze()), n) pa.update(pairwise_acc, n) hs.update(hamming_dis, n) return mse.avg, pa.avg, hs.avg
Example #5
Source File: train_imagenet.py From NAO_pytorch with GNU General Public License v3.0 | 6 votes |
def valid(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() with torch.no_grad(): model.eval() for step, (input, target) in enumerate(valid_queue): input = input.cuda() target = target.cuda() logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data, n) top1.update(prec1.data, n) top5.update(prec5.data, n) if (step+1) % 100 == 0: logging.info('valid %03d %e %f %f', step+1, objs.avg, top1.avg, top5.avg) return top1.avg, top5.avg, objs.avg
Example #6
Source File: test_controller.py From NAO_pytorch with GNU General Public License v3.0 | 6 votes |
def nao_valid(queue, model): pa = utils.AvgrageMeter() hs = utils.AvgrageMeter() with torch.no_grad(): model.eval() for step, sample in enumerate(queue): encoder_input = sample['encoder_input'] encoder_target = sample['encoder_target'] decoder_target = sample['decoder_target'] encoder_input = encoder_input.cuda() encoder_target = encoder_target.cuda() decoder_target = decoder_target.cuda() predict_value, logits, arch = model(encoder_input) n = encoder_input.size(0) pairwise_acc = utils.pairwise_accuracy(encoder_target.data.squeeze().tolist(), predict_value.data.squeeze().tolist()) hamming_dis = utils.hamming_distance(decoder_target.data.squeeze().tolist(), arch.data.squeeze().tolist()) pa.update(pairwise_acc, n) hs.update(hamming_dis, n) return pa.avg, hs.avg
Example #7
Source File: train_cifar.py From NAO_pytorch with GNU General Public License v3.0 | 6 votes |
def valid(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() with torch.no_grad(): model.eval() for step, (input, target) in enumerate(valid_queue): input = input.cuda() target = target.cuda() logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data, n) top1.update(prec1.data, n) top5.update(prec5.data, n) if (step+1) % 100 == 0: logging.info('valid %03d %e %f %f', step+1, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #8
Source File: train_imagenet.py From NAO_pytorch with GNU General Public License v3.0 | 6 votes |
def valid(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() with torch.no_grad(): model.eval() for step, (input, target) in enumerate(valid_queue): input = input.cuda() target = target.cuda() logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data, n) top1.update(prec1.data, n) top5.update(prec5.data, n) if (step+1) % 100 == 0: logging.info('valid %03d %e %f %f', step+1, objs.avg, top1.avg, top5.avg) return top1.avg, top5.avg, objs.avg
Example #9
Source File: test_imagenet.py From NAS-Benchmark with GNU General Public License v3.0 | 6 votes |
def infer(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(valid_queue): input = Variable(input, volatile=True).cuda() target = Variable(target, volatile=True).cuda(async=True) logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data[0], n) top1.update(prec1.data[0], n) top5.update(prec5.data[0], n) if step % args.report_freq == 0: logging.info('valid %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, top5.avg, objs.avg
Example #10
Source File: test.py From NAS-Benchmark with GNU General Public License v3.0 | 6 votes |
def infer(test_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(test_queue): input = Variable(input, volatile=True).cuda() target = Variable(target, volatile=True).cuda(async=True) logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data[0], n) top1.update(prec1.data[0], n) top5.update(prec5.data[0], n) if step % args.report_freq == 0: logging.info('test %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #11
Source File: test.py From eval-nas with MIT License | 6 votes |
def infer(test_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(test_queue): input = Variable(input, volatile=True).cuda() target = Variable(target, volatile=True).cuda(async=True) logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data[0], n) top1.update(prec1.data[0], n) top5.update(prec5.data[0], n) if step % args.report_freq == 0: logging.info('test %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #12
Source File: test_imagenet.py From eval-nas with MIT License | 6 votes |
def infer(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(valid_queue): input = Variable(input, volatile=True).cuda() target = Variable(target, volatile=True).cuda(async=True) logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data[0], n) top1.update(prec1.data[0], n) top5.update(prec5.data[0], n) if step % args.report_freq == 0: logging.info('valid %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, top5.avg, objs.avg
Example #13
Source File: train_search.py From eval-nas with MIT License | 6 votes |
def nao_valid(queue, model): pa = utils.AvgrageMeter() hs = utils.AvgrageMeter() with torch.no_grad(): model.eval() for step, sample in enumerate(queue): encoder_input = sample['encoder_input'] encoder_target = sample['encoder_target'] decoder_target = sample['decoder_target'] encoder_input = encoder_input.cuda() encoder_target = encoder_target.cuda() decoder_target = decoder_target.cuda() predict_value, logits, arch = model(encoder_input) n = encoder_input.size(0) pairwise_acc = utils.pairwise_accuracy(encoder_target.data.squeeze().tolist(), predict_value.data.squeeze().tolist()) hamming_dis = utils.hamming_distance(decoder_target.data.squeeze().tolist(), arch.data.squeeze().tolist()) pa.update(pairwise_acc, n) hs.update(hamming_dis, n) return pa.avg, hs.avg
Example #14
Source File: train_cifar.py From NAS-Benchmark with GNU General Public License v3.0 | 6 votes |
def valid(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() with torch.no_grad(): model.eval() for step, (input, target) in enumerate(valid_queue): input = input.cuda() target = target.cuda() logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data, n) top1.update(prec1.data, n) top5.update(prec5.data, n) if (step+1) % 100 == 0: logging.info('valid %03d %e %f %f', step+1, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #15
Source File: train_imagenet.py From eval-nas with MIT License | 6 votes |
def infer(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(valid_queue): input = Variable(input, volatile=True).cuda() target = Variable(target, volatile=True).cuda(async=True) logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data[0], n) top1.update(prec1.data[0], n) top5.update(prec5.data[0], n) if step % args.report_freq == 0: logging.info('valid %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, top5.avg, objs.avg
Example #16
Source File: train.py From NAS-Benchmark with GNU General Public License v3.0 | 6 votes |
def infer(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(valid_queue): input = input.cuda(non_blocking=True) target = target.cuda(non_blocking=True) #input = Variable(input).cuda() #target = Variable(target).cuda(async=True) with torch.no_grad(): logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data.item(), n) top1.update(prec1.data.item(), n) top5.update(prec5.data.item(), n) if step % args.report_freq == 0: logging.info('valid %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #17
Source File: test.py From NAS-Benchmark with GNU General Public License v3.0 | 6 votes |
def infer(test_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(test_queue): input = input.cuda() target = target.cuda() with torch.no_grad(): logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data.item(), n) top1.update(prec1.data.item(), n) top5.update(prec5.data.item(), n) if step % args.report_freq == 0: logging.info('test %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #18
Source File: train_search.py From NAS-Benchmark with GNU General Public License v3.0 | 6 votes |
def infer(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(valid_queue): input = input.cuda() target = target.cuda(non_blocking=True) #input = Variable(input).cuda() #target = Variable(target).cuda(async=True) with torch.no_grad(): logits = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data.item(), n) top1.update(prec1.data.item(), n) top5.update(prec5.data.item(), n) if step % args.report_freq == 0: logging.info('valid %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #19
Source File: train_cifar.py From NAS-Benchmark with GNU General Public License v3.0 | 6 votes |
def infer(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(valid_queue): input = input.cuda(non_blocking=True) target = target.cuda(non_blocking=True) with torch.no_grad(): logits, _ = model(input) loss = criterion(logits, target) prec1, _ = utils.accuracy(logits, target, topk=(1,5)) n = input.size(0) objs.update(loss.data.item(), n) top1.update(prec1.data.item(), n) if step % args.report_freq == 0: logging.info('Valid Step: %03d Objs: %e Acc: %f', step, objs.avg, top1.avg) return top1.avg, objs.avg
Example #20
Source File: train_search.py From NAS-Benchmark with GNU General Public License v3.0 | 6 votes |
def nao_valid(queue, model): pa = utils.AvgrageMeter() hs = utils.AvgrageMeter() with torch.no_grad(): model.eval() for step, sample in enumerate(queue): encoder_input = sample['encoder_input'] encoder_target = sample['encoder_target'] decoder_target = sample['decoder_target'] encoder_input = encoder_input.cuda() encoder_target = encoder_target.cuda() decoder_target = decoder_target.cuda() predict_value, logits, arch = model(encoder_input) n = encoder_input.size(0) pairwise_acc = utils.pairwise_accuracy(encoder_target.data.squeeze().tolist(), predict_value.data.squeeze().tolist()) hamming_dis = utils.hamming_distance(decoder_target.data.squeeze().tolist(), arch.data.squeeze().tolist()) pa.update(pairwise_acc, n) hs.update(hamming_dis, n) return pa.avg, hs.avg
Example #21
Source File: train.py From darts with Apache License 2.0 | 6 votes |
def infer(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(valid_queue): input = Variable(input, volatile=True).cuda() target = Variable(target, volatile=True).cuda(async=True) logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data[0], n) top1.update(prec1.data[0], n) top5.update(prec5.data[0], n) if step % args.report_freq == 0: logging.info('valid %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #22
Source File: test.py From darts with Apache License 2.0 | 6 votes |
def infer(test_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(test_queue): input = Variable(input, volatile=True).cuda() target = Variable(target, volatile=True).cuda(async=True) logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data[0], n) top1.update(prec1.data[0], n) top5.update(prec5.data[0], n) if step % args.report_freq == 0: logging.info('test %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #23
Source File: train_imagenet.py From darts with Apache License 2.0 | 6 votes |
def infer(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(valid_queue): input = Variable(input, volatile=True).cuda() target = Variable(target, volatile=True).cuda(async=True) logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data[0], n) top1.update(prec1.data[0], n) top5.update(prec5.data[0], n) if step % args.report_freq == 0: logging.info('valid %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, top5.avg, objs.avg
Example #24
Source File: train_search.py From darts with Apache License 2.0 | 6 votes |
def infer(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.eval() for step, (input, target) in enumerate(valid_queue): input = Variable(input, volatile=True).cuda() target = Variable(target, volatile=True).cuda(async=True) logits = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data[0], n) top1.update(prec1.data[0], n) top5.update(prec5.data[0], n) if step % args.report_freq == 0: logging.info('valid %03d %e %f %f', step, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg
Example #25
Source File: train_imagenet.py From eval-nas with MIT License | 6 votes |
def valid(valid_queue, model, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() with torch.no_grad(): model.eval() for step, (input, target) in enumerate(valid_queue): input = input.cuda() target = target.cuda() logits, _ = model(input) loss = criterion(logits, target) prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data, n) top1.update(prec1.data, n) top5.update(prec5.data, n) if (step+1) % 100 == 0: logging.info('valid %03d %e %f %f', step+1, objs.avg, top1.avg, top5.avg) return top1.avg, top5.avg, objs.avg
Example #26
Source File: train.py From AutoDL with Apache License 2.0 | 5 votes |
def test(model, test_prog, test_vars, exe, data_list): """ test """ test_py_reader, loss_test, acc_test = test_vars test_prog = test_prog.clone(for_test=True) objs = utils.AvgrageMeter() test_reader = reader.test10(FLAGS.data_path, FLAGS.batch_size, data_list) test_py_reader.decorate_paddle_reader(test_reader) test_py_reader.start() test_fetch_list = [acc_test] test_start_time = time.time() step_id = 0 try: while True: prev_test_start_time = test_start_time test_start_time = time.time() acc_v, = exe.run( test_prog, fetch_list=test_fetch_list) objs.update(np.array(acc_v), np.array(acc_v).shape[0]) step_id += 1 except fluid.core.EOFException: test_py_reader.reset() print("test acc {0}".format(objs.avg)) return objs.avg
Example #27
Source File: train.py From SinglePathOneShot with MIT License | 5 votes |
def validate(model, device, args, *, all_iters=None): objs = AvgrageMeter() top1 = AvgrageMeter() top5 = AvgrageMeter() loss_function = args.loss_function val_dataprovider = args.val_dataprovider model.eval() max_val_iters = 250 t1 = time.time() with torch.no_grad(): for _ in range(1, max_val_iters + 1): data, target = val_dataprovider.next() target = target.type(torch.LongTensor) data, target = data.to(device), target.to(device) output = model(data) loss = loss_function(output, target) prec1, prec5 = accuracy(output, target, topk=(1, 5)) n = data.size(0) objs.update(loss.item(), n) top1.update(prec1.item(), n) top5.update(prec5.item(), n) logInfo = 'TEST Iter {}: loss = {:.6f},\t'.format(all_iters, objs.avg) + \ 'Top-1 err = {:.6f},\t'.format(1 - top1.avg / 100) + \ 'Top-5 err = {:.6f},\t'.format(1 - top5.avg / 100) + \ 'val_time = {:.6f}'.format(time.time() - t1) logging.info(logInfo)
Example #28
Source File: train_imagenet.py From NAS-Benchmark with GNU General Public License v3.0 | 5 votes |
def train(train_queue, model, optimizer, global_step, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.train() for step, (input, target) in enumerate(train_queue): input = input.cuda().requires_grad_() target = target.cuda() optimizer.zero_grad() logits, aux_logits = model(input, global_step) global_step += 1 loss = criterion(logits, target) if aux_logits is not None: aux_loss = criterion(aux_logits, target) loss += 0.4 * aux_loss loss.backward() nn.utils.clip_grad_norm_(model.parameters(), args.grad_clip) optimizer.step() prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data, n) top1.update(prec1.data, n) top5.update(prec5.data, n) if (step+1) % 100 == 0: logging.info('train %03d loss %e top1 %f top5 %f', step+1, objs.avg, top1.avg, top5.avg) return top1.avg, objs.avg, global_step
Example #29
Source File: train_search.py From enas-pytorch with Apache License 2.0 | 5 votes |
def train(train_loader, model, controller, optimizer): total_loss = utils.AvgrageMeter() total_top1 = utils.AvgrageMeter() for step, (data, target) in enumerate(train_loader): model.train() n = data.size(0) data = data.cuda() target = target.cuda() optimizer.zero_grad() controller.eval() dag, _, _ = controller() logits, _ = model(data, dag) loss = F.cross_entropy(logits, target) loss.backward() optimizer.step() prec1 = utils.accuracy(logits, target)[0] total_loss.update(loss.item(), n) total_top1.update(prec1.item(), n) if step % args.report_freq == 0: logging.info('train %03d %e %f', step, total_loss.avg, total_top1.avg) return total_top1.avg
Example #30
Source File: train_search.py From NAS-Benchmark with GNU General Public License v3.0 | 5 votes |
def child_train(train_queue, model, optimizer, global_step, arch_pool, arch_pool_prob, criterion): objs = utils.AvgrageMeter() top1 = utils.AvgrageMeter() top5 = utils.AvgrageMeter() model.train() for step, (input, target) in enumerate(train_queue): input = input.cuda().requires_grad_() target = target.cuda() optimizer.zero_grad() # sample an arch to train arch = utils.sample_arch(arch_pool, arch_pool_prob) logits, aux_logits = model(input, arch, global_step) global_step += 1 loss = criterion(logits, target) if aux_logits is not None: aux_loss = criterion(aux_logits, target) loss += 0.4 * aux_loss loss.backward() nn.utils.clip_grad_norm_(model.parameters(), args.child_grad_bound) optimizer.step() prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5)) n = input.size(0) objs.update(loss.data, n) top1.update(prec1.data, n) top5.update(prec5.data, n) if (step + 1) % 100 == 0: logging.info('Train %03d loss %e top1 %f top5 %f', step + 1, objs.avg, top1.avg, top5.avg) logging.info('Arch: %s', ' '.join(map(str, arch[0] + arch[1]))) return top1.avg, objs.avg, global_step