Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inference on single stereo image pairs #12

Open
kHarshit opened this issue Jan 15, 2020 · 10 comments
Open

Inference on single stereo image pairs #12

kHarshit opened this issue Jan 15, 2020 · 10 comments

Comments

@kHarshit
Copy link

kHarshit commented Jan 15, 2020

Thanks for your work.

I want to perform inference on a single stereo image pair. This repo only contains evaluation on KITTI dataset images.

@CMartinETH
Copy link

I am working on the exact same thing. Right now, I am trying to write a function that stores the inference results in an image. But my results are always blurry (see image below).

Within the module finetune.py, I use the test function and use the output and convert it to a PIL image.
Maybe someone has an explanation for this.
inferenceresult_disp_0

@JF-Lee
Copy link

JF-Lee commented Jun 2, 2020

I am working on the exact same thing. Right now, I am trying to write a function that stores the inference results in an image. But my results are always blurry (see image below).
Within the module finetune.py, I use the test function and use the output and convert it to a PIL image.
Maybe someone has an explanation for this.

Hi,I also encountered this problem,and I use torchvision.utils.save_image to save the tensor, but get blank pic.

@CMartinETH
Copy link

@JF-Lee I found a solution to the issue: I wrote a function that stores the output of the network (keep in mind, you get 4 different images, one image per stage multiplied by the batch size - so say you have a batch size of 8, you get 8 images in one tensor as output, 4 times).
This can be done from within the test function. I hand over the output and x (to know which is the current stage I am saving the image of, or to only save the image of stage 3).

Then the code in the separate file looks something like this:

for i in range(output.size()[0]):
        img_cpu = np.asarray(output.cpu())
        img_save = np.clip(img_cpu[i, :, :], 0, 2**16)
        img_save = (img_save * 256.0).astype(np.uint16)
        name = "some path name"
        cv2.imwrite(name, img_save)

I hope that helps!

@JF-Lee
Copy link

JF-Lee commented Jun 7, 2020 via email

@mileyan
Copy link
Owner

mileyan commented Jun 15, 2020

@CMartinETH, thanks too much for helping solve this issue. I will update this function to the master branch.

@lawo123
Copy link

lawo123 commented Oct 26, 2020

Why is my prediction so bad?
image

@namoamituo
Copy link

@JF-Lee I found a solution to the issue: I wrote a function that stores the output of the network (keep in mind, you get 4 different images, one image per stage multiplied by the batch size - so say you have a batch size of 8, you get 8 images in one tensor as output, 4 times). This can be done from within the test function. I hand over the output and x (to know which is the current stage I am saving the image of, or to only save the image of stage 3).

Then the code in the separate file looks something like this:

for i in range(output.size()[0]):
        img_cpu = np.asarray(output.cpu())
        img_save = np.clip(img_cpu[i, :, :], 0, 2**16)
        img_save = (img_save * 256.0).astype(np.uint16)
        name = "some path name"
        cv2.imwrite(name, img_save)

I hope that helps!

hi,Could you show me some more details? I'm not sure where the above code should be placed in the test function

@leizhenyu-lzy
Copy link

Why is my prediction so bad? image

got similar result, it looks a little blurred

@leizhenyu-lzy
Copy link

@JF-Lee I found a solution to the issue: I wrote a function that stores the output of the network (keep in mind, you get 4 different images, one image per stage multiplied by the batch size - so say you have a batch size of 8, you get 8 images in one tensor as output, 4 times). This can be done from within the test function. I hand over the output and x (to know which is the current stage I am saving the image of, or to only save the image of stage 3).
Then the code in the separate file looks something like this:

for i in range(output.size()[0]):
        img_cpu = np.asarray(output.cpu())
        img_save = np.clip(img_cpu[i, :, :], 0, 2**16)
        img_save = (img_save * 256.0).astype(np.uint16)
        name = "some path name"
        cv2.imwrite(name, img_save)

I hope that helps!

hi,Could you show me some more details? I'm not sure where the above code should be placed in the test function

you can put it in the test() function in the file finetune.py

def test(dataloader, model, log):

    stages = 3 + args.with_spn
    D1s = [AverageMeter() for _ in range(stages)]
    length_loader = len(dataloader)

    model.eval()

    for batch_idx, (imgL, imgR, disp_L) in enumerate(dataloader):
        imgL = imgL.float().cuda()
        imgR = imgR.float().cuda()
        disp_L = disp_L.float().cuda()

        with torch.no_grad():
            outputs = model(imgL, imgR)
            print(f"[test] : len(outputs)={len(outputs)}")  # 4
            for x in range(stages):
                output = torch.squeeze(outputs[x], 1)
                print(f"[test] : output.shape={output.shape}")  # torch.Size([8, 1, 368, 1232])
                for i in range(output.size()[0]):  # 8
                    img_cpu = np.asarray(output.cpu())
                    img_save = np.clip(img_cpu[i, :, :], 0, 2**16)
                    img_save = (img_save * 256.0).astype(np.uint16)
                    name = "/home/lzy/Project/DepthEstimateBasedOnDeepLearning/AnyNet/results/test/"+str(x)+"_"+str(i)+".png"
                    cv2.imwrite(name, img_save)
                D1s[x].update(error_estimating(output, disp_L).item())

@Xi-Gong
Copy link

Xi-Gong commented Jan 21, 2024

Why is my prediction so bad? image

Compare to the paper result, looks like this is actually the best result AnyNet can get.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants