09.05.2023 Views

pdfcoffee

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

• To create random values from a given gamma distribution of shape

[M,N] in the range [minval (default=0), maxval] and using seed:

t_random = tf.random_uniform([2,3], maxval=4, seed=12) ==> [[

2.54461002 3.69636583 2.70510912], [ 2.00850058 3.84459829

3.54268885]]

• To randomly crop a given tensor to a specified size:

tf.random_crop(t_random, [2,5],seed=12) where t_random is an

already defined tensor. This will result in a [2,5] Tensor

randomly cropped from Tensor t_random.

Chapter 2

• Every time we need to present the training sample in a random order, we

can use tf.random_shuffle() to randomly shuffle a tensor along its first

dimension. If t_random is the tensor we want to shuffle then we use:

tf.random_shuffle(t_random)

• Randomly generated tensors are affected by the value of an initial seed.

To obtain the same random numbers in multiple runs or sessions, the seed

should be set to a constant value. When there is a large number of random

tensors in use, we can set the seed for all randomly generated tensors by

using tf.set_random_seed(). The following command sets the seed for

random tensors for all sessions as 54:

tf.set_random_seed(54) //Seed can be any integer value.

Variables

Variables are created using the tf.Variable class. The definition of variables

also includes the constant or random values from which they should be initialized.

In the following code, we create two different tensor variables t_a and t_b. Both

will be initialized to random uniform distributions of shape [50, 50], minval=0,

and maxval=10:

rand_t = tf.random_uniform([50,50], 0, 10, seed=0)

t_a = tf.Variable(rand_t)

t_b = tf.Variable(rand_t)

Variables are often used to represent weights and biases in a neural network:

weights = tf.Variable(tf.random_normal([100,100],stddev=2))

bias = tf.Variable(tf.zeros[100], name = 'biases')

[ 57 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!