fangwei123456 / spikingjelly

SpikingJelly is an open-source deep learning framework for Spiking Neural Network (SNN) based on PyTorch.
https://spikingjelly.readthedocs.io
Other
1.35k stars 239 forks source link

STDP使用求助 #585

Closed LFZhou2000 closed 5 days ago

LFZhou2000 commented 1 week ago

Issue type

SpikingJelly version

0.0.0.0.14

Description 您好! 主要想求助一些STDP的使用问题:

  1. STDPLearner中的sn参数是只能输入神经元吗(neuron.BaseNode)?似乎接其他层也能跑起来
  2. 如果1是,那么请问在如下程序中(卷积层与IF之间有一层BN层),STDPLearner的参数synapse应为net[0], sn应为net[2]而非net[1]?
  3. 请问spikingjelly是否支持类似2的,卷积与神经元间还有其他层的STDP?

self.conv_fc = torch.nn.Sequential( layer.Conv2d(1, 5, kernel_size=3, padding=0, bias=False), layer.BatchNorm2d(5), neuron.IFNode(surrogate_function=surrogate.ATan()), layer.MaxPool2d(2, 2), # 14 * 14

    layer.Flatten(),
    layer.Linear(5 * 13 * 13, 10, bias=False),
    neuron.IFNode(surrogate_function=surrogate.ATan())
    )

learning.STDPLearner(step_mode='m', synapse=net[0], sn=net[2], tau_pre=tau_pre, tau_post=tau_post, f_pre=f_weight, f_post=f_weight)

期待获得您的帮助,谢谢!

AllenYolk commented 5 days ago

您好!非常抱歉,回复得有些晚。

  1. STDPLearner中的sn参数是只能输入神经元吗(neuron.BaseNode)?似乎接其他层也能跑起来

从代码角度上说sn参数不一定要是neuron.BaseNodeSTDPLearner实际上使用了monitor.OutputMonitor来记录sn的输出;当sn不是神经元层时,自然也可以记录其输出。

class STDPLearner(base.MemoryModule):
    def __init__(
        self, step_mode: str,
        synapse: Union[nn.Conv2d, nn.Linear], sn: neuron.BaseNode,
        tau_pre: float, tau_post: float,
        f_pre: Callable = lambda x: x, f_post: Callable = lambda x: x
    ):
        super().__init__()
        ...
        self.out_spike_monitor = monitor.OutputMonitor(sn)
        ...
  1. 如果1是,那么请问在如下程序中(卷积层与IF之间有一层BN层),STDPLearner的参数synapse应为net[0], sn应为net[2]而非net[1]?
  2. 请问spikingjelly是否支持类似2的,卷积与神经元间还有其他层的STDP?

然而,从生物合理性角度来看sn需要是脉冲神经元。否则STDP就不会叫做"spike-timing dependent plasticity"了。

从算法有效性角度来看,用可塑性规则学习的网络通常不会在权重和神经元层之间添加BN等操作。可塑性这个研究领域内的一些工作会选择把BN放在权重层前面,从而不打破“突触权重-神经元”这个整体模块(如Hebbian Deep Learning Without Feedback)。当然,您可以自己尝试一下把BN添加在权重和神经元层中间,看看是否有效!

LFZhou2000 commented 5 days ago

感谢您的耐心解答,我的问题基本有了答案,谢谢!