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

코드 실해 해봤는데 # 정책신경망을 업데이트하는 훈련함수 생성 부분에서 에러가 나요 #59

Open
Cinofe opened this issue Aug 5, 2021 · 4 comments

Comments

@Cinofe
Copy link

Cinofe commented Aug 5, 2021

에러 내용 : 예외가 발생했습니다. TypeError
get_updates() takes 3 positional arguments but 4 were given
File "D:\seungwan\Desktop\AI_Study\AI_Reference\reinforcement-learning-kr-master\1-grid-world\7-reinforce\reinforce_agent.py", line 52, in optimizer
updates = optimizer.get_updates(self.model.trainable_weights, [], loss)
File "D:\seungwan\Desktop\AI_Study\AI_Reference\reinforcement-learning-kr-master\1-grid-world\7-reinforce\reinforce_agent.py", line 25, in init
self.optimizer = self.optimizer()
File "D:\seungwan\Desktop\AI_Study\AI_Reference\reinforcement-learning-kr-master\1-grid-world\7-reinforce\reinforce_agent.py", line 92, in
agent = ReinforceAgent()

@swkim01
Copy link

swkim01 commented Nov 30, 2021

버전이 업데이트되면서 get_updates 함수 옵션 순서와 갯수가 바뀌었습니다. 다음과 같이 해야 합니다.
updates = optimizer.get_updates(loss, self.model.trainable_weights)

@Cinofe
Copy link
Author

Cinofe commented Nov 30, 2021 via email

@hdw1215
Copy link

hdw1215 commented Jan 17, 2022

안녕하세요, 저도 기존 질문과 같은 에러가 있어서 말씀하신대로
updates = optimizer.get_updates(loss, self.model.trainable_weights)

위 코드로 변환하였습니다.

그랬더니,

TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, 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.

위와 같은 에러가 발생하는데.. numpy 최신버전으로 설치해도 동일한 에러가 발생합니다.

혹시 get_updates 뿐만 아니라 다른 코드들도 수정해줘야하나요?

=============================================
1/17

from tensorflow.python.framework.ops import disable_eager_execution
disable_eager_execution()

위 코드 입력하니까

TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, 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.

에러는 사라졌는데, 이제는 get_update 코드 아래 줄

train = K.function([self.model.input, action, discounted_rewards], [], updates = updates)

위 코드가 문제입니다..

@swkim01
Copy link

swkim01 commented Jan 17, 2022

안녕하세요, 저도 기존 질문과 같은 에러가 있어서 말씀하신대로 updates = optimizer.get_updates(loss, self.model.trainable_weights)

위 코드로 변환하였습니다.

그랬더니,

TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, 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.

위와 같은 에러가 발생하는데.. numpy 최신버전으로 설치해도 동일한 에러가 발생합니다.

혹시 get_updates 뿐만 아니라 다른 코드들도 수정해줘야하나요?

============================================= 1/17

from tensorflow.python.framework.ops import disable_eager_execution
disable_eager_execution()

위 코드 입력하니까

TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, 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.

에러는 사라졌는데, 이제는 get_update 코드 아래 줄

train = K.function([self.model.input, action, discounted_rewards], [], updates = updates)

위 코드가 문제입니다..

다음과 같이 수정해 보시기 바랍니다.
train = K.function([self.model.input, action, discounted_rewards], [loss], updates = updates)

또, 아래 정책신경망_ 업데이트 함수 train_model 에서 다음과 같이 수정해야 할 겁니다.
self.optimizer([np.array(self.states), np.array(self.actions), np.array(discounted_rewards)])

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

3 participants