Zaktualizuj 'train-sacred.py'

This commit is contained in:
Kornelia Girejko 2022-05-08 20:30:23 +02:00
parent feb020c9a9
commit ccbcdd3715

View File

@ -84,17 +84,17 @@ def my_main(epochs):
loss.backward()
optimizer.step()
optimizer.zero_grad()
if (epochs%100==0):
print(f'epoch:{epochs+1},loss = {loss.item():.4f}')
with open ("output.txt",'a+') as f:
if (epochs%100==0):
f.write(f'epoch:{epochs+1},loss = {loss.item():.4f}')
with torch.no_grad():
y_predicted = model(X_testing)
y_predicted_cls = y_predicted.round()
acc = y_predicted_cls.eq(y_testing).sum()/float(y_testing.shape[0])
print(f'{acc:.4f}')
result = open("output",'w+')
result.write(f'{y_predicted}')
#result = open("output",'w+')
#result.write(f'{y_predicted}')
torch.save(model, "modelS.pkl")