braincog.model_zoo package

Submodules

braincog.model_zoo.backeinet module

class braincog.model_zoo.backeinet.CIFARNet(step=20, encode_type='rate', if_back=True, if_ei=True, *args, **kwargs)

基类:BaseModule

forward(inputs)

Defines the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class braincog.model_zoo.backeinet.MNISTNet(step=20, encode_type='rate', if_back=True, if_ei=True, data='mnist', *args, **kwargs)

基类:BaseModule

forward(inputs)

Defines the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

braincog.model_zoo.base_module module

class braincog.model_zoo.base_module.BaseConvModule(in_channels: int, out_channels: int, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False, node=<class 'braincog.base.node.node.PLIFNode'>, **kwargs)

基类:Module

SNN卷积模块 :param in_channels: 输入通道数 :param out_channels: 输出通道数 :param kernel_size: kernel size :param stride: stride :param padding: padding :param bias: Bias :param node: 神经元类型 :param kwargs:

forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class braincog.model_zoo.base_module.BaseLinearModule(in_features: int, out_features: int, bias=True, node=<class 'braincog.base.node.node.LIFNode'>, *args, **kwargs)

基类:Module

线性模块 :param in_features: 输入尺寸 :param out_features: 输出尺寸 :param bias: 是否有Bias, 默认 False :param node: 神经元类型, 默认 LIFNode :param args: :param kwargs:

forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class braincog.model_zoo.base_module.BaseModule(step, encode_type, layer_by_layer=False, temporal_flatten=False, *args, **kwargs)

基类:Module, ABC

SNN抽象类, 所有的SNN都要继承这个类, 以实现一些基础方法 :param step: 仿真步长 :param encode_type: 数据编码类型 :param layer_by_layer: 是否layer wise地进行前向推理 :param temporal_flatten: 是否将时间维度和channel合并 :param args: :param kwargs:

static forward(self, inputs)

Defines the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

get_attr(attr)

获取神经元的某一属性值 :param attr: 属性名称 :return: 对应属性的值, List

get_fire_rate(requires_grad=False)

获取神经元的fire-rate :param requires_grad: 是否需要梯度信息, 默认为 False 会截断梯度 :return: 所有神经元的fire-rate

get_fp(temporal_info=False)

获取所有神经元的状态 :param temporal_info: 是否要读取神经元的时间维度状态, False会把时间维度拍平 :return: 所有神经元的状态, List

get_mem(temporal_info=False)

获取所有神经元的模电势 :param temporal_info: 是否要读取神经元的时间维度状态, False会把时间维度拍平 :return: 所有神经元的状态, List

get_spike_info()

获取神经元的脉冲信息, 主要用于绘图 :return:

get_threshold()

获取所有神经元的阈值 :return:

get_tot_spike()

获取神经元总的脉冲数量 :return:

reset()

重置所有神经元的膜电位 :return:

set_attr(attr, val)

设置神经元的属性 :param attr: 属性名称 :param val: 设置的属性值 :return:

set_requires_fp(flag)
set_requires_mem(flag)
training: bool

braincog.model_zoo.bdmsnn module

class braincog.model_zoo.bdmsnn.BDMSNN(num_state, num_action, weight_exc, weight_inh, node_type)

基类:Module

UpdateWeight(i, s, num_action, dw)

更新网络中第i组连接的权重 :param i:要更新的连接组索引 :param s:传入状态 :param dw:更新权重的量 :return:

forward(input)

根据输入得到网络的输出 :param input: 输入 :return: 网络的输出

getweight()

获取网络的连接(包括权值等) :return: 网络的连接

reset()

reset神经元或学习法则的中间量 :return: None

training: bool

braincog.model_zoo.convnet module

braincog.model_zoo.convnet.cifar_convnet(step, encode_type, spike_output: bool, node_type, *args, **kwargs)
braincog.model_zoo.convnet.dvs_convnet(step, encode_type, spike_output: bool, node_type, num_classes, *args, **kwargs)
braincog.model_zoo.convnet.mnist_convnet(step, encode_type, spike_output: bool, node_type, *args, **kwargs)

braincog.model_zoo.glsnn module

class braincog.model_zoo.glsnn.BaseGLSNN(input_size=784, hidden_sizes=[800, 800, 800], output_size=10, opt=None)

基类:BaseModule

The fully connected model of the GLSNN :param input_size: the shape of the input :param hidden_sizes: list, the number of neurons of each layer in the hidden layers :param ouput_size: the number of the output layers

feedback(ff_value, y_label)

process information in the feedback manner and get target :param ff_value: the feedforward value of each layer :param y_label: the label of the corresponding input

feedback_parameters()
forward(x)

process the information in the forward manner :param x: the input

forward_parameters()
set_gradient(x, y)

get the corresponding update of each layer

training: bool

braincog.model_zoo.linearNet module

class braincog.model_zoo.linearNet.droDMTrainNet(connection)

基类:Module

Drosophila Training network: compound eye-KC-MBON

UpdateWeight(i, dw)

更新网络中第i组连接的权重 :param i: 要更新的连接的索引 :param dw: 更新的量 :return: None

forward(input)

根据输入得到输出 :param input: 输入电流 :return: 网络的输出,以及网络运行产生的STDP可塑性

getweight()

获取网络的连接(包括权值等) :return: 网络的连接

reset()

reset神经元或学习法则的中间量 :return: None

training: bool

braincog.model_zoo.nonlinearNet module

class braincog.model_zoo.nonlinearNet.droDMTestNet(connection)

基类:Module

Drosophila Testing Network: compound eye-KC-MBON DA-GABA-MB

UpdateWeight(i, dw)

更新网络中第i组连接的权重 :param i: 要更新的连接的索引 :param dw: 更新的量 :return: None

forward(input, input_da)

根据输入得到输出 :param input: 输入电流 :return: 网络的输出,以及网络运行产生的STDP可塑性

getweight()

获取网络的连接(包括权值等) :return: 网络的连接

reset()

reset神经元或学习法则的中间量 :return: None

training: bool

braincog.model_zoo.qsnn module

class braincog.model_zoo.qsnn.Hidden_layer(input_size, neu_num, fb_neus)

基类:Module

隐藏层两房室网络

training: bool
update_state(basal_input, apical_input, test)
update_weight(delta_, lr, t, beta, eps)
class braincog.model_zoo.qsnn.Net(net_size)

基类:Module

两房室脉冲神经网络

predict(input_, input_delta, image_ori, image_ori_delta, shift, noise, noise_rate=0)
routine(input_, input_delta, image_ori, image_ori_delta, shift, label, test=False, noise=False, noise_rate=None)

网络信息处理过程 :param input_: 输入图片 :param input_delta: 输入扰动图片,用于计算相位 :param image_ori: 原始图片 :param image_ori_delta: 原始扰动图片 :param shift: 是否反转背景 :param label: 输入数据分类标签 :param test: 是否是测试阶段 :param noise: 是否增加噪声 :param noise_rate: 噪声比例

training: bool
update_state(input_, label, test)
update_weight(lr, t, beta, eps)
class braincog.model_zoo.qsnn.Output_layer(input_size, neu_num)

基类:Module

输出层两房室网络

training: bool
update_state(basal_input, I, test)
update_weight(lr, t, beta, eps)
braincog.model_zoo.qsnn.deriv_sigma(x)
braincog.model_zoo.qsnn.get_kappas(n)
braincog.model_zoo.qsnn.kappa(x)
braincog.model_zoo.qsnn.sigma(x)

braincog.model_zoo.resnet module

Deep Residual Learning for Image Recognition https://github.com/pytorch/vision/blob/master/torchvision/models/resnet.py

class braincog.model_zoo.resnet.ResNet(block, layers, inplanes=64, num_classes=10, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None, step=8, encode_type='direct', spike_output=False, *args, **kwargs)

基类:BaseModule

ResNet-SNN :param block: Block类型 :param layers: block 层数 :param inplanes: 输入通道数量 :param num_classes: 输出类别数 :param zero_init_residual: 是否使用零初始化 :param groups: 卷积分组 :param width_per_group: 每一组的宽度 :param replace_stride_with_dilation: 是否使用stride替换dilation :param norm_layer: Norm 方式, 默认为 BatchNorm :param step: 仿真步长, 默认为 8 :param encode_type: 编码方式, 默认为 direct :param spike_output: 是否使用脉冲输出, 默认为 False :param args: :param kwargs:

forward(inputs)

Defines the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
braincog.model_zoo.resnet.resnet101(pretrained=False, **kwargs)
braincog.model_zoo.resnet.resnet152(pretrained=False, **kwargs)
braincog.model_zoo.resnet.resnet18(pretrained=False, **kwargs)
braincog.model_zoo.resnet.resnet34(pretrained=False, **kwargs)
braincog.model_zoo.resnet.resnet34_half(pretrained=False, **kwargs)
braincog.model_zoo.resnet.resnet50(pretrained=False, **kwargs)
braincog.model_zoo.resnet.resnet50_half(pretrained=False, **kwargs)
braincog.model_zoo.resnet.resnet9(pretrained=False, **kwargs)
braincog.model_zoo.resnet.resnext101_32x8d(pretrained=False, **kwargs)
braincog.model_zoo.resnet.resnext50_32x4d(pretrained=False, **kwargs)
braincog.model_zoo.resnet.wide_resnet101_2(pretrained=False, **kwargs)
braincog.model_zoo.resnet.wide_resnet50_2(pretrained=False, **kwargs)

braincog.model_zoo.resnet19_snn module

braincog.model_zoo.resnet19_snn.resnet19(pretrained=False, progress=True, norm=<class 'braincog.base.connection.layer.ThresholdDependentBatchNorm2d'>, **kwargs)

braincog.model_zoo.rsnn module

class braincog.model_zoo.rsnn.RSNN(num_state, num_action)

基类:Module

UpdateWeight(reward)
forward(input)

Defines the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

getweight()
reset()
training: bool

braincog.model_zoo.sew_resnet module

class braincog.model_zoo.sew_resnet.SEWResNet(block, layers, num_classes=1000, step=8, encode_type='direct', zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None, cnf: Optional[str] = None, *args, **kwargs)

基类:BaseModule

forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
braincog.model_zoo.sew_resnet.sew_resnet101(pretrained=False, progress=True, cnf: Optional[str] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a spiking neuron layer

  • kwargs (dict) – kwargs for node

返回

Spiking ResNet-101

返回类型

torch.nn.Module

The spike-element-wise ResNet-101 “Deep Residual Learning in Spiking Neural Networks” modified by the ResNet-101 model from “Deep Residual Learning for Image Recognition”

braincog.model_zoo.sew_resnet.sew_resnet152(pretrained=False, progress=True, cnf: Optional[str] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a single step neuron

  • kwargs (dict) – kwargs for node

返回

Spiking ResNet-152

返回类型

torch.nn.Module

The spike-element-wise ResNet-152 “Deep Residual Learning in Spiking Neural Networks” modified by the ResNet-152 model from “Deep Residual Learning for Image Recognition”

braincog.model_zoo.sew_resnet.sew_resnet18(pretrained=False, progress=True, cnf: Optional[str] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a spiking neuron layer

  • kwargs (dict) – kwargs for node

返回

Spiking ResNet-18

返回类型

torch.nn.Module

The spike-element-wise ResNet-18 “Deep Residual Learning in Spiking Neural Networks” modified by the ResNet-18 model from “Deep Residual Learning for Image Recognition”

braincog.model_zoo.sew_resnet.sew_resnet19(pretrained=False, progress=True, cnf: Optional[str] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a spiking neuron layer

  • kwargs (dict) – kwargs for node

返回

Spiking ResNet-18

返回类型

torch.nn.Module

The spike-element-wise ResNet-18 “Deep Residual Learning in Spiking Neural Networks” modified by the ResNet-18 model from “Deep Residual Learning for Image Recognition”

braincog.model_zoo.sew_resnet.sew_resnet19slim(pretrained=False, progress=True, cnf: Optional[str] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a spiking neuron layer

  • kwargs (dict) – kwargs for node

返回

Spiking ResNet-18

返回类型

torch.nn.Module

The spike-element-wise ResNet-18 “Deep Residual Learning in Spiking Neural Networks” modified by the ResNet-18 model from “Deep Residual Learning for Image Recognition”

braincog.model_zoo.sew_resnet.sew_resnet34(pretrained=False, progress=True, cnf: Optional[str] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a spiking neuron layer

  • kwargs (dict) – kwargs for node

返回

Spiking ResNet-34

返回类型

torch.nn.Module

The spike-element-wise ResNet-34 “Deep Residual Learning in Spiking Neural Networks” modified by the ResNet-34 model from “Deep Residual Learning for Image Recognition”

braincog.model_zoo.sew_resnet.sew_resnet50(pretrained=False, progress=True, cnf: Optional[str] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a spiking neuron layer

  • kwargs (dict) – kwargs for node

返回

Spiking ResNet-50

返回类型

torch.nn.Module

The spike-element-wise ResNet-50 “Deep Residual Learning in Spiking Neural Networks” modified by the ResNet-50 model from “Deep Residual Learning for Image Recognition”

braincog.model_zoo.sew_resnet.sew_resnext101_32x8d(pretrained=False, progress=True, cnf: Optional[str] = None, node: Optional[callable] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a single step neuron

  • kwargs (dict) – kwargs for node

返回

Spiking ResNeXt-101 32x8d

返回类型

torch.nn.Module

The spike-element-wise ResNeXt-101 32x8d “Deep Residual Learning in Spiking Neural Networks” modified by the ResNeXt-101 32x8d model from “Aggregated Residual Transformation for Deep Neural Networks”

braincog.model_zoo.sew_resnet.sew_resnext34_32x4d(pretrained=False, progress=True, cnf: Optional[str] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a single step neuron

  • kwargs (dict) – kwargs for node

返回

Spiking ResNeXt-101 32x8d

返回类型

torch.nn.Module

The spike-element-wise ResNeXt-101 32x8d “Deep Residual Learning in Spiking Neural Networks” modified by the ResNeXt-101 32x8d model from “Aggregated Residual Transformation for Deep Neural Networks”

braincog.model_zoo.sew_resnet.sew_resnext50_32x4d(pretrained=False, progress=True, cnf: Optional[str] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a single step neuron

  • kwargs (dict) – kwargs for node

返回

Spiking ResNeXt-50 32x4d

返回类型

torch.nn.Module

The spike-element-wise ResNeXt-50 32x4d “Deep Residual Learning in Spiking Neural Networks” modified by the ResNeXt-50 32x4d model from “Aggregated Residual Transformation for Deep Neural Networks”

braincog.model_zoo.sew_resnet.sew_wide_resnet101_2(pretrained=False, progress=True, cnf: Optional[str] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a single step neuron

  • kwargs (dict) – kwargs for node

返回

Spiking Wide ResNet-101-2

返回类型

torch.nn.Module

The spike-element-wise Wide ResNet-101-2 “Deep Residual Learning in Spiking Neural Networks” modified by the Wide ResNet-101-2 model from “Wide Residual Networks” The model is the same as ResNet except for the bottleneck number of channels which is twice larger in every block. The number of channels in outer 1x1 convolutions is the same, e.g. last block in ResNet-50 has 2048-512-2048 channels, and in Wide ResNet-50-2 has 2048-1024-2048.

braincog.model_zoo.sew_resnet.sew_wide_resnet50_2(pretrained=False, progress=True, cnf: Optional[str] = None, **kwargs)
参数
  • pretrained (bool) – If True, the SNN will load parameters from the ANN pre-trained on ImageNet

  • progress (bool) – If True, displays a progress bar of the download to stderr

  • cnf (str) – the name of spike-element-wise function

  • node (callable) – a single step neuron

  • kwargs (dict) – kwargs for node

返回

Spiking Wide ResNet-50-2

返回类型

torch.nn.Module

The spike-element-wise Wide ResNet-50-2 “Deep Residual Learning in Spiking Neural Networks” modified by the Wide ResNet-50-2 model from “Wide Residual Networks” The model is the same as ResNet except for the bottleneck number of channels which is twice larger in every block. The number of channels in outer 1x1 convolutions is the same, e.g. last block in ResNet-50 has 2048-512-2048 channels, and in Wide ResNet-50-2 has 2048-1024-2048.

braincog.model_zoo.vgg_snn module

class braincog.model_zoo.vgg_snn.SNN5(num_classes=10, step=8, node_type=<class 'braincog.base.node.node.LIFNode'>, encode_type='direct', *args, **kwargs)

基类:BaseModule

forward(inputs)

Defines the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class braincog.model_zoo.vgg_snn.SNN7_tiny(num_classes=10, step=8, node_type=<class 'braincog.base.node.node.LIFNode'>, encode_type='direct', *args, **kwargs)

基类:BaseModule

forward(inputs)

Defines the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class braincog.model_zoo.vgg_snn.VGG_SNN(num_classes=10, step=8, node_type=<class 'braincog.base.node.node.LIFNode'>, encode_type='direct', *args, **kwargs)

基类:BaseModule

forward(inputs)

Defines the computation performed at every call.

Should be overridden by all subclasses.

备注

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

Module contents