best_model_wts = copy.deepcopy(model.state_dict())

        print()

    time_elapsed = time.time() - since
    print('Training complete in {:.0f}m {:.0f}s'.format(
        time_elapsed // 60, time_elapsed % 60))
    print('Best val Acc: {:4f}'.format(best_acc))

    # 가장 나은 모델 가중치를 불러옴
    model.load_state_dict(best_model_wts)
    return model


if __name__ == "__main__":
    freeze_support()

    model_ft = models.resnet18(pretrained=True)
    num_ftrs = model_ft.fc.in_features
    model_ft.fc = torch.nn.Linear(num_ftrs, 2)
    learning_rate = 0.001
    criterion = torch.nn.CrossEntropyLoss()
    optimizer_ft = torch.optim.SGD(model_ft.parameters(),
                                   lr=0.001,
                                   momentum=0.9)
    exp_lr_scheduler = lr_scheduler.StepLR(optimizer_ft,
                                           step_size=7,
                                           gamma=0.1)

    if is_cuda:
        model_ft = model_ft.cuda()
Example #2
0
# przypisanie kolorów wierzchołką zbioru
# @timing
def main(n):
    time1 = time.time()
    for node in n:
        colors_of_nodes[node] = get_color_for_node(node)
    time2 = time.time()
    myfile = open("test.txt", "a")
    myfile.write('%s: \t %0.4f s\n' % ("main", time2 - time1))
    myfile.close()
    return colors_of_nodes

if __name__ == "__main__":

    #wykonanie symulacji
    for cores in range(1, 5):

        n = G.nodes()
        n = [n[i::cores] for i in range(cores)]

        with Pool(cores) as p:
            freeze_support()
            time1 = time.time()
            print(p.map(main, n))
            time2 = time.time()

        myfile = open("test.txt", "a")
        myfile.write('%s: \t %0.4f s\n' % (cores, time2 - time1))
        myfile.close()