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

How to load depth data? #122

Open
luigilella98 opened this issue Aug 12, 2024 · 2 comments
Open

How to load depth data? #122

luigilella98 opened this issue Aug 12, 2024 · 2 comments

Comments

@luigilella98
Copy link

Thank you for your work and the code. I wanted to ask you how to load depth into the model as there is no specific "load_and_transform_depth_data" method. Should I use "load_and _transform_vision_data"?

@Kerio99
Copy link

Kerio99 commented Sep 22, 2024

Hi, I have the same question. Have you find the answer?

@luigilella98
Copy link
Author

luigilella98 commented Oct 10, 2024

@Kerio99 I created a function from scratch, but it would be better if they provided it.


def load_and_transform_depth_data(depth_paths, device):
    if depth_paths is None:
        return None
    device = torch.device(device)

    depth_outputs = []
    for depth_path in depth_paths:
        data_transform = transforms.Compose(
            [
                transforms.Resize(
                    224, interpolation=transforms.InterpolationMode.BICUBIC
                ),
                transforms.CenterCrop(224),
                transforms.ToTensor(),
            ]
        )
        with open(depth_path, "rb") as fopen:
            image = Image.open(fopen).convert("L")

        
        image = np.array(image, dtype=np.float32) / 255.0
        disparity = Image.fromarray(image)
        #plt.imshow(image, cmap='Spectral')
        #plt.show()
        #mask = image > 0 
        #image = image - image[mask].min()
        #disparity = 1.0 / image
        #disparity = (disparity - disparity[mask].min())/(disparity[mask].max() - disparity[mask].min())
        #disparity[mask == 0] = 0
        #disparity = np.clip(disparity, 0, 1)
        plt.imshow(image, cmap='Spectral')
        plt.show()
        #disparity = Image.fromarray(disparity)

        disparity = data_transform(disparity).to(device)

        depth_outputs.append(disparity)

    return torch.stack(depth_outputs, dim=0)

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

2 participants