new blog
Posts
Showing posts with label RNN. Show all posts
Showing posts with label RNN. Show all posts
Monday, 11 May 2020
Thursday, 18 July 2019
Some TF version errors in [Text generation using a RNN with eager execution]
Some TF version errors in [Text generation using a RNN with eager execution]
Tensorflow RNN tutorials are basically based on the TF version 1.13 or higher.
I was following this one below.
https://www.tensorflow.org/tutorials/sequences/text_generation
- Error 1
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-70-7589cf238f4d> in <module> ----> 1 sampled_indices = tf.random.categorical(example_batch_predictions[0], num_samples=1) 2 #sampled_indices = tf.random.multinomial(example_batch_predictions[0], num_samples=1) 3 # use tf.random.multinomial if using TF 1.12 or lower. 4 sampled_indices = tf.squeeze(sampled_indices,axis=-1).numpy() AttributeError: module 'tensorflow._api.v1.random' has no attribute 'categorical'
Solution
sampled_indices = tf.random.multinomial(example_batch_predictions[0], num_samples=1)
# use tf.random.multinomial if using TF 1.12 or lower.
- Error 2
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-72-9ea97acf159a> in <module> 4 # if using TF 1.12 or lower, use 'tf.keras.backend.sparse_categorical_crossentropy' 5 ----> 6 example_batch_loss = loss(target_example_batch, example_batch_predictions) 7 print("Prediction shape: ", example_batch_predictions.shape, " # (batch_size, sequence_length, vocab_size)") 8 print("scalar_loss: ", example_batch_loss.numpy().mean()) <ipython-input-72-9ea97acf159a> in loss(labels, logits) 1 def loss(labels, logits): ----> 2 return tf.keras.losses.sparse_categorical_crossentropy(labels, logits, from_logits=True) 3 #return tf.keras.backend.sparse_categorical_crossentropy(labels, logits, from_logits=True) 4 # if using TF 1.12 or lower, use 'tf.keras.backend.sparse_categorical_crossentropy' 5 TypeError: sparse_categorical_crossentropy() got an unexpected keyword argument 'from_logits'Solution
return tf.keras.backend.sparse_categorical_crossentropy(labels, logits, from_logits=True) # if using TF 1.12 or lower, use 'tf.keras.backend.sparse_categorical_crossentropy'
Subscribe to:
Posts (Atom)
[ new blog ]
new blog https://jihyo-jeon.github.io/
-
< What I did > How to install ORB_SLAM2 and test it on Ubuntu 16.04 1. Create a new folder mkdir ORB_SLAM cd ORB_SLAM 2. I...
-
How to run ORB SLAM with KITTI Dataset Monocular Examples 1. Download the dataset ( grayscale images ) from http://www.cvlibs.net/da...
-
Evolutionary Approach to Approximate Digital Circuits Design 1 This paper proposed the automatic design process to evolv...