使用manim社区版绘制神经网络结构图

1、概述manim作为非常炫酷的动画系统可以非常清晰生动表述数学原理的相关动画。但是在原生系统中并没有神经网络结构绘制的模块,需要自行开发。本文展示了最基本的dnn网络的绘制方式,供大家参考。2、完整代码class NeuralNetworkMobject(VGroup): # Constructor with parameters of the neurons in a list def __init__(self, neural_network, *arg
摘要由CSDN通过智能技术生成

1、概述

manim作为非常炫酷的动画系统可以非常清晰生动表述数学原理的相关动画。但是在原生系统中并没有神经网络结构绘制的模块,需要自行开发。本文展示了最基本的dnn网络的绘制方式,供大家参考。

2、完整代码

class NeuralNetworkMobject(VGroup):
        
    # Constructor with parameters of the neurons in a list
    def __init__(self, neural_network, *args, **kwargs):
        VGroup.__init__(self, *args,**kwargs)
        self.neuron_radius = 0.15
        self.neuron_to_neuron_buff= MED_SMALL_BUFF
        self.layer_to_layer_buff= LARGE_BUFF
        self.output_neuron_color= WHITE
        self.input_neuron_color= WHITE
        self.hidden_layer_neuron_color= WHITE
        self.neuron_stroke_width= 2
        self.neuron_fill_color= GREEN
        self.edge_color= LIGHT_GREY
        self.edge_stroke_width= 2
        self.edge_propogation_color= YELLOW
        self.edge_propogation_time= 1
        self.max_shown_neurons= 16
        self.brace_for_large_layers= True
        self.average_shown_activation_of_large_layer= True
        self.include_output_labels= False
        self.arrow= False
        self.arrow_tip_size= 0.1
        self.left_size= 1
        self.neuron_fill_opacity= 1
        for name, value in kwargs.items():
            setattr(self, name, value)
        self.layer_sizes = neural_network
        self.add_neurons()
        self.add_edges()
        self.add_to_back(self.layers)
    # Helper method for constructor
    def add_neurons(self):
        layers = VGroup(*[
            self.get_layer(size, index)
            for index, size in enumerate(self.layer_sizes)
        ])
        layers.arrange_submobjects(RIGHT, buff=self.layer_to_layer_buff)
        self.layers = layers
        if self.include_output_labels:
            self.label_outputs_text()
    # Helper method for constructor
    def get_nn_fill_color(self, index):
        if index == -1 or index =
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值