size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([9

news/2024/9/21 11:05:03

1. 报错 RuntimeError: Error(s) in loading state_dict for FasterRCNN: size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([91, 1024]) from checkpoint, the shape in current model is torch.Size([80, 1024]).

pytorch 1.11.0
torchvision 0.12.0

Traceback (most recent call last):File "C:\Users\Administrator\.IntelliJIdea2017.2\config\plugins\python\helpers\pydev\pydevd.py", line 1596, in <module>globals = debugger.run(setup['file'], None, None, is_module)File "C:\Users\Administrator\.IntelliJIdea2017.2\config\plugins\python\helpers\pydev\pydevd.py", line 1023, in runpydev_imports.execfile(file, globals, locals)  # execute the scriptFile "C:\Users\Administrator\.IntelliJIdea2017.2\config\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfileexec(compile(contents+"\n", file, 'exec'), glob, loc)File "E:/mat/py-demo-22/p220625/detect_image.py", line 60, in <module>num_classes=len(CLASSES), pretrained_backbone=True).to(DEVICE)File "D:\python374\lib\site-packages\torchvision\models\detection\faster_rcnn.py", line 399, in fasterrcnn_resnet50_fpnmodel.load_state_dict(state_dict)File "D:\python374\lib\site-packages\torch\nn\modules\module.py", line 1498, in load_state_dictself.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for FasterRCNN:size mismatch for roi_heads.box_predictor.cls_score.weight: copying a param with shape torch.Size([91, 1024]) from checkpoint, the shape in current model is torch.Size([80, 1024]).size mismatch for roi_heads.box_predictor.cls_score.bias: copying a param with shape torch.Size([91]) from checkpoint, the shape in current model is torch.Size([80]).size mismatch for roi_heads.box_predictor.bbox_pred.weight: copying a param with shape torch.Size([364, 1024]) from checkpoint, the shape in current model is torch.Size([320, 1024]).size mismatch for roi_heads.box_predictor.bbox_pred.bias: copying a param with shape torch.Size([364]) from checkpoint, the shape in current model is torch.Size([320]).

解决

  • model.load_state_dict(torch.load(“./model.pth”), False) 未解决
  • 调整pytorch版本:pip install pytorch==1.7.1 未解决
    报错
Traceback (most recent call last):File "C:\Users\Administrator\.IntelliJIdea2017.2\config\plugins\python\helpers\pydev\pydevd.py", line 1596, in <module>globals = debugger.run(setup['file'], None, None, is_module)File "C:\Users\Administrator\.IntelliJIdea2017.2\config\plugins\python\helpers\pydev\pydevd.py", line 1023, in runpydev_imports.execfile(file, globals, locals)  # execute the scriptFile "C:\Users\Administrator\.IntelliJIdea2017.2\config\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfileexec(compile(contents+"\n", file, 'exec'), glob, loc)File "E:/mat/py-demo-22/p220625/detect_image.py", line 50, in <module>"frcnn-mobilenet": detection.fasterrcnn_mobilenet_v3_large_320_fpn,
AttributeError: module 'torchvision.models.detection' has no attribute 'fasterrcnn_mobilenet_v3_large_320_fpn'
  • 加载重新保存

解决办法1: https://github.com/facebookresearch/maskrcnn-benchmark/issues/430在这里插入图片描述

解决办法2:

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pgtn.cn/news/17635.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

数据结构--队列

文章目录队列队列存储结构特点队列的相关概念&#xff1a;队列的操作&#xff1a;队列的分类&#xff1a;数组实现链表实现队列 队列存储结构特点 &#xff08;1&#xff09;队列中的数据元素遵循“先进先出”的原则 &#xff08;2&#xff09;在队尾添加元素&#xff0c;在队…

文件服务器共享目录设置(二)

三、 设置磁盘配额及文件屏蔽 为了防止用户无限制的上传文件&#xff0c;或上传病毒木马等文件&#xff0c;还需要进一步加强安全设置。用磁盘配额来管理用户的文件夹空间&#xff0c;用文件屏蔽来阻止用户上传有风险的文件。 在win2003中&#xff0c;磁盘配额只能…

机器学习--局部加权线性回归

文章目录局部加权线性回归预测鲍鱼年龄局部加权线性回归 具体理论见上次笔记《线性回归》 预测鲍鱼年龄 import numpy as npclass LocalWeightedLinearRegression(object):def __init__(self,train_data,train_result):""":param train_data: 输入训练数据:p…

Standup Timer的MVC模式及项目结构分析

前言 学习android一段时间了&#xff0c;为了进一步了解android的应用是如何设计开发的&#xff0c;决定详细研究几个开源的android应用。从一些开源应用中吸收点东西&#xff0c;一边进行量的积累&#xff0c;一边探索android的学习研究方向。这里我首先选择了jwood的Standup …

JAVA IDEA切换新机器配置环境一览

1. 装jdk 自动配置环境变量 2. idea配置git git config --global user.name "xxx" git config --global user.email "xxxxx.com"3. idea配置maven 解压apache-maven-xxx.jar&#xff0c;配置环境变量MAVEN_HOME,PATH增加%MAVEN_HOME%\bin settings.xml…

数据结构--串

文章目录串串的基本概念串的基本操作代码实现串 串的基本概念 长度&#xff1a;串中字符的个数&#xff0c;称为串的长度。 空串&#xff1a;长度为零的字符串称为空串。 空格串&#xff1a;由一个或多个连续空格组成的串称为空格串。 串相等&#xff1a;两个串相等&#xff…

5,ORM组件XCode(动手)

本篇才真正是XCode教程第一篇。《速览》是为了以最简洁的语言最短小的篇幅去吸引开发者&#xff1b;《简介》则是对XCode组件和XCode开发模式的一个整体介绍&#xff0c;让开发者从宏观的角度去理解XCode&#xff1b;《共舞》把XCode提到了一个新的高度&#xff0c;让开发者感受…

使用Python,OpenCV追踪对象的轨迹,来确定其移动方向

这篇博客是上一篇博客: 使用Python,OpenCV转换颜色空间,追踪对象的轨迹的扩展。将使用Python,OpenCV追踪对象的轨迹,来确定其移动方向; 虽然球跟踪展示了目标检测和跟踪的基础知识,但无法计算球的实际移动方向。通过在两个单独的帧中简单地计算对象(x,y)坐标之间的增…