GithubHelp home page GithubHelp logo

Draw the loss curve about couta HOT 2 CLOSED

943fansi avatar 943fansi commented on July 29, 2024
Draw the loss curve

from couta.

Comments (2)

xuhongzuo avatar xuhongzuo commented on July 29, 2024

I printed these loss values after each training epoch.
You could do this personalized requirement by yourself.
issue closed.

from couta.

943fansi avatar 943fansi commented on July 29, 2024

Add 4 lines code at src/algorithms/couta_algo.py, can save info in a "train_log.txt" file.

...
    val_loss = torch.mean(torch.stack(val_loss)).data.cpu().item()
# start
loss_file = "train_log.txt"
_f = open(loss_file, "a")
print(f'epoch: {i+1:02},loss: {epoch_loss:.6f},loss_oc: {epoch_loss_oc:.6f}, val_loss: {val_loss:.6f}',
                  file=_f, flush=True)
_f.close()
#end
    if (i+1) % 10 == 0:
    ...

And then use following code to transform it into a csv file:

import numpy as np
import pandas as pd

with open("train_log.txt", "r") as f:
    data = f.readlines()

n = len(data)
result = np.zeros([n, 4])
for i in range(n):
    record = data[i].split(",")
    epoch = int(record[0].split(" ")[-1])
    loss = float(record[1].split(" ")[-1])
    loss_oc = float(record[2].split(" ")[-1])
    val_loss = float(record[3].split(" ")[-1])
    print(epoch, loss, loss_oc, val_loss)
    result[i, :] = [epoch, loss, loss_oc, val_loss]
df = pd.DataFrame(data=result, columns=["epoch", "loss", "loss_oc", "val_loss"])
df.to_csv("loss_curve.csv")

from couta.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.