From 5d4c690d035d438d7384940da4aa2dedac128572 Mon Sep 17 00:00:00 2001 From: Parth Sharma <99831413+PsVenom@users.noreply.github.com> Date: Sat, 29 Apr 2023 17:33:37 +0530 Subject: [PATCH] updated policies.py to support tf 2.x replaced tf 1.0 functions with tf.compat.v1 + replaced tf.contrib with tf-slim --- stable_baselines/deepq/policies.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stable_baselines/deepq/policies.py b/stable_baselines/deepq/policies.py index 3a2dfec1..5233d417 100644 --- a/stable_baselines/deepq/policies.py +++ b/stable_baselines/deepq/policies.py @@ -1,5 +1,5 @@ import tensorflow as tf -import tensorflow.contrib.layers as tf_layers +import tf_slim as tf_layers import numpy as np from gym.spaces import Discrete @@ -38,7 +38,7 @@ def _setup_init(self): """ Set up action probability """ - with tf.variable_scope("output", reuse=True): + with tf.compat.v1.variable_scope("output", reuse=True): assert self.q_values is not None self.policy_proba = tf.nn.softmax(self.q_values) @@ -100,13 +100,13 @@ def __init__(self, sess, ob_space, ac_space, n_env, n_steps, n_batch, reuse=Fals if layers is None: layers = [64, 64] - with tf.variable_scope("model", reuse=reuse): - with tf.variable_scope("action_value"): + with tf.compat.v1.variable_scope("model", reuse=reuse): + with tf.compat.v1.variable_scope("action_value"): if feature_extraction == "cnn": extracted_features = cnn_extractor(self.processed_obs, **kwargs) action_out = extracted_features else: - extracted_features = tf.layers.flatten(self.processed_obs) + extracted_features = tf.compat.v1.layers.flatten(self.processed_obs) action_out = extracted_features for layer_size in layers: action_out = tf_layers.fully_connected(action_out, num_outputs=layer_size, activation_fn=None) @@ -117,7 +117,7 @@ def __init__(self, sess, ob_space, ac_space, n_env, n_steps, n_batch, reuse=Fals action_scores = tf_layers.fully_connected(action_out, num_outputs=self.n_actions, activation_fn=None) if self.dueling: - with tf.variable_scope("state_value"): + with tf.compat.v1.variable_scope("state_value"): state_out = extracted_features for layer_size in layers: state_out = tf_layers.fully_connected(state_out, num_outputs=layer_size, activation_fn=None)