I put np.ndarray type data in a for statement and created a neural net, but it doesn't work. Please let me know. Below is the error statement and the corresponding part.
Error Statements
2020-11-11 14:18:42.758237:Itensorflow/stream_executor/platform/default/dso_loader.cc:44]
Successfully opened dynamic library cudart64_100.dll
Traceback (most recent call last):
File "C:/Users/namae/Desktop/myo-python-1.0.4/bindsnet-master/bindsnet/preRSNN.py", line 95, in
<module>
network.run (inputs=inputs, time=time)
File "C:\Python36\lib\site-packages\bindsnet\network\network.py", line 312, in run
iflen(inputs[key].size())==1:
TypeError: 'int' object is not callable
Here's the code.
import torch
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 include.data import get_data_set
import numpy as np
import tensorflow as
train_x, train_y=get_data_set()
_BATCH_SIZE=300
_CLASS_SIZE=6 time=100
network=Network(dt=1.0)
input=input(n=100, sum_input=True)
middle=LIFNodes (n=100, trace=True)
center=LIFNodes (n=100, trace=True)
final=LIFNodes (n=100, trace=True)
out = LIFNodes (n = 100, sum_input = True)
input_middle=connection(source=inpt, target=middle, wmin=0, wmax=1e-1)
middle_center= Connection (source=middle, target=center, wmin=0, wmax=1e-1)
center_final=Connection (source=center, target=final, wmin=0, wmax=1e-1)
final_out=Connection(source=final, target=out, wmin=0, wmax=1e-1)network.add_layer(inpt,name='A')
network.add_layer(middle, name='B')
network.add_layer(center,name='C')
network.add_layer(final, name='D')
network.add_layer(out,name='E')
forward_connection=Connection(source=inpt, target=middle, w=0.05+0.1*torch.randn(inpt.n,
middle.n))
network.add_connection(connection=forward_connection, source="A", target="B")
forward_connection=Connection(source=middle, target=center, w=0.05+0.1*torch.randn(middle.n,
center.n))
network.add_connection(connection=forward_connection, source="B", target="C")
forward_connection=Connection(source=center, target=final, w=0.05+0.1*torch.randn(center.n,
final.n))
network.add_connection(connection=forward_connection, source="C", target="D")
forward_connection=Connection(source=final, target=out, w=0.05+0.1*torch.randn(final.n, out.n))
network.add_connection(connection=forward_connection, source="D", target="E")
current_connection=Connection(source=out, target=out, w=0.025*(torch.eye(out.n)-1), )
network.add_connection(connection=current_connection, source="E", target="E")
apt_monitor=Monitor(obj=impt, state_vars=("s", "v"), time=500, )
middle_monitor=Monitor(obj=impt, state_vars=("s", "v"), time=500, )
center_monitor=Monitor(obj=impt, state_vars=("s", "v"), time=500, )
final_monitor=Monitor(obj=impt, state_vars=("s", "v"), time=500, )
out_monitor=Monitor(obj=impt, state_vars=("s", "v"), time=500, )
orlin network.layers:
m=Monitor(network.layers[l], state_vars=['s'], time=time)
network.add_monitor(m,name=l)
# network.to ('cuda')
# load training data
# data_set=np.load("C:/Users/namae/Desktop/myo-python-1.0.4/myo-armband-nn-
master/data/train_set.npz")
npzfile=np.load("C:/Users/namae/Desktop/myo-python-1.0.4/myo-armband-nn-master/data/train_set.npz")
x = npzfile ['x']
y=npzfile['y']
loader=zip(x,y)
def model(_NUM_CLASSES=4):
x=tf.placeholder(tf.float32,shape=[None,64],name='Input')
y=tf.placeholder(tf.float32,shape=[None,_NUM_CLASSES], name='Output')
return x,y
grads = {}
lr,lr_decay = 1e-2,0.95
criterion=torch.nn.CrossEntropyLoss()
for i in enumerate (zip(x,y)) :
inputs = {'A':x.repeat(time,1), 'E_b':torch.ones(time,1)}
network.run(inputs=inputs, time=time) ここ Here it is.
y=torch.tensor(y).long()
spikes={l:network.monitor[l].get('s') for lin network.layers}
summarized_inputs={l:network.layer[l].summed for lin network.layer}
output=spikes ['E'].sum(-1.softmax(0)
predicted=output.argmax(1).item()
# Loss and SGD Updates
grads['dl/df'] = summed_inputs['E'].softmax(0)
grads ['dl/df'] [y] - = 1
grads['dl/dw'] = torch.ger (summed_inputs['A', grads['dl/df'])
network.connections ['A', 'E'].w-=lr*grads ['dl/dw']
# damping rate
if i>0 and i%500 == 0:
lr = lr_decay
network.reset()
iflen(inputs[key].size())==1:
TypeError: 'int' object is not callable
The int object cannot be called, so
You might want to review the line.
What's in inputs[key].size?
© 2024 OneMinuteCode. All rights reserved.