Giter Site home page Giter Site logo

Comments (1)

insikk avatar insikk commented on August 29, 2024

I was able to retrieve evaluation metrics from saved file format.

import torch
import os

def smooth(scalars, weight):  # Weight between 0 and 1
    last = scalars[0]  # First value in the plot (first timestep)
    smoothed = list()
    for point in scalars:
        smoothed_val = last * weight + (1 - weight) * point  # Calculate smoothed value
        smoothed.append(smoothed_val)                        # Save it
        last = smoothed_val                                  # Anchor the last smoothed value

    return smoothed

plt.plot(test_result['classifier.glob[-1](64,).accuracy_top_1'])        
plt.show()

smoothed_val = smooth(test_result['classifier.glob[-1](64,).accuracy_top_1'], 0.99)
plt.plot(smoothed_val)        
plt.show()

output_path = "./output"

experiments = os.listdir(output_path)
# print(experiments)
for exp_name in experiments:
    exp_path = os.path.join(output_path, exp_name)
    if exp_name[0] == '.':
        continue
    saved_model_path = os.path.join(exp_path, "binaries")
    for saved_model_name in os.listdir(saved_model_path):
        if not saved_model_name.endswith(".t7"):
            continue
        if '_last' in saved_model_name or \
           '_final' in saved_model_name:
            save_path = os.path.join(saved_model_path, saved_model_name)
            graph_path = os.path.join(exp_path, f"{saved_model_name}_global_test_acc.png")
            if os.path.exists(graph_path):
                continue
            print(saved_model_name)
            try:
                model = torch.load(save_path)
            except EOFError as e:                
                print(f"skip processing this model {saved_model_name} due to exception:", e)
                continue
            # print(model.keys())
            test_result = model['results']['results']['results']['test']
            keys = ['classifier.glob[-1](64,).accuracy_top_1',
                    'classifier.glob[-1](128,).accuracy_top_1',
                    'classifier.glob[8](192,5,5).accuracy_top_1',
                   ]
            t_result = None
            for key in keys:
                try:
                    t_result = test_result[key]
                    break
                except KeyError:
                    print(f"key: {key} does not exists in list:", test_result.keys())
            if t_result is not None:
                smoothed_val = smooth(t_result, 0.99)
                plt.plot(smoothed_val)        
                plt.savefig(graph_path)
                plt.show()

from dim.

Related Issues (20)

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.