# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load in 

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
from PIL import Image
import torch
from numpy import genfromtxt

from torch.utils.data.dataset import Dataset
# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
'''
dir_filenames=[]
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        path=os.path.join(dirname, filename)
        print(path)
        dir_filenames.append(path)
# Any results you write to the current directory are saved as output.
'''



class dataset(Dataset):
    """Face Landmarks dataset."""

    def __init__(self,  root_dir):
        
        #root_dir='E:\\IPSL\\Remote_Sensing\\Graduation Reserach\\Data\\High Res\\Cropped\\Train'
        self.root_dir=root_dir
        self.label = genfromtxt(self.root_dir+'train_labels.csv', delimiter=',')
        self.TotalImg = self.label.shape[0]
      

    def __len__(self):
        return self.TotalImg

    def __getitem__(self, idx):
        label=self.label[idx,1]
        path_img=self.label[idx,0]
        img=Image.open(self.root_dir+'train/'+path_img+'.tif')
      
        #return timg.type(torch.cuda.FloatTensor),tGT.type(torch.cuda.FloatTensor),tant.type(torch.cuda.FloatTensor)
        return  img,label

if __name__ == '__main__':
    path_train='/kaggle/input/histopathologic-cancer-detection/'
    path_test='/kaggle/input/histopathologic-cancer-detection/test/'
    Dataset_train=dataset(path_train)
    train_loader = torch.utils.data.DataLoader(dataset=Dataset_train,
                                                    batch_size=4,
                                                    shuffle=True)
    
    
    
    
    
    
    
    
    