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

ValueError: Could not find trained model in model_dir: ./output/sa_nn1. #2

Open
mamengyiyi opened this issue Mar 28, 2019 · 6 comments

Comments

@mamengyiyi
Copy link

Hi, thanks for your amazing work. When I tried to run the main.py, it occured this error. How can I resolve it please?Below are the traceback:
Traceback (most recent call last): File "main_with_actor_in_it.py", line 162, in <module> main() File "main_with_actor_in_it.py", line 97, in main actions = env.act(state) File "/home/my/.conda/envs/tensorflow1.8/lib/python3.6/site-packages/pommerman/envs/v0.py", line 137, in act return self.model.act(agents, obs, self.action_space) File "/home/my/.conda/envs/tensorflow1.8/lib/python3.6/site-packages/pommerman/forward_model.py", line 122, in act ret.append(act_ex_communication(agent)) File "/home/my/.conda/envs/tensorflow1.8/lib/python3.6/site-packages/pommerman/forward_model.py", line 101, in act_ex_communication return agent.act(obs[agent.agent_id], action_space=action_space) File "/home/my/playground/magnet/models/ddpg_agent.py", line 98, in act input_to_ddpg = self.__input_to_ddpg__(prev_state, curr_state) File "/home/my/playground/magnet/models/ddpg_agent.py", line 83, in __input_to_ddpg__ graph_predictions = np.asmatrix(list(itertools.islice(y_generator, prev_state.shape[0]))[0]['graph']) File "/home/my/.conda/envs/tensorflow1.8/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 488, in predict self._model_dir)) ValueError: Could not find trained model in model_dir: ./output/sa_nn1.

@tegg89
Copy link
Owner

tegg89 commented Mar 28, 2019

Thank you for having interest in this repo. The code does not have the referred error messages but the deprecated messages have shown. Please check the updated code and try to run via python main.py.

@mamengyiyi
Copy link
Author

mamengyiyi commented Mar 28, 2019

Thank you for having interest in this repo. The code does not have the referred error messages but the deprecated messages have shown. Please check the updated code and try to run via python main.py.

Thank you. It runs well until it restore parameters from ./output/sa_nn1/model.ckpt-3:
报错
It went well when restoring parameters from ./output/sa_nn1/model.ckpt-2 and model.ckpt-1:
2
Why this happened?

@XiongrenChen
Copy link

@mamengyiyi
I also encountered this issue and what I do is to modify the code of ddpg_agent.py like below,
def act(self, obs, action_space):
action = action_space.sample()

    self.prev_state = self.curr_state
    if self.pr_action is not None:
        self.curr_state = state_to_matrix_with_action(obs, action=self.pr_action)

    if self.prev_state is not None:
        curr_state = self.curr_state
        prev_state = self.prev_state

        input_to_ddpg = self.__input_to_ddpg__(prev_state, curr_state)


        curr_state_matrix = self.curr_state
        prev_state_matrix = self.prev_state

#modify start
pred_input_NN1 = tf.estimator.inputs.numpy_input_fn(
x={"state1": prev_state_matrix.astype("float32"),
"state2": curr_state_matrix.astype("float32"),
"y": np.asmatrix(self.graph.flatten())},
y=np.asmatrix(self.graph.flatten()),
batch_size=1,
num_epochs=None,
shuffle=False)
#modify end
# Predict the estimator
y_generator = self.estimator_nn1.predict(input_fn=pred_input_NN1)

        graph_predictions =  np.asmatrix(list(itertools.islice(y_generator, prev_state_matrix.shape[0]))[0])
        input_to_ddpg = np.concatenate([self.curr_state, graph_predictions], axis=1)
        print(input_to_ddpg.shape)
        # action = self.actor.predict(np.expand_dims(input_to_ddpg, 0))[0, 0]

    self.pr_action = action

    return action

@GELIELEO
Copy link

@mamengyiyi
I also encountered this issue and what I do is to modify the code of ddpg_agent.py like below,
def act(self, obs, action_space):
action = action_space.sample()

    self.prev_state = self.curr_state
    if self.pr_action is not None:
        self.curr_state = state_to_matrix_with_action(obs, action=self.pr_action)

    if self.prev_state is not None:
        curr_state = self.curr_state
        prev_state = self.prev_state

        input_to_ddpg = self.__input_to_ddpg__(prev_state, curr_state)


        curr_state_matrix = self.curr_state
        prev_state_matrix = self.prev_state

#modify start
pred_input_NN1 = tf.estimator.inputs.numpy_input_fn(
x={"state1": prev_state_matrix.astype("float32"),
"state2": curr_state_matrix.astype("float32"),
"y": np.asmatrix(self.graph.flatten())},
y=np.asmatrix(self.graph.flatten()),
batch_size=1,
num_epochs=None,
shuffle=False)
#modify end

Predict the estimator

y_generator = self.estimator_nn1.predict(input_fn=pred_input_NN1)

        graph_predictions =  np.asmatrix(list(itertools.islice(y_generator, prev_state_matrix.shape[0]))[0])
        input_to_ddpg = np.concatenate([self.curr_state, graph_predictions], axis=1)
        print(input_to_ddpg.shape)
        # action = self.actor.predict(np.expand_dims(input_to_ddpg, 0))[0, 0]

    self.pr_action = action

    return action

Thank you, it work!

@ZhaoMingYang-tju
Copy link

@mamengyiyi
I also encountered this issue and what I do is to modify the code of ddpg_agent.py like below,
def act(self, obs, action_space):
action = action_space.sample()

    self.prev_state = self.curr_state
    if self.pr_action is not None:
        self.curr_state = state_to_matrix_with_action(obs, action=self.pr_action)

    if self.prev_state is not None:
        curr_state = self.curr_state
        prev_state = self.prev_state

        input_to_ddpg = self.__input_to_ddpg__(prev_state, curr_state)


        curr_state_matrix = self.curr_state
        prev_state_matrix = self.prev_state

#modify start
pred_input_NN1 = tf.estimator.inputs.numpy_input_fn(
x={"state1": prev_state_matrix.astype("float32"),
"state2": curr_state_matrix.astype("float32"),
"y": np.asmatrix(self.graph.flatten())},
y=np.asmatrix(self.graph.flatten()),
batch_size=1,
num_epochs=None,
shuffle=False)
#modify end

Predict the estimator

y_generator = self.estimator_nn1.predict(input_fn=pred_input_NN1)

        graph_predictions =  np.asmatrix(list(itertools.islice(y_generator, prev_state_matrix.shape[0]))[0])
        input_to_ddpg = np.concatenate([self.curr_state, graph_predictions], axis=1)
        print(input_to_ddpg.shape)
        # action = self.actor.predict(np.expand_dims(input_to_ddpg, 0))[0, 0]

    self.pr_action = action

    return action

Thank you, it work!

Excuse me , can you run the project successfully? I still have problem as above..I' ve sent a e-mail to you. Would you like to communicate with me,plz

@Amanda2024
Copy link

@mamengyiyi
I also encountered this issue and what I do is to modify the code of ddpg_agent.py like below,
def act(self, obs, action_space):
action = action_space.sample()

    self.prev_state = self.curr_state
    if self.pr_action is not None:
        self.curr_state = state_to_matrix_with_action(obs, action=self.pr_action)

    if self.prev_state is not None:
        curr_state = self.curr_state
        prev_state = self.prev_state

        input_to_ddpg = self.__input_to_ddpg__(prev_state, curr_state)


        curr_state_matrix = self.curr_state
        prev_state_matrix = self.prev_state

#modify start
pred_input_NN1 = tf.estimator.inputs.numpy_input_fn(
x={"state1": prev_state_matrix.astype("float32"),
"state2": curr_state_matrix.astype("float32"),
"y": np.asmatrix(self.graph.flatten())},
y=np.asmatrix(self.graph.flatten()),
batch_size=1,
num_epochs=None,
shuffle=False)
#modify end

Predict the estimator

y_generator = self.estimator_nn1.predict(input_fn=pred_input_NN1)

        graph_predictions =  np.asmatrix(list(itertools.islice(y_generator, prev_state_matrix.shape[0]))[0])
        input_to_ddpg = np.concatenate([self.curr_state, graph_predictions], axis=1)
        print(input_to_ddpg.shape)
        # action = self.actor.predict(np.expand_dims(input_to_ddpg, 0))[0, 0]

    self.pr_action = action

    return action

Thank you, it work!

Excuse me , can you run the project successfully? I still have problem as above..I' ve sent a e-mail to you. Would you like to communicate with me,plz

hi, can you solve it? I have the same question

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

6 participants