Giter Site home page Giter Site logo

nn_visualization's Introduction

AI可视化及对抗样本演示

模型结构动画

我们应用开源的神经网络的结构和参数可视化代码,运行python start_tool.py命令,载入一个处理过的模型(storage/data/default/*.pro.npz),可清晰的看到网络的层次化结构:

如果我们选择generate_network, 便能得到一个未经训练的原始模型:

可见训练的过程,就是将所有的线设置成合适的值的过程。

训练过程可视化

这里我们借助于stefsietz大佬的Unity3D开源项目,配置好Unity环境后,打开案例里面的场景,便能看到下面这个工作区:

运行Game,载入训练好的转换后的模型文件夹jsons,可以动态的拖拽模型:

CNN原理演示

这里使用佐治亚理工**博士出品的CNN解释器,动态的感受一下CNN中几个基本组件原理:

  • 卷积:自动提取局部特征

  • 激活:对特征进行非线性映射

  • 池化:特征采样,信息抽象

  • 全连接,计算分类概率

对抗样本产生

这里使用一个简单的FGSM方法产生一个对抗样本。

我们首先读取一张小熊猫图片,载入已训练好的tiny_vgg模型,得到梯度后,使用梯度符号*扰动,叠加到原始图像上,便得到对对抗样本。

image_batch

loss_object = tf.keras.losses.CategoricalCrossentropy()
with tf.GradientTape(persistent=True) as tape:
    tape.watch(image_batch)
    predictions = tiny_vgg(image_batch)
    loss = loss_object(label_batch, predictions)
gradients = tape.gradient(loss, image_batch)
signed_grad = tf.sign(gradients)

epsilon, prediction = 0.01, True
label_true = predictions[0].numpy().argmax()

while prediction:
    adv_img = tf.add(image_batch, epsilon * signed_grad)
    adv_img = tf.clip_by_value(adv_img, 0, 1)
    label_pred = tiny_vgg(adv_img)[0].numpy().argmax()
    if label_pred == label_true:
        epsilon += 0.0007

对抗样本可视化

首先看看原始的小熊猫图片在神经网络中的一个特征分布情况:

再看看小熊猫图片被加入对抗样本后的特征分布情况:

可以清楚看到,两者的预测结果截然不同,我们仔细放大下最后一个max_pooling层第三个filter提取的特征差异(颜色深浅):

参考资料

神经网络的结构和参数可视化

基于Unity的神经网络训练过程可视化

  • 仓库地址: https://github.com/stefsietz/nn-visualizer
  • 运行环境:Python、Tensorflow1、Unity、C#
  • 使用效果:构建3D版神经网络,使用鼠标和神经网络动态交互,动态查看训练过程

CNN原理可视化

  • 仓库地址: https://github.com/poloclub/cnn-explainer
  • 运行环境:Python、Tensorflow2、TensorflowJS、NodeJS
  • 使用效果:演示神经网络的原理,查看每一层、每个神经元的特征数值

MNIST数据集分类模型可视化交互

工具

nn_visualization's People

Contributors

aisecstudent 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.