When I use the H5py library to read the .mat dataset, I get the following error. What is wrong? I have not found duplicate function and variable names. Thank you!
tgt_dataset_root = h5py.File('E:\\ADDA\\pytorch-adda-master-lab\\datasets\\lab\\sandy\\mat\\test_target_domain_sandy.mat','r')
data = tgt_dataset_root['data'] # use the key for data here
label = tgt_dataset_root['label'] # use the key for target here
data = numpy.array(data)
label = numpy.array(label)
tgt_dataset = TensorDataset(data, label)
tgt_dataset_root = h5py.File('E:\\ADDA\\pytorch-adda-master-lab\\datasets\\lab\\sandy\\mat\\test_target_domain_sandy.mat','r')
data = tgt_dataset_root['data'] # use the key for data here
label = tgt_dataset_root['label'] # use the key for target here
data = torch.from_numpy(data)
label = torch.from_numpy(label)
tgt_dataset = TensorDataset(data, label)
I’m not sure how your data is stored, as the first error message points to an integer scalar value, while it now seems to be a Dataset class?
Could you print(type(data)) after indexing it from tgt_dataset_root?
Creating the tensors seems to work, while you are now facing an error stating the data and labels have a different length.
I would recommend to check the correspondence between both tensors, as apparently you have either missing labels or missing data.
One approach would be to get both lengths and cut the longer tensor to the size of the shorter one:
min_len = min(data.size(0), target.size(0))
data = data[:min_len]
target = target[:min_len]
However, I would not recommend to just apply this approach, as you are apparently missing some data, so the correspondence between your data and target might be broken.
Thank you very much for your patience and guidance. Now both data and label can be printed separately. If it is used as a data set, do we still need to integrate it like this?