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 visualize prediction results #5

Open
ChenccLOL opened this issue Feb 1, 2024 · 2 comments
Open

How to visualize prediction results #5

ChenccLOL opened this issue Feb 1, 2024 · 2 comments

Comments

@ChenccLOL
Copy link

ChenccLOL commented Feb 1, 2024

Hello, thanks for your great work.
I have used your code to complete the training and testing process. In the test results, I found that only the predicted mask results are stored. Could you please advise me how to convert the mask results into vector results in the ego vehicle coordinate system? Can you provide the corresponding visualization code? If possible, I would greatly appreciate it.

@RanRan814
Copy link

Hi! Have you ever visualized it? Thx

@GQXmmm
Copy link

GQXmmm commented Aug 2, 2024

Here is a simple code for visualization, hope it helps

import os
import numpy as np
import matplotlib.pyplot as plt
import tqdm
gt_paths = 'Path/to/your/data/nuscenes/customer/pivot-bezier/'
pred_paths = 'Path/to/your/evaluation/results/'
pred_npz_files = os.listdir(pred_paths)

def filter_and_denormalize(points, width, height):
    filtered_points = points[~np.all(points == 0, axis=1)]
    denormalized_points = filtered_points * [width, height]
    return denormalized_points

for f in tqdm.tqdm(pred_npz_files):
    prediction_data = np.load(pred_paths + f, allow_pickle=True)
    prediction_data = prediction_data['dt_res'].item()
    label_data  = np.load(gt_paths + f, allow_pickle=True)
    label_data = label_data['pivot_pts'].item()
    prediction_label_colors = {1: 'green', 2: 'gray', 3: 'red'}
    label_colors = {0: 'green', 1: 'gray', 2: 'red'}

    fig, axes = plt.subplots(1, 2, figsize=(8, 8))  

    ax = axes[0]
    points = prediction_data['map']
    labels = prediction_data['pred_label']
    for i, (pts, label) in enumerate(zip(points, labels)):
        if pts is not None:
            pts = np.array(pts)
            x, y = pts[:, 0], pts[:, 1]
            color = prediction_label_colors.get(label, 'blue')
            ax.plot(y, x, color=color)
            ax.scatter(y, x, color=color, s=10)

    ax.axis('off')
    ax.set_title('Predict', fontsize=14, color='blue')

    ax = axes[1]
    for label, arrays in label_data.items():
        for pts in arrays:
            if len(pts) > 0:
                pts = filter_and_denormalize(pts, 400, 200)
                if not np.all(pts == 0):  
                    x, y = pts[:, 0], pts[:, 1]
                    color = label_colors.get(label, 'blue')
                    ax.plot(y, x, color=color)
                    ax.scatter(y, x, color=color, s=10)

    ax.axis('off')
    ax.set_title('GroundTruth', fontsize=14, color='gray')


    plt.tight_layout()

    name = f.split('.')[0]
    plt.savefig(f'vis/{name}.png', bbox_inches='tight')
    plt.close()

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

3 participants