Giter Site home page Giter Site logo

为什么会出现这个错误RuntimeError: Expected object of scalar type float but got scalar type double for argument 'other' about retinanet-pytorch HOT 14 OPEN

yatenglg avatar yatenglg commented on July 22, 2024
为什么会出现这个错误RuntimeError: Expected object of scalar type float but got scalar type double for argument 'other'

from retinanet-pytorch.

Comments (14)

yatengLG avatar yatengLG commented on July 22, 2024 2

关于这个报错,统一回复

原因是

  • 模型与数据类型不一致,
  • " Expected object of scalar type float but got scalar type double for argument 'other' ",应该输入的是float类型,但是输入的参数是double类型的。

具体查看方法是

  • for param in net.parameters(): print(param.dtype)
    打印你模型权重的dtype类型(模型是没有dtype属性的,模型的数值类型具体来讲是模型权重参数的数值类型)。`
  • for image, label in dataloader : print(image.dtype, label,dtype)
    查看输入数据以及标签的数值类型。

解决方法:

  1. 将模型调整为双精度 net.double()
  2. 调整为单精度 net.float()
  3. 数据同操作

from retinanet-pytorch.

dfy888 avatar dfy888 commented on July 22, 2024 1

终于跑起来了 我自己的数据集
问题在这:

print("这里的错啊:", gt_boxes.dtype, gt_boxes.size())

# print("这里的错啊:", corner_form_priors.dtype, corner_form_priors.size())
# 所以我经常遇到'float64' * 'float32' 报错
corner_form_priors = corner_form_priors.float()  # 'float32' 我加的这句

ious = iou_of(gt_boxes.unsqueeze(0), corner_form_priors.unsqueeze(1))

希望可以帮到跟我一样的朋友 再次感谢作者的注释

from retinanet-pytorch.

lmcltj avatar lmcltj commented on July 22, 2024

我也出现了

from retinanet-pytorch.

yatengLG avatar yatengLG commented on July 22, 2024

因为,数据是双精度的啊,而需要的是单精度的。
如果你需要模型是双精度的, 用 model = model.double() 改成双精度就行。
或者 把你数据 data=data.float() 改成单精度的

from retinanet-pytorch.

taochx avatar taochx commented on July 22, 2024

请问这个错误具体应该怎么改呢?我尝试改了几个地方的,但是还是有错误

from retinanet-pytorch.

yatengLG avatar yatengLG commented on July 22, 2024

@taochongxin 模型权重和数据均是有精度的。 一般来讲,自定义的模型,如果没有特别指定,一般都是单精度的,也就是float, 主要问题应该是出在你的数据上,你把你的数据,的dtype打印出来,看看是什么。 然后把模型和数据的 dtype改成一样的就可以了。 这个问题也一般会出现在损失函数中,反正涉及到权重的地方都会有精度问题。你统一了就好了

from retinanet-pytorch.

taochx avatar taochx commented on July 22, 2024

@yatengLG 多谢回复,我使用的数据集也是voc2007,我再尝试改一下,谢谢

from retinanet-pytorch.

lmcltj avatar lmcltj commented on July 22, 2024

我都改成双精度了,可以跑通

from retinanet-pytorch.

dfy888 avatar dfy888 commented on July 22, 2024

我也遇到这个问题了

from retinanet-pytorch.

yatengLG avatar yatengLG commented on July 22, 2024

@dfy888 精度问题,模型精度和数据精度不一致。

from retinanet-pytorch.

dfy888 avatar dfy888 commented on July 22, 2024

型精度和数据精度不一致

AttributeError: 'DataLoader' object has no attribute 'dtype'
到底改哪里啊? 模型 数据都没有 dtype属性? 感谢作者大大的回复

from retinanet-pytorch.

yatengLG avatar yatengLG commented on July 22, 2024

@dfy888

for param in net.parameters(): print(param.dtype)
查看模型参数的 数值精度

然后你数据也是同样的,只要是tensor肯定有dtype的

from retinanet-pytorch.

yatengLG avatar yatengLG commented on July 22, 2024

@dfy888 dataloader 是个 数据加载器的类,不是你的输入数据。
你训练的时候不是,有个 for image, label in dataloader: 么 , 这里拿出来的才是数据啊

from retinanet-pytorch.

dfy888 avatar dfy888 commented on July 22, 2024

@dfy888 dataloader 是个 数据加载器的类,不是你的输入数据。
你训练的时候不是,有个 for image, label in dataloader: 么 , 这里拿出来的才是数据啊

我到不了那里 刚刚定位了一下是这里的问题:
print("传进来的类型torch:gt_boxes={};gt_labels={}".format(gt_boxes.dtype, gt_labels.dtype))
boxes, labels = assign_priors(gt_boxes, gt_labels,
self.corner_form_priors,
self.iou_threshold)

from retinanet-pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.