imgs = Variable(imgs)
    if torch.cuda.is_available():
        imgs = imgs.cuda()

    rgbs = imgs[:, :3, :, :]
    depths = imgs[:, 3:-1, :, :]
    boudarys = imgs[:, -1:, :, :]

    feature = model_enc(rgbs)
    pred_semseg1, pred_semseg2, pred_depth, pred_boundary = model_dec(feature)

    # if args.use_f2:
    #     outputs += F2(feature)
    #     outputs /= 2

    total_ent += calc_entropy(pred_semseg1).data.cpu().numpy()[0]

    if args.saves_prob:
        # Save probability tensors
        prob_outdir = os.path.join(base_outdir, "prob")
        mkdir_if_not_exist(prob_outdir)
        prob_outfn = os.path.join(prob_outdir,
                                  path.split('/')[-1].replace('png', 'npy'))
        np.save(prob_outfn, pred_semseg1[0].data.cpu().numpy())

    # Save predicted pixel labels(pngs)
    if train_args.add_bg_loss:
        pred = pred_semseg1[0, :args.n_class].data.max(0)[1].cpu()
    else:
        pred = pred_semseg1[0, :args.n_class - 1].data.max(0)[1].cpu()
Beispiel #2
0
    F2.cuda()

total_ent = 0.
for index, (imgs, _, paths) in tqdm(enumerate(target_loader)):
    path = paths[0]

    imgs = Variable(imgs)
    if torch.cuda.is_available():
        imgs = imgs.cuda()

    g_rgb_outdic = G_3ch(imgs[:, :3, :, :])
    g_ir_outdic = G_1ch(imgs[:, 3:, :, :])

    outputs = F1(g_rgb_outdic, g_ir_outdic)

    total_ent += calc_entropy(outputs).data.cpu().numpy()[0]

    if args.saves_prob:
        # Save probability tensors
        prob_outdir = os.path.join(base_outdir, "prob")
        mkdir_if_not_exist(prob_outdir)
        prob_outfn = os.path.join(prob_outdir, path.split('/')[-1].replace('png', 'npy'))
        np.save(prob_outfn, outputs[0].data.cpu().numpy())

    # Save predicted pixel labels(pngs)
    pred = outputs[0, :args.n_class - 1].data.max(0)[1].cpu().numpy()
    img = Image.fromarray(np.uint8(pred))
    img = img.resize(test_img_shape, Image.NEAREST)
    label_outdir = os.path.join(base_outdir, "label")

    mkdir_if_not_exist(label_outdir)

data_list_fn = os.path.join(base_outdir, "data_list.txt")
with open(data_list_fn, "w") as f:
    pass

total_ent = 0.
for index, (imgs, labels, paths) in tqdm(enumerate(target_loader)):
    path = paths[0]
    imgs = Variable(imgs)
    if torch.cuda.is_available():
        imgs = imgs.cuda()

    preds = model(imgs)

    total_ent += calc_entropy(preds).data.cpu().numpy()[0]

    subdir = path.split('/')[-2]

    if train_args.net == "psp":
        preds = preds[0]

    if args.saves_prob:
        # Save probability tensors
        prob_outdir = os.path.join(base_outdir, "prob")
        prob_outdir = add_subdir_if_necessary(prob_outdir, subdir, args.tgt_dataset)
        mkdir_if_not_exist(prob_outdir)
        prob_outfn = os.path.join(prob_outdir, path.split('/')[-1].replace('png', 'npy'))
        np.save(prob_outfn, preds[0].data.cpu().numpy())

    # Save predicted pixel labels(pngs)