farizrahman4u / qlearning4k

Q-learning for Keras
MIT License
385 stars 84 forks source link

One Hot #17

Closed OscarRL closed 6 years ago

OscarRL commented 7 years ago

Tensorflow now provides a native one_hot function making the fast implementation suitable with tensorflow

https://www.tensorflow.org/versions/r0.11/api_docs/python/array_ops.html#one_hot

Ex: def one_hot_tensor(self, seq, num_classes): import tensorflow as T return T.one_hot(K.reshape(T.cast(seq, T.int32), (-1, 1)), num_classes)

farizrahman4u commented 7 years ago

I have added one hot function to the Keras backend too. Would you like to submit a PR so that fast mode works on both backends?

OscarRL commented 7 years ago

Yes, srry.. I didn't see it

https://keras.io/backend/#backend-functions

def one_hot(self, seq, num_classes): return K.one_hot(K.reshape(K.cast(seq, "int32"), (-1, 1)), num_classes)

Works on the 2 backends for me on gpu

farizrahman4u commented 7 years ago

Yes. Can you make a PR to qlearning4k to use K.one_hot?

OscarRL commented 7 years ago

Look the pull request