Hi
I’m new to pytorch…
when I build small model to predict hand sign is (0,1,2,3,4,5) I found out that grad for layers is 0 so model didn’t learn any thing… I don’t know why, I tried to classify FashionMNIST before that one and it work well, so I think problem could be In load H5 file to pytorch so that is my code for this part
keys = list(train_file.keys())
labels = list(train_file[keys[0]])
train_x = np.divide(np.array(train_file[keys[1]],dtype=np.float32),255)
train_y = np.array(train_file[keys[2]])
#-----------#
keys = list(test_file.keys())
test_labels=list(test_file[keys[0]])
test_x = np.divide(np.array(test_file[keys[1]],dtype=np.float32),255)
test_y = np.array(test_file[keys[2]])
#load data into pytorch loader
train_y = np.reshape(train_y,(1080,1)) # pytorch expext labels with shape (N,1) not (N,)
train_x = np.reshape(train_x,(1080,3,64,64)) # pytorch expect channels first (3,w,h) not (w,h,3)
test_y = np.reshape(test_y,(120,1)) # pytorch expext labels with shape (N,1) not (N,)
test_x = np.reshape(test_x,(120,3,64,64)) # pytorch expect channels first (3,w,h) not (w,h,3)
# load data into data loader
train_x = torch.stack([torch.Tensor(i) for i in train_x])
train_y = torch.stack([torch.Tensor(i) for i in train_y])
test_x = torch.stack([torch.Tensor(i) for i in test_x])
test_y = torch.stack([torch.Tensor(i) for i in test_y])
train_dataset = torch.utils.data.TensorDataset(train_x,train_y)
test_dataset = torch.utils.data.TensorDataset(test_x,test_y)
trainloader = DataLoader(train_dataset,batch_size=32,shuffle=True)
testloader = DataLoader(test_dataset,batch_size=32,shuffle=True)