Giter Site home page Giter Site logo

viz_torch_optim's Introduction

可视化pytorch的优化器

这个工程学习了 原工程 的可视化的方法,主要目的是对比学习

  1. 同一优化器在不同参数下的表现
  2. 同一函数下在不同优化器下的梯度下降表现

深度学习是对loss进行梯度下降,从而得到神经网络的参数。本工程以二元函数为例子,提供了二维、三维的静态、动态轨迹图的方法。 使用者仅需要在core.py中main函数里定义好Problem实例,选择好想要对比的优化器,再选择输出什么轨迹图。如下:

def main():
    problem = Problem(
        f=beales,  # 二元函数
        start=[2, 1.7],  # 优化起点
        minima=[3., 0.5],  # 函数的极小值坐标
        bound=[[-3, 3], [-3, 3]],  # 函数自变量的绘图范围
        z_limit=[0, 300],  # 函数值的绘图范围
        grid_step=0.1,  # 网格的密度
        train_step=10,  # 训练步数
        fig=FIG,  # plt.figure实例
        optimizer_fn_dict=optimizer_fn_dict  # 优化器字典
      ) 
    optimizer_fn_dict = dict(
        SGD=partial(optim.SGD, lr=.4),  # SGD
        Adadelta=optim.Adadelta,  # Adadelta
        Adam=partial(optim.Adam, lr=1  # Adam
    )

    # 选择轨迹图
    problem.train()
    problem.show_trace_2d()  # 二维静态轨迹
    # problem.show_trace_3d()  # 三维静态轨迹
    # problem.animation_2d()  # 二维动态轨迹
    # problem.animation_3d()  # 三维动态轨迹
    plt.legend(loc='upper right')
    plt.show()

最后运行

python core.py

即可。 Problem.py中存放着一些有趣的二元函数,你也可以使用最简单的二元二次函数。

目前图还做得不太美观,欢迎提建议。

示例

二维静态图

二维静态图

三维静态图

二维动态图

二维动态图

三维静态图

三维动态图

三维动态图

viz_torch_optim's People

Contributors

wassname avatar frankhui avatar

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.