Created
February 1, 2020 14:21
-
-
Save hartikainen/3a6b5f276139423ed35898db129e59e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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