Hi,
I implemented rnn model, but it seems that it is not learning from data.
Initially my training data is unbalanced -1871 of zeroes and 229 of ones and at each epoch I get results varying from 63%-65%. When I print out predicted values I see that they are always zeroes.
Can you please help me to find any solution to this problem? I tried to experiment with WeightedRandomSampler,RandomSampler and  varying weights in CrossEntropyLoss criterion. Each time I end up with all predictions equal to zero. Below is my code:
batch_size = 100
train_data=myDatasetTrain()
test_data =myDatasetTest()
num_train = len(train_data)
indices = list(range(num_train))
split=int(num_train*7/10)
train_idx, valid_idx = indices[:split], indices[split:]
train_sampler = SequentialSampler(train_idx)
valid_sampler = SequentialSampler(valid_idx)
train_loader = DataLoader(dataset=train_data,sampler=train_sampler, batch_size=batch_size, drop_last=True)
valid_loader = DataLoader(dataset=train_data,sampler=valid_sampler, batch_size=batch_size, drop_last=True)
test_loader = DataLoader(dataset=test_data,shuffle=True, batch_size=batch_size, drop_last=True)

weight = [0.3, 0.7]
class_weights = torch.FloatTensor(weight)
criterion = nn.CrossEntropyLoss(weight=class_weights)
optimizer = torch.optim.Adam(model.parameters(), lr=0.01) 

N_INPUTS = 16
N_NEURONS = 20
N_OUTPUTS = 2
n_layers=20
drop_prob=0.85

class ImageRNN(nn.Module):
def __init__(self, batch_size, n_inputs, n_neurons,drop_prob, n_outputs,n_layers):
    super(ImageRNN, self).__init__()
    
    self.n_neurons = n_neurons
    self.batch_size = batch_size
    self.n_inputs = n_inputs
    self.n_outputs = n_outputs
    self.n_layers=n_layers
    self.drop_prob = drop_prob
    self.basic_rnn = nn.RNN(self.n_inputs,self.n_neurons,self.n_layers)
    self.dropout = nn.Dropout(drop_prob)
    self.FC = nn.Linear(self.n_neurons, self.n_outputs)
    
def init_hidden(self):
    return (torch.zeros(self.n_layers, self.batch_size, self.n_neurons))

def forward(self, X):
    X = X.unsqueeze(dim=0) 
    self.batch_size = X.size(1)
    self.hidden = self.init_hidden()
    output, self.hidden = self.basic_rnn(X, self.hidden)
    out = self.dropout(output)
    out = self.FC(out)
    
    return out.view(-1, self.n_outputs) 
model = ImageRNN(batch_size, N_INPUTS, N_NEURONS, drop_prob, N_OUTPUTS,n_layers)

n_epochs = 300
valid_loss_min = np.Inf


for epoch in range(n_epochs):
train_loss = 0.0
train_acc = 0.0

model.train()
for data, target in train_loader:
    optimizer.zero_grad()
    output = model(data)
    loss = criterion(output, target)
    loss.backward()
    optimizer.step()
    train_loss += loss.detach().item()
    train_acc += get_accuracy(output, target, batch_size)
print('Epoch:  %d | Loss: %.4f | Train Accuracy: %.2f' 
      %(epoch, train_loss / len(train_loader), train_acc/len(train_loader)))

Thank you so much in advance!!!