I think i have problem on how to create label in case of dataset. I followed the  link https://www.kaggle.com/mratsim/starting-kit-for-pytorch-deep-learning 120 .
I have 5529 labels(string concepts) in total. Just to check , i converted them to numpy array.
Each of my image contains variable number of labels as you can see my training concepts.

Screenshot_2019-07-04 validationsettrasnferlearnkaggle.png1299×639 68.8 KB

I used multi binarizer to convert my labels into my multi hot encoded tensor.
One of the link mentioned used the total number of classes within the multilabel binarizer , to convert the labels, whereas, most of the links don’t do so.
When I run the following code,
class myCustomDataset(Dataset):
“”“my dataset.”""
def __init__(self, csv_file, root_dir,img_ext,transform=None):
    """
    Args:
        csv_file (string): Path to the csv file with annotations.
        root_dir (string): Directory with all the images.
        transform (callable, optional): Optional transform to be applied
            on a sample.
    """
    #.iloc[:,0]=[[0]]
     #
    tmp_df = pd.read_csv(csv_file,sep=';',header=None)
    assert tmp_df.iloc[:,0].apply(lambda x: os.path.isfile(root_dir + x + img_ext)).all(), \

“Some images referenced in the CSV file were not found”
#global r
    self.mlb = MultiLabelBinarizer()
    
    self.root_dir = root_dir
    self.img_ext = img_ext
    self.transform = transform

    self.X_train = tmp_df.iloc[:,0]
    self.y_train = self.mlb.fit_transform(tmp_df.iloc[:,1].str.split(',')).astype(np.float32)
    
    #'float'
    
def __len__(self):
    return len(self.X_train.index)

def __getitem__(self, index):
    
    img = Image.open(self.root_dir + self.X_train[index] + self.img_ext)
    img = img.convert('RGB')
    if self.transform is not None:
        img = self.transform(img)
    
    label =torch.from_numpy(self.y_train[index])
    #from_numpy(self.y[index])
    return img, label

After this i print the following code,I made a   custom dataset and then dataloader accordingly:

first.jpg854×403 43.3 KB


second.jpg707×441 46.6 KB

I would like to ask If i should provide my numpy array ‘r’ while writing
self.mlb = MultiLabelBinarizer()
inside the braces or not.
I don’t know if i am going good or not.
My other question is, why is  torch size 3233 in the later case.
When i put  ‘r’ inside multilabel binarizer, my  label size in case of trainloader and validloader changes from 5216 and 3233 to 5528 for both and my torch size changes from 3323 to 5528.
I am unable to understand which one is correct and how should i proceed ahead.
Please provide me your suggestions.