AlexanderLutsenko / nobuco

Pytorch to Keras/Tensorflow/TFLite conversion made intuitive
MIT License
263 stars 17 forks source link

ModuleNotFoundError: No module named 'keras.src.engine' #27

Open ivanstepanovftw opened 8 months ago

ivanstepanovftw commented 8 months ago
Traceback (most recent call last):
  File "/p/i/proj/waternet_tf.py", line 5, in <module>
    import nobuco
  File "/p/i/proj/.venv/lib/python3.12/site-packages/nobuco/__init__.py", line 1, in <module>
    from nobuco.converters.channel_ordering import t_pytorch2keras, t_keras2pytorch
  File "/p/i/proj/.venv/lib/python3.12/site-packages/nobuco/converters/channel_ordering.py", line 6, in <module>
    from nobuco.commons import ChannelOrder, TF_TENSOR_CLASSES
  File "/p/i/proj/.venv/lib/python3.12/site-packages/nobuco/commons.py", line 3, in <module>
    from keras.src.engine.keras_tensor import KerasTensor
ModuleNotFoundError: No module named 'keras.src.engine'

Both tensorflow and keras installed.

Python 3.12.2 nobuco 0.12.0 keras 3.0.5 tensorflow 2.16.0rc0 torch 2.2.0

AlexanderLutsenko commented 8 months ago

Hi! Starting with 2.16-rc0, Tensorflow resolves to Keras 3. The new Keras is not fully backward-compatible. Nobuco is tested with 2.15 and will continue to rely on the old Keras 2 until the first stable release of 2.16.

AlexanderLutsenko commented 7 months ago

Transitioning to Keras 3 turned out more complicated than was advertised (see https://github.com/keras-team/keras/issues/19314). I'll get back to it as soon as there is more clarity regarding the new Keras' design.

pedrofrodenas commented 7 months ago

Yes, Indeed keras.src.engine.keras_tensor was moved to from keras.src.backend import KerasTensor . I already tried this but another errors arrise. During model conversion because keras.backend.placeholder was also removed in the newer tensorflow 2.16 version.

AlexanderTekle commented 3 months ago

do we still have to use tensorflow 2.15 to avoid this error?

AlexanderLutsenko commented 3 months ago

@AlexanderTekle Shortly put, yes.

kabyanil commented 3 months ago

Using tensorflow 2.15 works for model conversion, from pytorch to keras. But, I am not able to use tfjs_converted to convert the keras model to tfjs. I tried saving the keras model in both .keras and .h5 format, but it does not seem to work.

johndpope commented 2 weeks ago

folks at google should put some effort in to help here. i really want to use tfjs (bypassing onnx)- and yet getting my code over to tensorflow has been a complete ball breaker.

UPDATE - looking into using this which has pytorch models -> tensorflow lite as of tensorflow 2.17 https://github.com/google-ai-edge/ai-edge-torch