成功解决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
(0)

相关推荐