火炬无法保存整数类型上的张量

发布于 2025-01-22 23:07:15 字数 413 浏览 0 评论 0原文

我尝试使用火炬调整一些我成功完成的图像。调整大小的图像具有整数类型,当我尝试保存它们时,我会收到以下错误:

RuntimeError: result type Float can't be cast to the desired output type Byte

我使用以下代码调整并保存图像:

image_temp = torchvision.transforms.Resize([200,200], antialias = True)(image_temp)
torchvision.utils.save_image(image_temp , './test.png')

如果将张量或图像转换为float类型,则可以保存它而无需错误。有人知道整数数据类型的问题并保存它是什么问题?

I try to use Torch to resize some images which I did successfully. The resized images have integer type and when I try to save them I get the error below:

RuntimeError: result type Float can't be cast to the desired output type Byte

I used the code below to resize and save images:

image_temp = torchvision.transforms.Resize([200,200], antialias = True)(image_temp)
torchvision.utils.save_image(image_temp , './test.png')

If I convert the tensor or the image to float type, I can save it without error. Does someone know what the problem with integer data type and saving it is?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文