attempt_load() got an unexpected keyword argument ‘map_location‘

Posted AI浩

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了attempt_load() got an unexpected keyword argument ‘map_location‘相关的知识,希望对你有一定的参考价值。

文章目录

报错信息

D:\\Users\\wh109\\anaconda3\\python.exe D:\\TrackAndReID\\Yolov5-Deepsort-Fastreid-main\\person_search_reid.py 
Loading faiss with AVX2 support.
Successfully loaded faiss with AVX2 support.
Traceback (most recent call last):
  File "D:\\TrackAndReID\\Yolov5-Deepsort-Fastreid-main\\person_search_reid.py", line 119, in <module>
    yolo_reid = yolo_reid(cfg, args, path=args.video_path)
  File "D:\\TrackAndReID\\Yolov5-Deepsort-Fastreid-main\\person_search_reid.py", line 32, in __init__
    self.person_detect = Person_detect(self.args, self.video_path)
  File "D:\\TrackAndReID\\Yolov5-Deepsort-Fastreid-main\\person_detect_yolov5.py", line 71, in __init__
    self.model = attempt_load(opt.weights, map_location=self.device)  # load FP32 model
TypeError: attempt_load() got an unexpected keyword argument 'map_location'

报错原因

yolov5的版本做了升级了。attempt_load的参数做了调整。如下代码:

def attempt_load(weights, device=None, inplace=True, fuse=True):
    # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a
    from models.yolo import Detect, Model

解决方法

将map_location改为device

 # Load model
 self.model = attempt_load(opt.weights, device=self.device)  # load FP32 model

以上是关于attempt_load() got an unexpected keyword argument ‘map_location‘的主要内容,如果未能解决你的问题,请参考以下文章

PyTorch BERT TypeError: forward() got an unexpected keyword argument 'labels'

MySQL技术专题(3)MySQL报错Got an error reading communication packets问题分析指南

TypeError: index() got an unexpected keyword argument ‘doc_type‘

login() got an unexpected keyword argument 'extra_context'

xgboost : TypeError: predict() got an unexpected keyword argument 'pred_contribs'

TypeError: __init__() got an unexpected keyword argument 'strict'