NameError: name ‘Optional‘ is not defined

D:\programfiles\miniconda\envs\py38torch_gpu\python.exe G:/yolov5/yolov5-6.1/train.py --data ../air-filter/data.yaml --cfg models/yolov5s-tph2.yaml --batch-size 1
Traceback (most recent call last):
  File "G:/yolov5/yolov5-6.1/train.py", line 44, in <module>
    import val  # for end-of-epoch mAP
  File "G:\yolov5\yolov5-6.1\val.py", line 38, in <module>
    from models.common import DetectMultiBackend
  File "G:\yolov5\yolov5-6.1\models\common.py", line 2511, in <module>
    class WindowAttention(nn.Module):
  File "G:\yolov5\yolov5-6.1\models\common.py", line 2558, in WindowAttention
    def forward(self, x, mask: Optional[torch.Tensor] = None):

NameError: name 'Optional' is not defined

 加入:

from typing import Optional

D:\programfiles\miniconda\envs\py38torch_gpu\python.exe G:/yolov5/yolov5-6.1/train.py --data ../air-filter/data.yaml --cfg models/yolov5s-tph2.yaml --batch-size 1
train: weights=yolov5s.pt, cfg=models/yolov5s-tph2.yaml, data=../air-filter/data.yaml, hyp=data\hyps\hyp.scratch-low.yaml, epochs=100, batch_size=1, imgsz=640, rect=False, resume=False, nosave=False, noval=False, noautoanchor=False, evolve=None, bucket=, cache=None, image_weights=False, device=, multi_scale=False, single_cls=False, optimizer=SGD, sync_bn=False, workers=0, project=runs\train, name=exp, exist_ok=False, quad=False, cos_lr=False, label_smoothing=0.0, patience=100, freeze=[0], save_period=-1, local_rank=-1, entity=None, upload_dataset=False, bbox_interval=-1, artifact_alias=latest
github: skipping check (not a git repository), for updates see https://github.com/ultralytics/yolov5
YOLOv5  2022-2-22 torch 1.9.0+cu111 CUDA:0 (GeForce RTX 2080 Super with Max-Q Design, 8192MiB)

Weights & Biases: run 'pip install wandb' to automatically track and visualize YOLOv5  runs (RECOMMENDED)
hyperparameters: lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0
TensorBoard: Start with 'tensorboard --logdir runs\train', view at http://localhost:6006/
2022-10-24 22:39:36.244864: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2022-10-24 22:39:36.244967: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

                 from  n    params  module                                  arguments                     
  0                -1  1      3520  models.common.Conv                      [3, 32, 6, 2, 2]              
  1                -1  1     18560  models.common.Conv                      [32, 64, 3, 2]                
  2                -1  1     18816  models.common.C3                        [64, 64, 1]                   
  3                -1  1     73984  models.common.Conv                      [64, 128, 3, 2]               
  4                -1  2    115712  models.common.C3                        [128, 128, 2]                 
  5                -1  1    295424  models.common.Conv                      [128, 256, 3, 2]              
  6                -1  3    625152  models.common.C3                        [256, 256, 3]                 
  7                -1  1   1180672  models.common.Conv                      [256, 512, 3, 2]              
  8                -1  1   1182720  models.common.C3                        [512, 512, 1]                 
  9                -1  1    656896  models.common.SPPF                      [512, 512, 5]                 
 10                -1  1    131584  models.common.Conv                      [512, 256, 1, 1]              
 11                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 12           [-1, 6]  1         0  models.common.Concat                    [1]                           
 13                -1  1    361984  models.common.C3                        [512, 256, 1, False]          
 14                -1  1     33024  models.common.Conv                      [256, 128, 1, 1]              
 15                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 16           [-1, 4]  1         0  models.common.Concat                    [1]                           
 17                -1  1     90880  models.common.C3                        [256, 128, 1, False]          
 18                -1  1      8320  models.common.Conv                      [128, 64, 1, 1]               
 19                -1  1         0  torch.nn.modules.upsampling.Upsample    [None, 2, 'nearest']          
 20           [-1, 2]  1         0  models.common.Concat                    [1]                           
Traceback (most recent call last):
  File "G:/yolov5/yolov5-6.1/train.py", line 653, in <module>
    main(opt)
  File "G:/yolov5/yolov5-6.1/train.py", line 546, in main
    train(opt.hyp, opt, device, callbacks)
  File "G:/yolov5/yolov5-6.1/train.py", line 131, in train
    model = Model(cfg or ckpt['model'].yaml, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device)  # create
  File "G:\yolov5\yolov5-6.1\models\yolo.py", line 107, in __init__
    self.model, self.save = parse_model(deepcopy(self.yaml), ch=[ch])  # model, savelist
  File "G:\yolov5\yolov5-6.1\models\yolo.py", line 399, in parse_model
    m_ = nn.Sequential(*(m(*args) for _ in range(n))) if n > 1 else m(*args)  # module
  File "G:\yolov5\yolov5-6.1\models\common.py", line 2725, in __init__
    self.m = SwinTransformerBlock(c_, c_, c_//32, n)
  File "G:\yolov5\yolov5-6.1\models\common.py", line 2710, in __init__
    self.tr = nn.Sequential(*(SwinTransformerLayer(c2, num_heads=num_heads, window_size=window_size,
  File "G:\yolov5\yolov5-6.1\models\common.py", line 2710, in <genexpr>
    self.tr = nn.Sequential(*(SwinTransformerLayer(c2, num_heads=num_heads, window_size=window_size,
  File "G:\yolov5\yolov5-6.1\models\common.py", line 2620, in __init__
    self.attn = WindowAttention(
  File "G:\yolov5\yolov5-6.1\models\common.py", line 2540, in __init__
    coords = torch.stack(torch.meshgrid([coords_h, coords_w], indexing="ij"))  # [2, Mh, Mw]

TypeError: meshgrid() got an unexpected keyword argument 'indexing'

Process finished with exit code 1

找到:

coords = torch.stack(torch.meshgrid([coords_h, coords_w], indexing="ij"))  # [2, Mh, Mw]

改为:

coords = torch.stack(torch.meshgrid([coords_h, coords_w]))  # [2, Mh, Mw]

YOLO系列是基于深度学习的端到端实时目标检测方法。 PyTorch版的YOLOv5轻量而高性能,更加灵活和易用,当前非常流行。 本课程将手把手地教大家使用labelImg标注和使用YOLOv5训练自己的数据集。课程实战分为两个项目:单目标检测(足球目标检测)和多目标检测(足球和梅西同时检测)。  本课程的YOLOv5使用ultralytics/yolov5,在Windows和Ubuntu系统上分别做项目演示。包括:安装YOLOv5、标注自己的数据集、准备自己的数据集(自动划分训练集和验证集)、修改配置文件、使用wandb训练可视化工具、训练自己的数据集、测试训练出的网络模型和性能统计。 除本课程《YOLOv5实战训练自己的数据集(Windows和Ubuntu演示)》外,本人推出了有关YOLOv5目标检测的系列课程。请持续关注该系列的其它视频课程,包括:《YOLOv5(PyTorch)目标检测:原理与源码解析》课程链接:https://edu.csdn.net/course/detail/31428《YOLOv5目标检测实战:Flask Web部署》课程链接:https://edu.csdn.net/course/detail/31087《YOLOv5(PyTorch)目标检测实战:TensorRT加速部署》课程链接:https://edu.csdn.net/course/detail/32303《YOLOv5目标检测实战:Jetson Nano部署》课程链接:https://edu.csdn.net/course/detail/32451《YOLOv5+DeepSORT多目标跟踪与计数精讲》课程链接:https://edu.csdn.net/course/detail/32669《YOLOv5实战口罩佩戴检测》课程链接:https://edu.csdn.net/course/detail/32744《YOLOv5实战中国交通标志识别》课程链接:https://edu.csdn.net/course/detail/35209 《YOLOv5实战垃圾分类目标检测》课程链接:https://edu.csdn.net/course/detail/35284  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

长沙有肥鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值