コード例 #1
0
 def summary(self, input_shape, batch_size=1, device='cpu'):
     print("[%s] Network summary..." % (self.__class__.__name__))
     torchsummary.summary(self,
                          input_size=input_shape,
                          batch_size=batch_size,
                          device=device)
     input = torch.randn([1, *input_shape], dtype=torch.float)
     counter = add_flops_counting_methods(self)
     counter.eval().start_flops_count()
     counter(input)
     print('Flops:  {}'.format(
         flops_to_string(counter.compute_average_flops_cost())))
     print(
         '----------------------------------------------------------------')
コード例 #2
0
ファイル: train.py プロジェクト: rheehot/StatAssist-GradBoost
    args.lr = args.learning_rate
    others = args.weight_decay * 0.01

    if not os.path.isdir(train_config['save_dir']):
        os.mkdir(train_config['save_dir'])

    model_name = train_config["Model"]

    if data_config["dataset_name"].startswith('cifar'):
        model = models.cifar.__dict__[model_name](
            num_classes=data_config["num_classes"])
    else:
        model = models.imagenet.__dict__[model_name](
            num_classes=data_config["num_classes"], pretrained=True)

    model_eval = add_flops_counting_methods(model)
    model_eval.eval().start_flops_count()
    batch = torch.FloatTensor(1, 3, data_config["w"], data_config["h"])
    out = model_eval(batch)
    N_flop = model.compute_average_flops_cost()
    total_parameters = netParams(model)
    print("num_classes: {}".format(data_config["num_classes"]))
    print("total_parameters: {}".format(total_parameters))
    if use_cuda:
        if num_gpu > 1:
            model = torch.nn.DataParallel(model)
            print("make DataParallel")
        model = model.cuda()

    start_epoch = 0
    Max_val_acc1 = 0.0
コード例 #3
0

#reporting results in fps:  
total=0
for x in range(0,200):
    image = torch.randn(1, 3, 360, 640).cuda()
    with torch.no_grad():
        a = time.perf_counter()
        output = net.forward(image)
        torch.cuda.synchronize()
        b = time.perf_counter()
        total+=b-a
print(str(200/total))

batch = torch.FloatTensor(1, 3, 512, 1024).cuda()
model = add_flops_counting_methods(net)
model.eval().start_flops_count()
_ = model(batch)



print('Flops:  {}'.format(flops_to_string(model.compute_average_flops_cost())))
print('Params: ' + get_model_parameters_number(model))


composed_transforms_ts = transforms.Compose([
                        augment.RandomHorizontalFlip(),                
                        augment.CenterCrop((512,1024)),
                        augment.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),#Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),#augment. Normalize_cityscapes(mean=(72.39, 82.91, 73.16)),#123.15, 115.90, 103.06 72.39, 82.91, 73.16
                        augment.ToTensor()])