Skip to content

Commit

Permalink
Merge pull request #824 from dzhwinter/inference
Browse files Browse the repository at this point in the history
"add inference"
  • Loading branch information
dzhwinter authored Apr 10, 2018
2 parents 9aa2637 + ab673e3 commit 6fa8a94
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fluid/policy_gradient/brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ def build_net(self):
act="tanh" # tanh activation
)
# fc2
self.all_act_prob = fluid.layers.fc(input=fc1,
all_act_prob = fluid.layers.fc(input=fc1,
size=self.n_actions,
act="softmax")
self.inferece_program = fluid.defaul_main_program().clone()
# to maximize total reward (log_p * R) is to minimize -(log_p * R)
neg_log_prob = fluid.layers.cross_entropy(
input=self.all_act_prob,
Expand All @@ -53,7 +54,7 @@ def build_net(self):

def choose_action(self, observation):
prob_weights = self.exe.run(
fluid.default_main_program().prune(self.all_act_prob),
self.inferece_program,
feed={"obs": observation[np.newaxis, :]},
fetch_list=[self.all_act_prob])
prob_weights = np.array(prob_weights[0])
Expand Down

0 comments on commit 6fa8a94

Please sign in to comment.