nengo / nengo-dl

Deep learning integration for Nengo
https://www.nengo.ai/nengo-dl
Other
88 stars 22 forks source link

ImportError: cannot import name 'network' from 'tensorflow.python.keras.engine' with TensorFlow 2.3.0 #167

Closed thomastiotto closed 4 years ago

thomastiotto commented 4 years ago

I just compiled TensorFlow 2.3.0 from source but I'm getting the following error when trying to run my code:

Traceback (most recent call last): File "/Users/thomastiotto/opt/anaconda3/envs/nengodl_opt/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3343, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-2-8961a12e9037>", line 1, in <module> runfile('/Users/thomastiotto/PycharmProjects/Memristor_Learning/experiments/test_builder_mPES.py', wdir='/Users/thomastiotto/PycharmProjects/Memristor_Learning/tests') File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/Users/thomastiotto/PycharmProjects/Memristor_Learning/experiments/test_builder_mPES.py", line 2, in <module> import nengo_dl File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "/Users/thomastiotto/opt/anaconda3/envs/nengodl_opt/lib/python3.7/site-packages/nengo_dl/__init__.py", line 58, in <module> from nengo_dl import callbacks, compat, converter, dists, losses File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "/Users/thomastiotto/opt/anaconda3/envs/nengodl_opt/lib/python3.7/site-packages/nengo_dl/callbacks.py", line 20, in <module> from nengo_dl import compat, utils File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs) File "/Users/thomastiotto/opt/anaconda3/envs/nengodl_opt/lib/python3.7/site-packages/nengo_dl/compat.py", line 14, in <module> from tensorflow.python.keras.engine import network ImportError: cannot import name 'network' from 'tensorflow.python.keras.engine' (/Users/thomastiotto/opt/anaconda3/envs/nengodl_opt/lib/python3.7/site-packages/tensorflow/python/keras/engine/__init__.py)

Everything was fine in TensorFlow 2.1.0 so it seems as if something changed internally in either v2.2.0 or 2.3.0 .

drasmuss commented 4 years ago

TF 2.3.0 compatibility was just recently added to NengoDL, so it isn't in the latest release (3.2.0). If you do a developer installation then everything should work. The NengoDL 3.3.0 release should be out within a week or two (there's just a couple other changes we want to get in first).

drasmuss commented 4 years ago

NengoDL 3.3.0 has now been released, so this should be resolved!

thomastiotto commented 4 years ago

Great, but the breaking changes introduced to the build process could have been documented and pointed out :)

drasmuss commented 4 years ago

There is this section in the release notes:

Internal NengoDL OpBuilder classes now separate the "pre build" stage from OpBuilder.__init__ (so that the same OpBuilder class can be re-used across multiple calls, rather than instantiating a new OpBuilder each time). Note that this has no impact on front-end users, this is only relevant to anyone that has implemented a custom build class. The logic that would previously have gone in OpBuilder.__init__ should now go in OpBuilder.build_pre. In addition, the ops argument has been removed from OpBuilder.build_pre; that will be passed to OpBuilder.__init__ ( and will be available in build_pre as self.ops). Similarly, the ops and config argument have been removed from build_post, and can instead be accessed through self.ops/config.

Or is it a different change you are referring to?

thomastiotto commented 4 years ago

Yes, that exactly. I read through the notes but missed that one, sorry!