BindsNET丨环境配置及安装
Posted AXYZdong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BindsNET丨环境配置及安装相关的知识,希望对你有一定的参考价值。
环境说明
操作系统:Windows 10
CUDA 版本为: 10.0
cudnn 版本为: 7.6.5
Python 版本为:Python 3.8
PyTorch 版本为:1.8.1
IDE:PyCharm
注意CUDA、cudnn、Python、PyTorch版本之间的匹配
BindsNET项目地址:https://github.com/BindsNET/bindsnet
官方推荐安装过程
官方推荐安装如下:
我的安装过程
- 第一步
使用anaconda创建一个python3.8的环境
- 第二步
安装pytorch
根据自己的电脑配置,在刚刚创建的的环境下,安装Pytorch。
Anaconda Prompt下输入以下指令激活环境,其中***为你创建环境的名称。
activate ***
转到创建的环境后,输入指令安装Pytorch。我的安装指令如下:
conda install pytorch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 cudatoolkit=10.2 -c pytorch
根据自己的电脑配置选择性进行安装,Pytotch官网。
- 第三步
安装可视化包 matplotlib
pip install matplotlib
- 第四步
测试代码,代码地址:https://bindsnet-docs.readthedocs.io/guide/guide_part_i.html#creating-a-network
代码运行成功就OK了。
# =====-*- coding: utf-8 -*-=====
# @Time : 2023/3/9 17:02
# @Author: AXYZdong
# @File : demo.py
# @IDE : Pycharm
# ===============================
import torch
import matplotlib.pyplot as plt
from bindsnet.network import Network
from bindsnet.network.nodes import Input, LIFNodes
from bindsnet.network.topology import Connection
from bindsnet.network.monitors import Monitor
from bindsnet.analysis.plotting import plot_spikes, plot_voltages
# Simulation time.
time = 500
# Create the network.
network = Network()
# Create and add input, output layers.
source_layer = Input(n=100)
target_layer = LIFNodes(n=1000)
network.add_layer(
layer=source_layer, name="A"
)
network.add_layer(
layer=target_layer, name="B"
)
# Create connection between input and output layers.
forward_connection = Connection(
source=source_layer,
target=target_layer,
w=0.05 + 0.1 * torch.randn(source_layer.n, target_layer.n), # Normal(0.05, 0.01) weights.
)
network.add_connection(
connection=forward_connection, source="A", target="B"
)
# Create recurrent connection in output layer.
recurrent_connection = Connection(
source=target_layer,
target=target_layer,
w=0.025 * (torch.eye(target_layer.n) - 1), # Small, inhibitory "competitive" weights.
)
network.add_connection(
connection=recurrent_connection, source="B", target="B"
)
# Create and add input and output layer monitors.
source_monitor = Monitor(
obj=source_layer,
state_vars=("s",), # Record spikes and voltages.
time=time, # Length of simulation (if known ahead of time).
)
target_monitor = Monitor(
obj=target_layer,
state_vars=("s", "v"), # Record spikes and voltages.
time=time, # Length of simulation (if known ahead of time).
)
network.add_monitor(monitor=source_monitor, name="A")
network.add_monitor(monitor=target_monitor, name="B")
# Create input spike data, where each spike is distributed according to Bernoulli(0.1).
input_data = torch.bernoulli(0.1 * torch.ones(time, source_layer.n)).byte()
inputs = "A": input_data
# Simulate network on input data.
network.run(inputs=inputs, time=time)
# Retrieve and plot simulation spike, voltage data from monitors.
spikes =
"A": source_monitor.get("s"), "B": target_monitor.get("s")
voltages = "B": target_monitor.get("v")
plt.ioff()
plot_spikes(spikes)
plot_voltages(voltages, plot_type="line")
plt.show()
—— END ——
如果以上内容有任何错误或者不准确的地方,欢迎在下面 👇 留言。或者你有更好的想法,欢迎一起交流学习~~~
更多精彩内容请前往 AXYZdong的博客
以上是关于BindsNET丨环境配置及安装的主要内容,如果未能解决你的问题,请参考以下文章
BindsNET丨Part I. 创建网络和添加网络组件(Creating and Adding Network Components)
深度学习环境安装配置中各个软件的关系及作用(Anaconda,Pycharm,Python,库,PyTorch, conda)
软件测试体系学习及构建(24)Selenium使用丨安装和注意事项
[Python人工智能] 三十九.VS Code配置Python编程和Keras环境及手写数字识别(基础篇)