Ejemplo n.º 1
0
        imgs_t.save(os.path.join(args.gen_img_dir, filename))

    if i_iter % num_calmIoU == 0:
        enc_shared.eval()
        print('evaluating models ...')
        for i_val, (images_val, labels_val) in tqdm(enumerate(val_loader)):
            images_val = Variable(images_val.cuda(), volatile=True)
            labels_val = Variable(labels_val, volatile=True)

            _, _, pred, _ = enc_shared(images_val)
            pred = upsample_512(pred)
            pred = pred.data.max(1)[1].cpu().numpy()
            gt = labels_val.data.cpu().numpy()
            cty_running_metrics.update(gt, pred)

        cty_score, cty_class_iou = cty_running_metrics.get_scores()

        for k, v in cty_score.items():
            print(k, v)

        cty_running_metrics.reset()
        City_tmp.append(cty_score['Mean IoU : \t'])
        epoch_tmp.append(i_iter)
        if i_iter % 10000 == 0 and i_iter != 0:
            save_models(model_dict, './weight_' + str(i_iter))

        if cty_score['Mean IoU : \t'] > best_iou:
            best_iter = i_iter
            best_iou = cty_score['Mean IoU : \t']
            save_models(model_dict, './weight/')
        enc_shared.eval()
        print('evaluating models ...')
        with torch.no_grad():
            for i_val, (images_val, labels_val) in tqdm(enumerate(val_loader)):
                images_val = Variable(images_val.cuda())
                labels_val = Variable(labels_val)

                _, aug_pred, pred, _ = enc_shared(images_val)
                #pred = upsample_512(pred)
                pred = 0.5 * aug_pred + pred
                pred = upsample_540(pred)
                pred = pred.data.max(1)[1].cpu().numpy()
                gt = labels_val.data.cpu().numpy()
                cty_running_metrics.update(gt, pred)

        cty_score, cty_class_iou = cty_running_metrics.get_scores()

        for k, v in cty_score.items():
            print(k, v)

        cty_running_metrics.reset()
        City_tmp.append(cty_score['Mean IoU : \t'])
        epoch_tmp.append(i_iter)
        if i_iter % 3000 == 0 and i_iter != 0:
            save_models(model_dict, save_model_path + 'weight_' + str(i_iter))

        if cty_score['Mean IoU : \t'] > best_iou:
            best_iter = i_iter
            best_iou = cty_score['Mean IoU : \t']
            save_models(model_dict, save_model_path + 'weight_best/')