class critic(tf.keras.Model):
def __init__(self):
super().__init__()
self.d1 = tf.keras.layers.Dense(128,activation='relu')
self.v = tf.keras.layers.Dense(1, activation = None)
def call(self, input_data):
x = self.d1(input_data)
v = self.v(x)
return v
class actor(tf.keras.Model):
def __init__(self):
super().__init__()
self.d1 = tf.keras.layers.Dense(128,activation='relu')
self.a = tf.keras.layers.Dense(2,activation='softmax')
def call(self, input_data):
x = self.d1(input_data)
a = self.a(x)
return a
You just call self.d1(input_data) directly, does tensorflow detect the input shape implicitly?
Besides, in your PG code you did tf.convert_to_tensor(input_data) before calling self.d1(x), while you didn't do that in PPO code. Does this mean tf.convert_to_tensor() is unnecessary?
TensorFlow models can be made using Sequential API, Functional API, and Subclassing. Here, I have used subclassing, and you do not need to specify input shape explicitly in that.
tf.convert_to_tensor(input_data) is optional here.
In Specifying the input shape in advance | TensorFlow Core, it says:
It then gives two ways to specify the shape of inputs:
Input
object to your model, so that it knows its input shape from the start:input_shape
argument to your first layer:But I haven't seen input shapes defined in your code:
(Reinforce)Policy Gradient with TensorFlow2.x
Proximal Policy Optimization (PPO) With TensorFlow 2.x
You just call
self.d1(input_data)
directly, does tensorflow detect the input shape implicitly?Besides, in your PG code you did
tf.convert_to_tensor(input_data)
before callingself.d1(x)
, while you didn't do that in PPO code. Does this meantf.convert_to_tensor()
is unnecessary?