Problems loading data for training..new to pytorch,please


#1

from libtiff import TIFF
import torch

class ISBIdata(torch.utils.data.Dataset):
“”“to load data”""
def init(self, dataPath):
super(ISBIdata, self).init()

    data_volume = TIFF.open(dataPath)
    volume = []
    for img in data_volume.iter_images():
        volume.append(img)

    # print(len(volume))
    self.volume = volume

def __getitem__(self, index):
    return self.volume[index]

def __len__(self):
    return len(self.volume)

def main():
train_data = ISBIdata(’/home/mellow/Projects/U-Net/train-volume.tif’)
len(train_data)

if name == ‘main’:
main()

here’s my code,but I got ‘AttributeErro’:
AttributeError: module ‘torch.utils’ has no attribute ‘data’

I can make sure of the installation of pytorch, but I don’t know what’s wrong of my code. Or am using a wrong way of loading data?


#2

Hi,

I am assuming you are dealing with a semantic segmentation task. And I think this thread can really help you!


(Zenghao Liu) #3

‘torch.utils’ is not a module, it’s a package. You can import the class-“Dataset” from the module-“data” in the package-“torch.utils”

from torch.utils.data import Dataset
class ISBIdata(Dataset):

#4

thank u.
I tyied to import ‘torch.utils.data’, as I could call torch.utils.data.Dataset in my class.
problem solved~
xD


#5

thank u for sharing.