Exemplo n.º 1
0
def compute_time():
    """
    计算100次,取平均值
    :return:
    """
    model_googlenet_bn = googlenet_bn.GoogLeNet_BN(num_classes=1000)
    model_googlenet = googlenet.GoogLeNet(num_classes=1000)
    model_googlenet_bn.eval()
    model_googlenet.eval()

    total_time_googlenet_bn = 0.0
    total_time_googlenet = 0.0

    epoch = 100
    for i in range(epoch):
        data = torch.randn((1, 3, 224, 224))
        start = time.time()
        outputs = model_googlenet_bn.forward(data)
        end = time.time()
        total_time_googlenet_bn += (end - start)

        start = time.time()
        outputs = model_googlenet.forward(data)
        end = time.time()
        total_time_googlenet += (end - start)

    print('[googlenet_bn] time: {:.4f}'.format(total_time_googlenet_bn /
                                               epoch))
    print('[googlenet] time: {:.4f}'.format(total_time_googlenet / epoch))
    print('time_googlenet / time_googlenet_bn: {:.3f}'.format(
        total_time_googlenet / total_time_googlenet_bn))
Exemplo n.º 2
0
def compute_param():
    model_googlenet_bn = googlenet_bn.GoogLeNet_BN(num_classes=1000)
    model_googlenet = googlenet.GoogLeNet(num_classes=1000)
    model_googlenet_bn.eval()
    model_googlenet.eval()

    num_googlenet_bn = util.num_model(model_googlenet_bn)
    num_googlenet = util.num_model(model_googlenet)

    print('[googlenet_bn] param num: {}'.format(num_googlenet_bn))
    print('[googlenet] param num: {}'.format(num_googlenet))

    print('num_googlenet_bn / num_googlenet: {:.2f}'.format(num_googlenet_bn /
                                                            num_googlenet))
Exemplo n.º 3
0
def test():
    model_googlenet_bn = googlenet_bn.GoogLeNet_BN(num_classes=1000)
    # print(model_googlenet_bn)

    # 训练阶段
    model_googlenet_bn.train()
    data = torch.randn((1, 3, 224, 224))
    outputs, aux2, aux1 = model_googlenet_bn.forward(data)
    print(outputs.shape)
    print(aux2.shape)
    print(aux1.shape)

    # 测试阶段
    model_googlenet_bn.eval()
    data = torch.randn((1, 3, 224, 224))
    outputs = model_googlenet_bn.forward(data)
    print(outputs.shape)
Exemplo n.º 4
0
    return model, loss_dict, acc_dict


if __name__ == '__main__':
    device = util.get_device()
    # device = 'cpu'

    data_loaders, data_sizes = load_data('./data/pascal-voc')
    print(data_loaders)
    print(data_sizes)

    res_loss = dict()
    res_acc = dict()
    for name in ['googlenet_bn', 'googlenet']:
        if name == 'googlenet_bn':
            model = googlenet_bn.GoogLeNet_BN(num_classes=20)
        else:
            model = googlenet.GoogLeNet(num_classes=20)
        model.eval()
        # print(model)
        model = model.to(device)

        criterion = nn.CrossEntropyLoss()
        optimizer = optim.Adam(model.parameters(), lr=1e-3)
        lr_schduler = optim.lr_scheduler.StepLR(optimizer,
                                                step_size=8,
                                                gamma=0.96)

        util.check_dir('./data/models/')
        best_model, loss_dict, acc_dict = train_model(data_loaders,
                                                      data_sizes,