text: import os
  import sys
  import glob
  import numpy as np
  import torch
  import utils
  import logging
  import argparse
  import torch.nn as nn
  import genotypes
  import torch.utils
  import torchvision.datasets as dset
  import torch.backends.cudnn as cudnn
  
  from torch.autograd import Variable
  # TODO: possibly use different network
  from model import NetworkCIFAR as Network
  from datasets import load_dataset
  from sklearn.metrics import r2_score
  
  
  parser = argparse.ArgumentParser("darts")
  parser.add_argument('--dataset', type=str, default='cifar', help='name of the dataset to use (e.g. cifar, mnist, graphene)')
  parser.add_argument('--data', type=str, default='../data', help='location of the data corpus')
  parser.add_argument('--batch_size', type=int, default=96, help='batch size')
  parser.add_argument('--report_freq', type=float, default=50, help='report frequency')
  parser.add_argument('--gpu', type=int, default=0, help='gpu device id')
  parser.add_argument('--init_channels', type=int, default=36, help='num of init channels')
  parser.add_argument('--layers', type=int, default=20, help='total number of layers')
  parser.add_argument('--model_path', type=str, default='EXP/model.pt', help='path of pretrained model')
  parser.add_argument('--auxiliary', action='store_true', default=False, help='use auxiliary tower')
  parser.add_argument('--cutout', action='store_true', default=False, help='use cutout')
  parser.add_argument('--cutout_length', type=int, default=16, help='cutout length')
  parser.add_argument('--drop_path_prob', type=float, default=0.2, help='drop path probability')
  parser.add_argument('--seed', type=int, default=0, help='random seed')
  parser.add_argument('--arch', type=str, default='DARTS', help='which architecture to use')
  args = parser.parse_args()
  
  log_format = '%(asctime)s %(message)s'
  logging.basicConfig(stream=sys.stdout, level=logging.INFO,
      format=log_format, datefmt='%m/%d %I:%M:%S %p')
  
  CIFAR_CLASSES = 10
  
  
  def main():
    if not torch.cuda.is_available():
      logging.info('no gpu device available')
      sys.exit(1)
  
    np.random.seed(args.seed)
    torch.cuda.set_device(args.gpu)
    cudnn.benchmark = True
    torch.manual_seed(args.seed)
    cudnn.enabled=True
    torch.cuda.manual_seed(args.seed)
    logging.info('gpu device = %d' % args.gpu)
    logging.info("args = %s", args)
  
    try:  
      genotype = eval("genotypes.%s" % args.arch)
    except (AttributeError, SyntaxError):
      genotype = genotypes.load_genotype_from_file(args.arch)
  
    test_data, OUTPUT_DIM, IN_CHANNELS, is_regression = load_dataset(args, train=False)
  
    model = Network(args.init_channels, OUTPUT_DIM, args.layers, args.auxiliary, genotype, num_channels=IN_CHANNELS)
    model = model.cuda()
  
    utils.load(model, args.model_path)
  
    logging.info("param size = %fMB", utils.count_parameters_in_MB(model))
  
    criterion = nn.CrossEntropyLoss() if not is_regression else nn.MSELoss()
    criterion = criterion.cuda()
  
    test_queue = torch.utils.data.DataLoader(
        test_data, batch_size=args.batch_size, shuffle=False, pin_memory=True, num_workers=2)
  
    model.drop_path_prob = args.drop_path_prob
    test_acc, test_obj = infer(test_queue, model, criterion, is_regression=is_regression)
    logging.info('test_acc (R^2 for regression) %f', test_acc)
  
    weights_foldername = os.path.dirname(args.model_path)
    with open(os.path.join(weights_foldername, "test.txt"), "w") as f:
      f.write(str(test_acc))
  
  
  def infer(test_queue, model, criterion, is_regression=False):
    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)
  
      n = input.size(0)
  
      if not is_regression:
          prec1, prec5 = utils.accuracy(logits, target, topk=(1, 5))
          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('train %03d %e %f %f', step, objs.avg, top1.avg, top5.avg)
      else:
          r2 = r2_score(target.data.cpu().numpy(), logits.data.cpu().numpy())
          objs.update(loss.data[0], n)
          top1.update(r2, n) # "top1" for regression is the R^2
  
          if step % args.report_freq == 0:
            logging.info('train %03d %e %f', step, objs.avg, top1.avg)
  
    return top1.avg, objs.avg
  
  
  if __name__ == '__main__':
    main()
  