Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue importing keras-rl on tensorflow-macos #380

Open
Sebewe opened this issue Sep 10, 2021 · 4 comments
Open

Issue importing keras-rl on tensorflow-macos #380

Sebewe opened this issue Sep 10, 2021 · 4 comments

Comments

@Sebewe
Copy link

Sebewe commented Sep 10, 2021

The tensorflow-macos branch is currently archived so I was hoping someone could help me find a fix for this Import error. Im trying to import keras-rl packages and its throwing errors because TensorFlow does not have a function that keras uses during import. Idk if there's a previous version of keras-rl that would fix this or if I'm kinda just boned until TensorFlow has proper support for the m1 chip. logs below, package versions listed from pip also below. (run on a jupyter notebook and a minforge/conda venv)

jupyter-client 7.0.2
jupyter-core 4.7.1
jupyterlab-pygments 0.1.2
tensorflow-addons-macos 0.1a3
tensorflow-estimator 2.5.0
tensorflow-macos 0.1a3
keras 2.6.0
keras-rl 0.4.2

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten
from tensorflow.keras.optimizers import Adam

from rl.agents.dqn import DQNAgent
from rl.policy import BoltzmannQPolicy
from rl.memory import SequentialMemory

ImportError Traceback (most recent call last)
/var/folders/mt/kt4lp3rx2p37sfswrnyhlkjr0000gn/T/ipykernel_2558/438834739.py in
----> 1 from rl.agents.dqn import DQNAgent
2 from rl.policy import BoltzmannQPolicy
3 from rl.memory import SequentialMemory

~/miniforge3/envs/tensorflow/lib/python3.8/site-packages/rl/agents/init.py in
1 from future import absolute_import
----> 2 from .dqn import DQNAgent, NAFAgent, ContinuousDQNAgent
3 from .ddpg import DDPGAgent
4 from .cem import CEMAgent
5 from .sarsa import SarsaAgent, SARSAAgent

~/miniforge3/envs/tensorflow/lib/python3.8/site-packages/rl/agents/dqn.py in
2 import warnings
3
----> 4 import keras.backend as K
5 from keras.models import Model
6 from keras.layers import Lambda, Input, Layer, Dense

~/miniforge3/envs/tensorflow/lib/python3.8/site-packages/keras/init.py in
23
24 # See b/110718070#comment18 for more details about this import.
---> 25 from keras import models
26
27 from keras.engine.input_layer import Input

~/miniforge3/envs/tensorflow/lib/python3.8/site-packages/keras/models.py in
17
18 import tensorflow.compat.v2 as tf
---> 19 from keras import backend
20 from keras import metrics as metrics_module
21 from keras import optimizer_v1

~/miniforge3/envs/tensorflow/lib/python3.8/site-packages/keras/backend.py in
34 from tensorflow.core.protobuf import config_pb2
35 from tensorflow.python.eager import context
---> 36 from tensorflow.python.eager.context import get_config
37 from tensorflow.python.framework import config
38 from keras import backend_config

ImportError: cannot import name 'get_config' from 'tensorflow.python.eager.context' (/Users/sebastian/miniforge3/envs/tensorflow/lib/python3.8/site-packages/tensorflow/python/eager/context.py)

@Sebewe Sebewe changed the title Issue importing on keras-rl on tensorflow-macos Issue importing keras-rl on tensorflow-macos Sep 10, 2021
@ClaudiuFilip110
Copy link

Hi, I've had some problems with keras-rl and tensorflow and I managed to find a solution to this problem, after hours of trying to figure it out. Hopefully it works for you too.

keras-rl works with tensorflow 1.X, from my understanding, and keras-rl2 is supposed to fix that by requiring tensorflow>=2.1.0. Unfortunately, keras-rl2 is archived, so there can't be anymore fixes. My solution was this:

  1. Download the keras-rl2 source code from here
  2. Go into setup.py and remove the install_requirements=['tensorflow'], line OR you can even change it to tensorflow-macos
  3. Follow the install instructions from source code from here (the keras-rl2 instructions are incomplete)

Once you install keras-rl2 your problems should dissapear.

My issues here these:

  • ERROR: Could not find a version that satisfies the requirement tensorflow (from keras-rl2) (from versions: none) when trying to install keras-rl2
  • ERROR: when trying to do pip install keras-rl2==1.0.5
    Keras symbolic inputs/outputs do not implement __len__. You may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model. This error will also get raised if you try asserting a symbolic input/output directly.

Hopefully this helps.

@IrodaRadjabova
Copy link

hello everyone, can you help me to solve this issue
ImportError Traceback (most recent call last)
Cell In[11], line 5
3 from keras import version
4 tf.keras.version = version
----> 5 from rl.agents import DQNAgent
6 from rl.policy import BoltzmannQPolicy
7 from rl.memory import SequentialMemory

File /opt/anaconda3/envs/py311/lib/python3.11/site-packages/rl/agents/init.py:1
----> 1 from .dqn import DQNAgent, NAFAgent, ContinuousDQNAgent
2 from .ddpg import DDPGAgent
3 from .cem import CEMAgent

File /opt/anaconda3/envs/py311/lib/python3.11/site-packages/rl/agents/dqn.py:8
5 from tensorflow.keras.layers import Lambda, Input, Layer, Dense
7 from rl.core import Agent
----> 8 from rl.policy import EpsGreedyQPolicy, GreedyQPolicy
9 from rl.util import *
12 def mean_q(y_true, y_pred):

File /opt/anaconda3/envs/py311/lib/python3.11/site-packages/rl/policy.py:3
1 import numpy as np
----> 3 from rl.util import *
6 class Policy:
...
----> 3 from tensorflow.keras.models import model_from_config, Sequential, Model, model_from_config
4 import tensorflow.keras.optimizers as optimizers
5 import tensorflow.keras.backend as K

ImportError: cannot import name 'model_from_config' from 'tensorflow.keras.models' (/opt/anaconda3/envs/py311/lib/python3.11/site-packages/keras/_tf_keras/keras/models/init.py)
I've tried to solve this issue in python version 3.9, 3.8, 3.11, 3.10

@ashokkushh
Copy link

hello everyone, can you help me to solve this issue ImportError Traceback (most recent call last) Cell In[11], line 5 3 from keras import version 4 tf.keras.version = version ----> 5 from rl.agents import DQNAgent 6 from rl.policy import BoltzmannQPolicy 7 from rl.memory import SequentialMemory

File /opt/anaconda3/envs/py311/lib/python3.11/site-packages/rl/agents/init.py:1 ----> 1 from .dqn import DQNAgent, NAFAgent, ContinuousDQNAgent 2 from .ddpg import DDPGAgent 3 from .cem import CEMAgent

File /opt/anaconda3/envs/py311/lib/python3.11/site-packages/rl/agents/dqn.py:8 5 from tensorflow.keras.layers import Lambda, Input, Layer, Dense 7 from rl.core import Agent ----> 8 from rl.policy import EpsGreedyQPolicy, GreedyQPolicy 9 from rl.util import * 12 def mean_q(y_true, y_pred):

File /opt/anaconda3/envs/py311/lib/python3.11/site-packages/rl/policy.py:3 1 import numpy as np ----> 3 from rl.util import * 6 class Policy: ... ----> 3 from tensorflow.keras.models import model_from_config, Sequential, Model, model_from_config 4 import tensorflow.keras.optimizers as optimizers 5 import tensorflow.keras.backend as K

ImportError: cannot import name 'model_from_config' from 'tensorflow.keras.models' (/opt/anaconda3/envs/py311/lib/python3.11/site-packages/keras/_tf_keras/keras/models/init.py) I've tried to solve this issue in python version 3.9, 3.8, 3.11, 3.10

do you got it?

@IrodaRadjabova
Copy link

IrodaRadjabova commented Apr 18, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants