Errors running nengo example CNN ciphar10

Hi all,
I’m running into this error:
AttributeError: ‘functools.partial’ object has no attribute ‘name
when trying to run the without the try exeption , this is the output :

Build finished in 0:00:00                                                      
Optimization finished in 0:00:00                                               
Construction finished in 0:00:04                                               
Loaded params './cifar10_convnet_params'
Constructing graph: build stage finished in 0:00:02                            
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-984d98431c7e> in <module>
    115     # try:
    116     train_slice = slice(0, 1024)
--> 117     train_outputs = sim.evaluate(
    118         x=slice_data_dict(train_inputs, train_slice),
    119         y=slice_data_dict(train_targets, train_slice),

~\anaconda3\lib\site-packages\nengo\utils\magic.py in __call__(self, *args, **kwargs)
    179                 return self.wrapper(wrapped, instance, args, kwargs)
    180             else:
--> 181                 return self.wrapper(self.__wrapped__, self.instance, args, kwargs)
    182         else:
    183             instance = getattr(self.__wrapped__, "__self__", None)

~\anaconda3\lib\site-packages\nengo_dl\simulator.py in require_open(wrapped, instance, args, kwargs)
     65         )
     66 
---> 67     return wrapped(*args, **kwargs)
     68 
     69 

~\anaconda3\lib\site-packages\nengo_dl\simulator.py in evaluate(self, x, y, n_steps, stateful, **kwargs)
    903         """
    904 
--> 905         return self._call_keras(
    906             "evaluate", x=x, y=y, n_steps=n_steps, stateful=stateful, **kwargs
    907         )

~\anaconda3\lib\site-packages\nengo\utils\magic.py in __call__(self, *args, **kwargs)
    179                 return self.wrapper(wrapped, instance, args, kwargs)
    180             else:
--> 181                 return self.wrapper(self.__wrapped__, self.instance, args, kwargs)
    182         else:
    183             instance = getattr(self.__wrapped__, "__self__", None)

~\anaconda3\lib\site-packages\nengo_dl\simulator.py in with_self(wrapped, instance, args, kwargs)
     48     try:
     49         with tf.device(instance.tensor_graph.device):
---> 50             output = wrapped(*args, **kwargs)
     51     finally:
     52         tf.keras.backend.set_floatx(keras_dtype)

~\anaconda3\lib\site-packages\nengo_dl\simulator.py in _call_keras(self, func_type, x, y, n_steps, stateful, **kwargs)
   1042             func_args = dict(x=x, y=y, **kwargs)
   1043 
-> 1044         outputs = getattr(self.keras_model, func_type)(**func_args)
   1045 
   1046         # update n_steps/time

~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in evaluate(self, x, y, batch_size, verbose, sample_weight, steps, callbacks, max_queue_size, workers, use_multiprocessing, return_dict)
   1387             with trace.Trace('test', step_num=step, _r=1):
   1388               callbacks.on_test_batch_begin(step)
-> 1389               tmp_logs = self.test_function(iterator)
   1390               if data_handler.should_sync:
   1391                 context.async_wait()

~\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py in __call__(self, *args, **kwds)
    826     tracing_count = self.experimental_get_tracing_count()
    827     with trace.Trace(self._name) as tm:
--> 828       result = self._call(*args, **kwds)
    829       compiler = "xla" if self._experimental_compile else "nonXla"
    830       new_tracing_count = self.experimental_get_tracing_count()

~\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py in _call(self, *args, **kwds)
    869       # This is the first call of __call__, so we have to initialize.
    870       initializers = []
--> 871       self._initialize(args, kwds, add_initializers_to=initializers)
    872     finally:
    873       # At this point we know that the initialization is complete (or less

~\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py in _initialize(self, args, kwds, add_initializers_to)
    723     self._graph_deleter = FunctionDeleter(self._lifted_initializer_graph)
    724     self._concrete_stateful_fn = (
--> 725         self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
    726             *args, **kwds))
    727 

~\anaconda3\lib\site-packages\tensorflow\python\eager\function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
   2967       args, kwargs = None, None
   2968     with self._lock:
-> 2969       graph_function, _ = self._maybe_define_function(args, kwargs)
   2970     return graph_function
   2971 

~\anaconda3\lib\site-packages\tensorflow\python\eager\function.py in _maybe_define_function(self, args, kwargs)
   3359 
   3360           self._function_cache.missed.add(call_context_key)
-> 3361           graph_function = self._create_graph_function(args, kwargs)
   3362           self._function_cache.primary[cache_key] = graph_function
   3363 

~\anaconda3\lib\site-packages\tensorflow\python\eager\function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes)
   3194     arg_names = base_arg_names + missing_arg_names
   3195     graph_function = ConcreteFunction(
-> 3196         func_graph_module.func_graph_from_py_func(
   3197             self._name,
   3198             self._python_function,

~\anaconda3\lib\site-packages\tensorflow\python\framework\func_graph.py in func_graph_from_py_func(name, python_func, args, kwargs, signature, func_graph, autograph, autograph_options, add_control_dependencies, arg_names, op_return_value, collections, capture_by_value, override_flat_arg_shapes)
    988         _, original_func = tf_decorator.unwrap(python_func)
    989 
--> 990       func_outputs = python_func(*func_args, **func_kwargs)
    991 
    992       # invariant: `func_outputs` contains only Tensors, CompositeTensors,

~\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py in wrapped_fn(*args, **kwds)
    632             xla_context.Exit()
    633         else:
--> 634           out = weak_wrapped_fn().__wrapped__(*args, **kwds)
    635         return out
    636 

~\anaconda3\lib\site-packages\tensorflow\python\framework\func_graph.py in wrapper(*args, **kwargs)
    975           except Exception as e:  # pylint:disable=broad-except
    976             if hasattr(e, "ag_error_metadata"):
--> 977               raise e.ag_error_metadata.to_exception(e)
    978             else:
    979               raise

AttributeError: in user code:

    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:1233 test_function  *
        return step_function(self, iterator)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:1224 step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:1259 run
        return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2730 call_for_each_replica
        return self._call_for_each_replica(fn, args, kwargs)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:3417 _call_for_each_replica
        return fn(*args, **kwargs)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:1217 run_step  **
        outputs = model.test_step(data)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:1185 test_step
        self.compiled_loss(
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\compile_utils.py:186 __call__
        self.build(y_pred)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\compile_utils.py:139 build
        self._losses = nest.map_structure(self._get_loss_object, self._losses)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\util\nest.py:659 map_structure
        structure[0], [func(*x) for x in entries],
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\util\nest.py:659 <listcomp>
        structure[0], [func(*x) for x in entries],
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\compile_utils.py:264 _get_loss_object
        loss_name = loss.__name__

    AttributeError: 'functools.partial' object has no attribute '__name__'

Also,
there is a #bug in the code:

where it has train_slice = slice(0, 1000)
needs to be replaced by train_slice = slice(0, 1024) so it can be divisible by batch_size = 256.
the same below, on test_slice.

Hi @aeon, and welcome to the Nengo forums! :smiley:

To better facilitate the debugging process, can you provide the following information:

  • Which example are you encountering this error in? (i.e., which repository, and in which directory)
  • What Python version do you have running? You can get this information by doing python --version in a terminal.
  • What versions of Nengo and the various Python packages do you have installed? You can get this information by doing pip freeze in a terminal.

centainly.
here it is: python 3.8.5

modules:
absl-py==0.11.0
alabaster==0.7.12
anaconda-client==1.7.2
anaconda-navigator==1.9.12
anaconda-project==0.8.3
argh==0.26.2
argon2-cffi @ file:///C:/ci/argon2-cffi_1596828585465/work
asn1crypto @ file:///tmp/build/80754af9/asn1crypto_1596577642040/work
astroid @ file:///C:/ci/astroid_1592487315634/work
astropy==4.0.1.post1
astunparse==1.6.3
atomicwrites==1.4.0
attrs==19.3.0
autopep8 @ file:///tmp/build/80754af9/autopep8_1596578164842/work
Babel==2.8.0
backcall==0.2.0
backports.functools-lru-cache==1.6.1
backports.shutil-get-terminal-size==1.0.0
backports.tempfile==1.0
backports.weakref==1.0.post1
bcrypt==3.1.7
beautifulsoup4==4.9.1
bitarray @ file:///C:/ci/bitarray_1596090623822/work
bkcharts==0.2
bleach==3.1.5
bokeh @ file:///C:/ci/bokeh_1593178781838/work
boto==2.49.0
Bottleneck==1.3.2
Box2D==2.3.10
brotlipy==0.7.0
cachetools==4.1.1
certifi==2020.12.5
cffi==1.14.0
chardet==3.0.4
click==7.1.2
cloudpickle @ file:///tmp/build/80754af9/cloudpickle_1594141588948/work
clyent==1.2.2
colorama==0.4.3
colorclass==2.2.0
comtypes==1.1.7
conda==4.9.2
conda-build==3.18.11
conda-package-handling==1.7.0
conda-verify==3.4.2
contextlib2==0.6.0.post1
cryptography==2.9.2
cycler==0.10.0
Cython @ file:///C:/ci/cython_1594829190914/work
cytoolz==0.10.1
dask @ file:///tmp/build/80754af9/dask-core_1594156306305/work
decorator==4.4.2
defusedxml==0.6.0
diff-match-patch @ file:///tmp/build/80754af9/diff-match-patch_1594828741838/work
dill==0.3.3
distributed @ file:///C:/ci/distributed_1594742844291/work
dlx==1.0.4
dm-tree==0.1.5
docplex==2.15.194
docutils==0.16
entrypoints==0.3
et-xmlfile==1.0.1
fastcache==1.1.0
fastdtw==0.3.4
fastjsonschema==2.15.0
filelock==3.0.12
flake8==3.8.3
Flask==1.1.2
flatbuffers==1.12
fsspec==0.7.4
future==0.18.2
gast==0.3.3
gevent @ file:///C:/ci/gevent_1593005471151/work
glfw==2.0.0
glob2==0.7
gmpy2==2.0.8
google-auth==1.20.0
google-auth-oauthlib==0.4.1
google-pasta==0.2.0
greenlet==0.4.16
grpcio==1.32.0
gym==0.18.0
h5py==2.10.0
HeapDict==1.0.1
html5lib @ file:///tmp/build/80754af9/html5lib_1593446221756/work
idna @ file:///tmp/build/80754af9/idna_1593446292537/work
image-dataset-loader==0.0.0
imageio @ file:///tmp/build/80754af9/imageio_1594161405741/work
imagesize==1.2.0
importlib-metadata @ file:///C:/ci/importlib-metadata_1593446511143/work
inflection==0.5.1
iniconfig @ file:///tmp/build/80754af9/iniconfig_1596827328212/work
intervaltree @ file:///tmp/build/80754af9/intervaltree_1594361675072/work
ipykernel @ file:///C:/ci/ipykernel_1596190155316/work/dist/ipykernel-5.3.4-py3-none-any.whl
ipython @ file:///C:/ci/ipython_1593447482397/work
ipython-genutils==0.2.0
ipywidgets==7.5.1
isort==4.3.21
itsdangerous==1.1.0
jdcal==1.4.1
jedi @ file:///C:/ci/jedi_1592833825077/work
Jinja2==2.11.2
joblib @ file:///tmp/build/80754af9/joblib_1594236160679/work
json5==0.9.5
jsonschema==3.2.0
jupyter==1.0.0
jupyter-client @ file:///tmp/build/80754af9/jupyter_client_1594826976318/work
jupyter-console==6.1.0
jupyter-core==4.6.3
jupyterlab==2.1.5
jupyterlab-server @ file:///tmp/build/80754af9/jupyterlab_server_1594164409481/work
Keras-Preprocessing==1.1.2
keyring @ file:///C:/ci/keyring_1593109799227/work
kiwisolver==1.2.0
lazy-object-proxy==1.4.3
libarchive-c==2.9
llvmlite==0.33.0+1.g022ab0f
locket==0.2.0
lockfile==0.12.2
lxml @ file:///C:/ci/lxml_1594822774489/work
Markdown==3.2.2
MarkupSafe==1.1.1
matplotlib @ file:///C:/ci/matplotlib-base_1592837548929/work
mccabe==0.6.1
menuinst==1.4.16
mistune==0.8.4
mkl-fft==1.1.0
mkl-random==1.1.1
mkl-service==2.3.0
mlxtend==0.18.0
mock==4.0.2
more-itertools==8.4.0
mpmath==1.1.0
msgpack==1.0.0
multipledispatch==0.6.0
multitasking==0.0.9
navigator-updater==0.2.1
nbconvert==5.6.1
nbformat==5.0.7
nengo==3.1.0
nengo-dl==3.4.0
nengo-gui==0.4.7
nengo-loihi==1.0.0
nest-asyncio==1.5.1
networkx @ file:///tmp/build/80754af9/networkx_1594377231366/work
nltk @ file:///tmp/build/80754af9/nltk_1592496090529/work
nose==1.3.7
notebook @ file:///C:/ci/notebook_1596840175976/work
ntlm-auth==1.5.0
numba==0.50.1
numexpr==2.7.1
numpy==1.19.5
numpydoc @ file:///tmp/build/80754af9/numpydoc_1594166760263/work
oauthlib==3.1.0
olefile==0.46
opencv-python==4.5.1.48
openpyxl @ file:///tmp/build/80754af9/openpyxl_1594167385094/work
opt-einsum==3.3.0
packaging==20.4
pandas @ file:///C:/ci/pandas_1596824377390/work
pandocfilters==1.4.2
paramiko==2.7.1
parso==0.7.0
partd==1.1.0
path==13.1.0
pathlib2==2.3.5
pathtools==0.1.2
patsy==0.5.1
pep8==1.7.1
pexpect==4.8.0
pickleshare==0.7.5
Pillow @ file:///C:/ci/pillow_1594298230227/work
pip-check==2.6
pkginfo==1.5.0.1
pluggy==0.13.1
ply==3.11
progressbar2==3.53.1
prometheus-client==0.8.0
prompt-toolkit==3.0.5
protobuf==3.12.4
psutil==5.7.0
py @ file:///tmp/build/80754af9/py_1593446248552/work
pyasn1==0.4.8
pyasn1-modules==0.2.8
pybind11==2.6.2
pycodestyle==2.6.0
pycosat==0.6.3
pycparser @ file:///tmp/build/80754af9/pycparser_1594388511720/work
pycurl==7.43.0.5
pydocstyle @ file:///tmp/build/80754af9/pydocstyle_1592848020240/work
pydot==1.4.1
pyflakes==2.2.0
pyglet==1.5.0
Pygments==2.6.1
pylatexenc==2.8
pylint @ file:///C:/ci/pylint_1592482039483/work
PyNaCl @ file:///C:/ci/pynacl_1595000047588/work
pyodbc===4.0.0-unsupported
pyOpenSSL @ file:///tmp/build/80754af9/pyopenssl_1594392929924/work
pyparsing==2.4.7
pyreadline==2.1
pyrsistent==0.16.0
PySocks==1.7.1
pystan==2.18.0.0
pytest==6.0.1
python-constraint==1.4.0
python-dateutil==2.8.1
python-jsonrpc-server @ file:///tmp/build/80754af9/python-jsonrpc-server_1594397536060/work
python-language-server @ file:///C:/ci/python-language-server_1594162130238/work
python-utils==2.5.6
pytz==2020.1
PyWavelets==1.1.1
pywin32==227
pywin32-ctypes==0.2.0
pywinpty==0.5.7
PyYAML==5.3.1
pyzmq==19.0.1
QDarkStyle==2.8.1
qiskit==0.23.6
qiskit-aer==0.7.5
qiskit-aqua==0.8.2
qiskit-ibmq-provider==0.11.1
qiskit-ignis==0.5.2
qiskit-terra==0.16.4
QtAwesome==0.7.2
qtconsole @ file:///tmp/build/80754af9/qtconsole_1592848611704/work
QtPy==1.9.0
Quandl==3.6.0
regex @ file:///C:/ci/regex_1596811715751/work
requests @ file:///tmp/build/80754af9/requests_1592841827918/work
requests-ntlm==1.1.0
requests-oauthlib==1.3.0
retworkx==0.7.2
rope==0.17.0
rsa==4.6
Rtree==0.9.4
ruamel-yaml==0.15.87
scikit-image==0.16.2
scikit-learn @ file:///C:/ci/scikit-learn_1592853510272/work
scipy==1.4.1
seaborn==0.10.1
Send2Trash==1.5.0
simplegeneric==0.8.1
singledispatch==3.4.0.3
sip==4.19.13
six==1.15.0
snowballstemmer==2.0.0
sortedcollections==1.2.1
sortedcontainers==2.2.2
soupsieve==2.0.1
Sphinx @ file:///tmp/build/80754af9/sphinx_1597428793432/work
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
sphinxcontrib-websupport @ file:///tmp/build/80754af9/sphinxcontrib-websupport_1597081412696/work
spyder @ file:///C:/ci/spyder_1594830825244/work
spyder-kernels @ file:///C:/ci/spyder-kernels_1594751670175/work
SQLAlchemy @ file:///C:/ci/sqlalchemy_1593445271541/work
statsmodels==0.11.1
sympy @ file:///C:/ci/sympy_1594234545115/work
tables==3.6.1
tblib==1.6.0
tensorboard==2.4.1
tensorboard-plugin-wit==1.7.0
tensorflow==2.4.1
tensorflow-estimator==2.4.0
tensorflow-probability==0.12.1
termcolor==1.1.0
terminado==0.8.3
terminaltables==3.1.0
testpath==0.4.4
threadpoolctl @ file:///tmp/tmp9twdgx9k/threadpoolctl-2.1.0-py3-none-any.whl
toml @ file:///tmp/build/80754af9/toml_1592853716807/work
toolz==0.10.0
tornado==6.0.4
tqdm @ file:///tmp/build/80754af9/tqdm_1596810128862/work
traitlets==4.3.3
typing-extensions @ file:///tmp/build/80754af9/typing_extensions_1592847887441/work
ujson==1.35
unicodecsv==0.14.1
urllib3 @ file:///tmp/build/80754af9/urllib3_1597086586889/work
watchdog @ file:///C:/ci/watchdog_1593447437088/work
wcwidth @ file:///tmp/build/80754af9/wcwidth_1593447189090/work
webencodings==0.5.1
websockets==8.1
Werkzeug==1.0.1
widgetsnbextension==3.5.1
win-inet-pton==1.1.0
win-unicode-console==0.5
wincertstore==0.2
wrapt==1.12.1
xlrd==1.2.0
XlsxWriter==1.2.9
xlwings==0.19.5
xlwt==1.3.0
xmltodict==0.12.0
yapf @ file:///tmp/build/80754af9/yapf_1593528177422/work
yellowbrick==1.2.1
yfinance==0.1.55
zict==2.0.0
zipp==3.1.0
zope.event==4.4
zope.interface==4.7.1

Thanks for the system information. :slight_smile:
Can you also provide the link to the example you are running? I’ll attempt to replicate your environment to see if I encounter the same issue.

sure.
you can download the Jupyter notebook here:
http://aeonlabs.solutions/downloads/Neuromorphic_Transfer_Learning.ipynb

and i thank you too.

I’m getting the following errors on running the CNN cifar 10 example code from the website, after this line of code:
(thank you in advance)

# use rate neurons always by setting learning_phase_scope
with tf.keras.backend.learning_phase_scope(1), nengo_dl.Simulator(

I've added the following prints for better understanding:
Build finished in 0:00:00                                                      
Optimization finished in 0:00:00                                               
Construction finished in 0:00:01                                               
starting training...
y_keys:
['output_p', 'input-layer_p', 'conv-layer1_p', 'conv-layer2_p', 'conv-layer3_p', 'conv-layer4_p', 'conv-layer5_p', 'dense-layer_p']
Y type:
<class 'list'>
X type:
<class 'list'>
train X shape:
(50000, 32, 32, 3)
train t shape:
(50000, 10)

train X:
[[[[-0.9999385  -0.9961553  -0.9965244 ]
   [-0.99996924 -0.9987697  -0.9973856 ]
   [-0.9996617  -0.9969858  -0.99701655]
   ...
   [-0.9976932  -0.9997232  -0.9976932 ]
   [-0.9997232  -0.9976932  -0.9997232 ]
   [-0.9976932  -0.99990773 -0.9976932 ]]

  [[-0.9999385  -0.9976932  -0.99981546]
   [-0.9976932  -0.999877   -0.9976932 ]
   [-0.99990773 -0.9976932  -0.99981546]
   ...
   [-0.9976932  -0.99975395 -0.9976932 ]
   [-0.9999385  -0.9976932  -0.99996924]
   [-0.9976932  -0.99996924 -0.9976932 ]]

  [[-0.999877   -0.9976932  -0.9997232 ]
   [-0.9976932  -0.9997847  -0.9976932 ]
   [-0.99975395 -0.9976932  -0.9998462 ]
   ...
   [-0.9976932  -0.9997232  -0.9976932 ]
   [-0.99975395 -0.9976932  -0.99996924]
   [-0.9976932  -0.9997847  -0.9976932 ]]

  ...
train t:
[[0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 1.]
 [0. 0. 0. ... 0. 0. 0.]
 ...
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]]

Constructing graph: build stage finished in 0:00:01      

the error output is:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-9c9fe265cc41> in <module>
     99 
    100         for epoch in range(n_epochs):
--> 101             sim.fit(
    102                 train_data,
    103                 steps_per_epoch=steps_per_epoch,

~\anaconda3\lib\site-packages\nengo\utils\magic.py in __call__(self, *args, **kwargs)
    179                 return self.wrapper(wrapped, instance, args, kwargs)
    180             else:
--> 181                 return self.wrapper(self.__wrapped__, self.instance, args, kwargs)
    182         else:
    183             instance = getattr(self.__wrapped__, "__self__", None)

~\anaconda3\lib\site-packages\nengo_dl\simulator.py in require_open(wrapped, instance, args, kwargs)
     65         )
     66 
---> 67     return wrapped(*args, **kwargs)
     68 
     69 

~\anaconda3\lib\site-packages\nengo_dl\simulator.py in fit(self, x, y, n_steps, stateful, **kwargs)
    866                 kwargs["validation_data"] = (x_val, y_val, validation_data[2])
    867 
--> 868         return self._call_keras(
    869             "fit", x=x, y=y, n_steps=n_steps, stateful=stateful, **kwargs
    870         )

~\anaconda3\lib\site-packages\nengo\utils\magic.py in __call__(self, *args, **kwargs)
    179                 return self.wrapper(wrapped, instance, args, kwargs)
    180             else:
--> 181                 return self.wrapper(self.__wrapped__, self.instance, args, kwargs)
    182         else:
    183             instance = getattr(self.__wrapped__, "__self__", None)

~\anaconda3\lib\site-packages\nengo_dl\simulator.py in with_self(wrapped, instance, args, kwargs)
     48     try:
     49         with tf.device(instance.tensor_graph.device):
---> 50             output = wrapped(*args, **kwargs)
     51     finally:
     52         tf.keras.backend.set_floatx(keras_dtype)

~\anaconda3\lib\site-packages\nengo_dl\simulator.py in _call_keras(self, func_type, x, y, n_steps, stateful, **kwargs)
   1042             func_args = dict(x=x, y=y, **kwargs)
   1043 
-> 1044         outputs = getattr(self.keras_model, func_type)(**func_args)
   1045 
   1046         # update n_steps/time

~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
   1098                 _r=1):
   1099               callbacks.on_train_batch_begin(step)
-> 1100               tmp_logs = self.train_function(iterator)
   1101               if data_handler.should_sync:
   1102                 context.async_wait()

~\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py in __call__(self, *args, **kwds)
    826     tracing_count = self.experimental_get_tracing_count()
    827     with trace.Trace(self._name) as tm:
--> 828       result = self._call(*args, **kwds)
    829       compiler = "xla" if self._experimental_compile else "nonXla"
    830       new_tracing_count = self.experimental_get_tracing_count()

~\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py in _call(self, *args, **kwds)
    869       # This is the first call of __call__, so we have to initialize.
    870       initializers = []
--> 871       self._initialize(args, kwds, add_initializers_to=initializers)
    872     finally:
    873       # At this point we know that the initialization is complete (or less

~\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py in _initialize(self, args, kwds, add_initializers_to)
    723     self._graph_deleter = FunctionDeleter(self._lifted_initializer_graph)
    724     self._concrete_stateful_fn = (
--> 725         self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
    726             *args, **kwds))
    727 

~\anaconda3\lib\site-packages\tensorflow\python\eager\function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
   2967       args, kwargs = None, None
   2968     with self._lock:
-> 2969       graph_function, _ = self._maybe_define_function(args, kwargs)
   2970     return graph_function
   2971 

~\anaconda3\lib\site-packages\tensorflow\python\eager\function.py in _maybe_define_function(self, args, kwargs)
   3359 
   3360           self._function_cache.missed.add(call_context_key)
-> 3361           graph_function = self._create_graph_function(args, kwargs)
   3362           self._function_cache.primary[cache_key] = graph_function
   3363 

~\anaconda3\lib\site-packages\tensorflow\python\eager\function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes)
   3194     arg_names = base_arg_names + missing_arg_names
   3195     graph_function = ConcreteFunction(
-> 3196         func_graph_module.func_graph_from_py_func(
   3197             self._name,
   3198             self._python_function,

~\anaconda3\lib\site-packages\tensorflow\python\framework\func_graph.py in func_graph_from_py_func(name, python_func, args, kwargs, signature, func_graph, autograph, autograph_options, add_control_dependencies, arg_names, op_return_value, collections, capture_by_value, override_flat_arg_shapes)
    988         _, original_func = tf_decorator.unwrap(python_func)
    989 
--> 990       func_outputs = python_func(*func_args, **func_kwargs)
    991 
    992       # invariant: `func_outputs` contains only Tensors, CompositeTensors,

~\anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py in wrapped_fn(*args, **kwds)
    632             xla_context.Exit()
    633         else:
--> 634           out = weak_wrapped_fn().__wrapped__(*args, **kwds)
    635         return out
    636 

~\anaconda3\lib\site-packages\tensorflow\python\framework\func_graph.py in wrapper(*args, **kwargs)
    975           except Exception as e:  # pylint:disable=broad-except
    976             if hasattr(e, "ag_error_metadata"):
--> 977               raise e.ag_error_metadata.to_exception(e)
    978             else:
    979               raise

AttributeError: in user code:

    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:805 train_function  *
        return step_function(self, iterator)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:795 step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:1259 run
        return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:2730 call_for_each_replica
        return self._call_for_each_replica(fn, args, kwargs)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\distribute\distribute_lib.py:3417 _call_for_each_replica
        return fn(*args, **kwargs)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:788 run_step  **
        outputs = model.train_step(data)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py:755 train_step
        loss = self.compiled_loss(
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\compile_utils.py:186 __call__
        self.build(y_pred)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\compile_utils.py:139 build
        self._losses = nest.map_structure(self._get_loss_object, self._losses)
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\util\nest.py:659 map_structure
        structure[0], [func(*x) for x in entries],
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\util\nest.py:659 <listcomp>
        structure[0], [func(*x) for x in entries],
    C:\Users\Aeon\anaconda3\lib\site-packages\tensorflow\python\keras\engine\compile_utils.py:264 _get_loss_object
        loss_name = loss.__name__

    AttributeError: 'functools.partial' object has no attribute '__name__'

I’ve moved this post here as well because it seems to be the same error as your other script, so the solution should be the same.

Hello @aeon, I believe you are referring to the example here: CIFAR-10 convolutional network — NengoLoihi 1.1.0.dev0 docs . Well… I also incurred the same issue i.e. AttributeError: 'functools.partial' object has no attribute '__name__' few weeks ago in the same tutorial, and that’s probably because our latest version of Python (I am on 3.7.7) has got something “wrong” with the partial function objects. I just didn’t bother to look further in the actual issue, but I caught the problem that it is with the partial function declaration in the following code snippet:

if layer_conf.get("on_chip", True):
            losses[probe] = partial(
                percentile_l2_loss_range,
                min_rate=0.5 * rate_target,
                max_rate=rate_target,
                percentile=percentile,
            )
            loss_weights[probe] = rate_reg
        else:
            losses[probe] = partial(
                percentile_l2_loss_range,
                min_rate=0,
                max_rate=rate_target,
                percentile=percentile,
            )

To get rid of the issue, I simply modified my code to not use the partial declaration of percentile_l2_loss_range, rather called the function percentile_l2_loss_range with desired fixed parameters. More info about the partial functions here in case you aren’t aware of them. Hope this helps!

Hi @aeon, @zerone

It seems like this issue was introduced in TensorFlow 2.2.0 and hasn’t been addressed by the TF team.

I’ve create a corresponding Github issue on the NengoLoihi github so that the devs can fix the example by rewriting the portion of the affected code. In the mean time, you can fix this in the code yourself by replacing the partial call with something like a lambda function call (what @zerone implied by “calling the function percentile_l2_loss_range with desired fixed parameters”).
As an example, convert this partial function call:

losses[probe] = partial(
    percentile_l2_loss_range,
    min_rate=0.5 * rate_target,
    max_rate=rate_target,
    percentile=percentile,
)

to something like this:

losses[probe] = \
    lambda y_true, y: \
        percentile_l2_loss_range(
            y_true, 
            y,
            min_rate=0.5 * rate_target,
            max_rate=rate_target,
            percentile=percentile
        )

@xchoo , (@zerone),
your code fix is working.
Also, in the meantime found an initialization bug. The batch size needs to be divisible by the test dataset size

one can find a running implementation on Kaggle.
I added some functionalities such as the ability to load the dataset from a local file.

https://www.kaggle.com/migueltoms/neuromorphic-ciphar-10-loihi-comparison-of-results

This is not a bug per se, just that the code is not fully optimized. But, yes, you are correct in pointing out that to avoid the warning, you’ll need to set the batch size and training size to be divisible.