最后,我从一个文件中训练了一个网络:)现在我想打印节点和权重,特别是权重,因为我想用pybrain训练网络,然后在其他地方实现一个使用它的NN。
我需要一种方法来打印层、节点和节点之间的权重,这样我就可以轻松地复制它。到目前为止,我可以使用n['in']访问层,例如,我可以执行以下操作:
dir(n['in']) ['class', 'delattr', 'dict', 'doc', 'format', 'getattribute', 'hash', 'init', 'module', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', '_backwardImplementation', '_forwardImplementation', '_generateName', '_getName', '_growBuffers', '_name', '_nameIds', '_resetBuffers', '_setName', 'activate', 'activateOndataset', 'argdict', 'backActivate', 'backward', 'bufferlist', 'dim', 'forward', 'getName', 'indim', 'inputbuffer', 'inputerror', 'name', 'offset', 'outdim', 'outputbuffer', 'outputerror', 'paramdim', 'reset', 'sequential', 'setArgs', 'setName', 'shift', 'whichNeuron']
但我不知道我怎么能拿到这里的重量。还有params属性,例如my network is 241 with bias,它显示:
n.params array([-0.8167133 , 1.00077451, -0.7591257 , -1.1150532 , -1.58789386, 0.11625991, 0.98547457, -0.99397871, -1.8324281 , -2.42200963, 1.90617387, 1.93741167, -2.88433965, 0.27449852, -1.52606976, 2.39446258, 3.01359547])
很难说是什么,至少用重量连接哪些节点。这就是我所需要的。
有许多方法可以访问网络的内部,即通过其“模块”列表或“连接”字典。参数存储在这些连接或模块中。例如,以下内容应打印任意网络的所有这些信息:
如果你想要更细粒度的东西(在神经元层面而不是层层面),你将不得不进一步分解那些参数向量——或者,从单个神经元层面构建你的网络。
试试这个,它对我有效:
结果应该是:
也许这有帮助(Python 3.2版的PyBrain)?
相关问题 更多 >
编程相关推荐