完美解决 AttributeError: module ‘torch.utils’ has no attribute ‘data’
文章目录
- 报错问题
- 解决方法
- 声明
报错问题
之前在工作中遇到过这个坑,记录一下问题以及解决方法,不一定针对所有情况都能用,但是可以供大家参考。
问题描述如下:
AttributeError: module ‘torch.utils’ has no attribute ‘data’
属性错误:模块的’torch.utils’没有属性’data’
解决方法
只需在顶行添加此代码即可!
import torch.utils.data # 新添加代码
将
import logging
import numpy as np
import torch
from . import ava_helper as ava_helper
from . import cv2_transform as cv2_transform
from . import transform as transform
from . import utils as utils
from .build import DATASET_REGISTRY
logger = logging.getLogger(__name__)
@DATASET_REGISTRY.register()
class Ava(torch.utils.data.Dataset):
"""
AVA Dataset
"""
def __init__(self, cfg, split):
self.cfg = cfg
self._split = split
更改为
import logging
import numpy as np
import torch
import torch.utils.data # 新添加代码
from . import ava_helper as ava_helper
from . import cv2_transform as cv2_transform
from . import transform as transform
from . import utils as utils
from .build import DATASET_REGISTRY
logger = logging.getLogger(__name__)
@DATASET_REGISTRY.register()
class Ava(torch.utils.data.Dataset):
"""
AVA Dataset
"""
def __init__(self, cfg, split):
self.cfg = cfg
self._split = split
声明
解决方法参考网络,如有侵权联系我删除