Esempio n. 1
0
def test(net, test_loader, epoch):
    net.eval()
    test_step = len(test_loader)
    print('\nEvaluating...')
    with torch.no_grad():
        evaluator = Evaluator()
        for i, sample in enumerate(test_loader):
            for key in sample:
                sample[key] = sample[key].cuda()
            output = net(sample)
            evaluator.add(output, sample)
            if (i + 1) % 100 == 0:
                print('Val Step [{}/{}]'.format(i + 1, test_step))

        results = evaluator.evaluate()
        print('Epoch {}/{}'.format(epoch + 1, args.epoch))
        print(
            '|  L.Collar  |  R.Collar  |  L.Sleeve  |  R.Sleeve  |   L.Waist  |   R.Waist  |    L.Hem   |   R.Hem    |     ALL    |'
        )
        print(
            '|   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |'
            .format(results['lm_dist'][0], results['lm_dist'][1],
                    results['lm_dist'][2], results['lm_dist'][3],
                    results['lm_dist'][4], results['lm_dist'][5],
                    results['lm_dist'][6], results['lm_dist'][7],
                    results['lm_dist_all']))
Esempio n. 2
0
def test(net, test_loader, epoch):
    net.eval()
    test_step = len(test_loader)
    print('\nEvaluating...')
    with torch.no_grad():
        evaluator = Evaluator()
        for i, sample in enumerate(test_loader):
            for key in sample:
                if key[0:2] != 'D_':
                    sample[key] = sample[key].cuda()
            output = net(sample)
            evaluator.add(output, sample)
            if (i + 1) % 100 == 0:
                print('Val Step [{}/{}]'.format(i + 1, test_step))  # j + 1 ?

        results = evaluator.evaluate()
        print('Epoch {}/{}'.format(epoch + 1, args.epoch))
        print(
            '|  L.Collar  |  R.Collar  |  L.Sleeve  |  R.Sleeve  |   L.Waist  |   R.Waist  |    L.Hem   |   R.Hem    |     ALL    |'
        )
        print(
            '|   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |'
            .format(results['lm_dist'][0], results['lm_dist'][1],
                    results['lm_dist'][2], results['lm_dist'][3],
                    results['lm_dist'][4], results['lm_dist'][5],
                    results['lm_dist'][6], results['lm_dist'][7],
                    results['lm_dist_all']))
        file = open('results_lr_%.4f_base_%d_de_%d_g_%.2f.txt'% \
                    (args.learning_rate, \
                     args.base_epoch, \
                     args.decay_epoch, \
                     args.gamma), 'a')
        file.write('Epoch {}\n'.format(args.base_epoch + epoch + 1))
        file.write(
            '|  L.Collar  |  R.Collar  |  L.Sleeve  |  R.Sleeve  |   L.Waist  |   R.Waist  |    L.Hem   |   R.Hem    |     ALL    |\n'
        )
        file.write(
            '|   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |\n\n'
            .format(results['lm_dist'][0], results['lm_dist'][1],
                    results['lm_dist'][2], results['lm_dist'][3],
                    results['lm_dist'][4], results['lm_dist'][5],
                    results['lm_dist'][6], results['lm_dist'][7],
                    results['lm_dist_all']))
        file.close()
Esempio n. 3
0
def test(net, test_loader, epoch):
    net.eval()
    test_step = len(test_loader)
    print('\nEvaluating...')
    with torch.no_grad():
        evaluator = Evaluator()
        for i, (sample, img) in enumerate(test_loader):
            #import matplotlib.pyplot as plt
            #print(len(sample['image_original']))
            #plt.imshow(sample['image_original'].numpy().swapaxes(0, 2))
            #plt.show()

            #image_name = sample['image_name']
            #print(image_name)

            for key in sample:
                if key != 'image_name':
                    sample[key] = sample[key].cuda()
            output = net(sample)
            #print(type(output))
            pos_map = output['lm_pos_map']
            #print(pos_map.size())
            #resh = pos_map.reshape(50, 8, -1)
            #print(resh.size())
            evaluator.add(output, sample, img)
            if (i + 1) % 100 == 0:
                print('Val Step [{}/{}]'.format(i + 1, test_step))

        results = evaluator.evaluate()
        print('Epoch {}/{}'.format(epoch + 1, args.epoch))
        print(
            '|  L.Collar  |  R.Collar  |  L.Sleeve  |  R.Sleeve  |   L.Waist  |   R.Waist  |    L.Hem   |   R.Hem    |     ALL    |'
        )
        print(
            '|   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |   {:.5f}  |'
            .format(results['lm_dist'][0], results['lm_dist'][1],
                    results['lm_dist'][2], results['lm_dist'][3],
                    results['lm_dist'][4], results['lm_dist'][5],
                    results['lm_dist'][6], results['lm_dist'][7],
                    results['lm_dist_all']))
Esempio n. 4
0
def test(net, test_loader, epoch):
    net.eval()
    test_step = len(test_loader)
    print('\nEvaluating...')
    with torch.no_grad():
        evaluator = Evaluator()
        pbar2 = tqdm(test_loader)
        for i, sample in enumerate(pbar2):
            iter_start_time = time.time()
            for key in sample:
                sample[key] = sample[key].cuda()

            output = net(sample)
            evaluator.add(output, sample)
            t = time.time() - iter_start_time
            if (i + 1) % 100 == 0:
                tqdm.write('Val Step [{}/{}],  Time:{:.3f}'.format(
                    i + 1, test_step, t))

        results = evaluator.evaluate()
        print('Epoch {}/{}'.format(epoch + 1, args.epoch))
        print('lm_dist_all: {:.5f} '.format(results['lm_dist_all']))