Open thebug-dev opened 6 months ago
我的代码如下: model.eval() for m in model.fc.modules(): if isinstance(m, neuron.LIFNode): m.store_v_seq = True print(model.fc[-1].store_v_seq) monitor_v = monitor.AttributeMonitor(attribute_name='v', pre_forward=False, net=model.fc[-1], instance=neuron.LIFNode) monitor_o = monitor.OutputMonitor(net=model.fc[-1], instance=neuron.LIFNode) with torch.no_grad(): data_iter = iter(test_loader) data, label = next(data_iter)
data = data[0] label = label[0] print(f'Label of the first sample: {label.item()}') data = data.to(device) out_fr = model(data) out_spikes_counter_frequency = out_fr.cpu().numpy() print(f'Firing rate: {out_spikes_counter_frequency}') v_list = monitor_v.records[0].squeeze() s_list = monitor_o.records[0].squeeze() print(monitor_v.records, monitor_o.records, v_list.shape, s_list.shape) numpy_array_v_list = v_list.detach().cpu().numpy() numpy_array_s_list = s_list.detach().cpu().numpy() visualizing.plot_1d_spikes(spikes=np.asarray(numpy_array_s_list), title='Membrane Potentials', xlabel='Simulating Step',ylabel='Neuron Index', dpi=300) numpy_array_s_list = numpy_array_s_list.flatten() visualizing.plot_one_neuron_v_s(numpy_array_v_list, numpy_array_s_list, v_threshold=1, v_reset=0, figsize=(12, 8), dpi=300) plt.show() functional.reset_net(model) del monitor_v,monitor_o
请问作者大大,已经设置了m.store_v_seq = True,但v监视器输出如下: [tensor([[0.6333, 0.0000, 0.7034, 0.6480]], device='cuda:0')],只有一个时间步的,而s监视器正常有32个时间步
之前的代码使用了文字文本,现改成代码文本方便查看: 输出如下: 形状为torch.Size([4]),并不是预期的(32,4)
model.fc如下:
已经修复了,我把monitor_v和monitor_o的两行代码改成: 就好了,很神奇,但原理未知
我的代码如下: model.eval() for m in model.fc.modules(): if isinstance(m, neuron.LIFNode): m.store_v_seq = True print(model.fc[-1].store_v_seq) monitor_v = monitor.AttributeMonitor(attribute_name='v', pre_forward=False, net=model.fc[-1], instance=neuron.LIFNode) monitor_o = monitor.OutputMonitor(net=model.fc[-1], instance=neuron.LIFNode) with torch.no_grad():
data_iter = iter(test_loader)
data, label = next(data_iter)
只取批次中的第一个样本
请问作者大大,已经设置了m.store_v_seq = True,但v监视器输出如下: [tensor([[0.6333, 0.0000, 0.7034, 0.6480]], device='cuda:0')],只有一个时间步的,而s监视器正常有32个时间步