Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_sn_dense(self):
layer_test(
SNDense, kwargs={'units': 3}, input_shape=(3, 2),
custom_objects={'SNDense': SNDense})
def test_sn_dense(self):
layer_test(
SNDense, kwargs={'units': 3}, input_shape=(3, 2),
custom_objects={'SNDense': SNDense})
def __init__(self, state_shape, action_dim, units=[32, 32],
enable_sn=False, output_activation="sigmoid",
name="Discriminator"):
super().__init__(name=name)
DenseClass = SNDense if enable_sn else Dense
self.l1 = DenseClass(units[0], name="L1", activation="relu")
self.l2 = DenseClass(units[1], name="L2", activation="relu")
self.l3 = DenseClass(1, name="L3", activation=output_activation)
dummy_state = tf.constant(
np.zeros(shape=(1,)+state_shape, dtype=np.float32))
dummy_action = tf.constant(
np.zeros(shape=[1, action_dim], dtype=np.float32))
with tf.device("/cpu:0"):
self([dummy_state, dummy_action])
def __init__(self, state_shape, action_dim, units=[32, 32],
n_latent_unit=32, enable_sn=False, name="Discriminator"):
super().__init__(name=name)
DenseClass = SNDense if enable_sn else Dense
self.l1 = DenseClass(units[0], name="L1", activation="relu")
self.l2 = DenseClass(units[1], name="L2", activation="relu")
self.l_mean = DenseClass(n_latent_unit, name="L_mean", activation="linear")
self.l_logstd = DenseClass(n_latent_unit, name="L_std", activation="linear")
self.l3 = DenseClass(1, name="L3", activation="sigmoid")
dummy_state = tf.constant(
np.zeros(shape=(1,)+state_shape, dtype=np.float32))
dummy_action = tf.constant(
np.zeros(shape=[1, action_dim], dtype=np.float32))
with tf.device("/cpu:0"):
self([dummy_state, dummy_action])
def __init__(self, state_shape, units=[32, 32],
enable_sn=False, output_activation="sigmoid",
name="Discriminator"):
tf.keras.Model.__init__(self, name=name)
DenseClass = SNDense if enable_sn else Dense
self.l1 = DenseClass(units[0], name="L1", activation="relu")
self.l2 = DenseClass(units[1], name="L2", activation="relu")
self.l3 = DenseClass(1, name="L3", activation=output_activation)
dummy_state = tf.constant(
np.zeros(shape=(1,) + state_shape, dtype=np.float32))
dummy_next_state = tf.constant(
np.zeros(shape=(1,) + state_shape, dtype=np.float32))
with tf.device("/cpu:0"):
self([dummy_state, dummy_next_state])
def __init__(self, state_shape, units=[32, 32],
enable_sn=False, output_activation="sigmoid",
name="Discriminator"):
super().__init__(name=name)
DenseClass = SNDense if enable_sn else Dense
self.l1 = DenseClass(units[0], name="L1", activation="relu")
self.l2 = DenseClass(units[1], name="L2", activation="relu")
self.l3 = DenseClass(1, name="L3", activation=output_activation)
dummy_state = tf.constant(
np.zeros(shape=(1,)+state_shape, dtype=np.float32))
with tf.device("/cpu:0"):
self(dummy_state)
def get_config(self):
config = {
"u_kernel_initializer": self.u_kernel_initializer,
"trainable": self.trainable}
base_config = super(SNDense, self).get_config()
return dict(list(base_config.items()) + list(config.items()))