Skip to content

Instantly share code, notes, and snippets.

@hartikainen
Created February 1, 2020 14:21
Show Gist options
  • Save hartikainen/3a6b5f276139423ed35898db129e59e7 to your computer and use it in GitHub Desktop.
Save hartikainen/3a6b5f276139423ed35898db129e59e7 to your computer and use it in GitHub Desktop.
import gym
import tensorflow as tf
from sklearn import preprocessing
from softlearning.utils.tensorflow import cast_and_concat
feature_fn = preprocessing.PolynomialFeatures(2)
def polynomial_inputs(x):
return feature_fn.fit_transform(x)
@tf.function(experimental_relax_shapes=True)
def tf_function(inputs):
inputs = cast_and_concat(inputs)
y = tf.numpy_function(
feature_fn.fit_transform,
[inputs],
tf.float32)
return y
env = gym.envs.make('Hopper-v3')
observations = env.reset()[None, ...]
actions = env.action_space.sample()[None, ...]
inputs = {'observations': observations, 'actions': actions}
outputs = tf_function(inputs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment