Skip to content

why don't we turn this "f"Pred: {target_image_pred_label} ..." into CPU? #1005

Answered by 0xm4ze
garylau1 asked this question in Q&A
Discussion options

You must be logged in to vote

Example Code:

Here's an improved version of your snippet with explanations:

import matplotlib.pyplot as plt

# Assume `target_image` is a tensor of shape (C, H, W)
plt.imshow(target_image.squeeze().permute(1, 2, 0))  # Make sure the image is in the right format for Matplotlib

# Convert `target_image_pred_label` to CPU if it's a tensor
if isinstance(target_image_pred_label, torch.Tensor):
    target_image_pred_label = target_image_pred_label.cpu().item()

# Format the title based on whether class names are available
if class_names:
    title = f"Pred: {class_names[target_image_pred_label]} | Prob: {target_image_pred_probs.max().cpu():.3f}"
else:
    title = f"Pred: {target_image_pred_label}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by garylau1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants