I want to use mlp do prediction(98 vectors of 100), when I save the results, there only 7 vectors(batch=10, the output of one batch). Even if I set batch=90, I saved 7 vectors. I want to know how could I save all baches results?
I save it as followed:
length=len(X) // batch_size
print(length)
for epoch in range(total_epoch):
loss_sum=0.0
for batch_idx in range(length+1):
if batch_idx != length:
x_ = X[batch_idx*batch_size : (batch_idx+1)*batch_size]
y_ = Y[batch_idx*batch_size : (batch_idx+1)*batch_size]
else:
x_ = X[batch_idx*batch_size : ]
y_ = Y[batch_idx*batch_size : ]
x_proj = projector(x_)
loss = torch.nn.MSELoss()(x_proj, y_)
loss_sum += loss.item()
optimizer.zero_grad()
loss.backward()
optimizer.step()
if batch_idx % print_freq == 0:
print(f"Epoch: {epoch}, Iteration: {batch_idx}, Loss: {loss.item():.4f}")
print(f"Epoch: {epoch}, Loss Avg: {loss_sum/length: .4f}")
print('pred:',x_proj)
pred=x_proj.detach().cpu().numpy() # Append batch output to list
out_pred = pd.DataFrame(pred).to_csv('prediction+{batch_idx}.csv')
out_pred = pd.DataFrame(pred).to_csv('prediction.csv')