def decode_pt(tensor, mean, std): """Decode a normalized PyTorch tensor back to RGB range""" out = tensor.clone() # Clone to avoid modifying original for t, m, s in zip(out, mean, std): t.mul_(s).add_(m) # Denormalize out = out.mul(255).clamp(0, 255).byte() # Scale back to RGB return out img_decoded = decode_pt(img_transformed, *imagenet_stats) show_image(img_decoded);