TensowFlow Flashcards

1
Q

Writing and running programs in TensorFlow has the following steps:

A

Create Tensors (variables) that are not yet executed/evaluated.
Write operations between those Tensors.
Initialize your Tensors.
Create a Session.
Run the Session. This will run the operations you’d written above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a placeholder?

A

A placeholder is an object whose value you can specify only later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you put values in a placholder?

A

You use the function feed_dict, feed_dict = {x: 3}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you do a matrix multiplication in tensforflow?

A

tf.matmul(…, …) to do a matrix multiplication

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Addition in tensorflow?

A

tf.add(…, …) to do an addition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

random initialization in python

A

np.random.randn(…) to initialize randomly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

how would you define a constant X that has shape (3,1)?

A

X = tf.constant(np.random.randn(3,1), name = “X”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How would you declare a placeholder?

A
tf.placeholder(
    dtype,
    shape=None,
    name=None
)
E.g. x = tf.placeholder(tf.float32, shape=(1024, 1024))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How would you initialize parameters in tensorflow?

A
tf.get_variable(
    name,
    shape=None,
    dtype=None,
    initializer=None,
    regularizer=None,
    trainable=True,
    collections=None,
    caching_device=None,
    partitioner=None,
    validate_shape=True,
    use_resource=None,
    custom_getter=None,
    constraint=None
)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to do a 2d convolution in TF?

A

tf.nn.conv2d(X,W1, strides = [1,s,s,1], padding = ‘SAME’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

how to maxpool in TF?

A

tf.nn.max_pool(A, ksize = [1,f,f,1], strides = [1,s,s,1], padding = ‘SAME’):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how to ReLU in TF?

A

tf.nn.relu(Z1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to flatten a layer in TF?

A

tf.contrib.layers.flatten(P)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to do a fully connected layer in TF?

A

tf.contrib.layers.fully_connected(F, num_outputs)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you softmax with several labels in TF?

A

tf.nn.softmax_cross_entropy_with_logits(logits = Z3, labels = Y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you setup the opimizer in TF?

A

optimizer = tf.train.GradientDescentOptimizer(learning_rate = learning_rate).minimize(cost)

17
Q

How do you run the session (on optimizer and cost) in TF?

A

_ , c = sess.run([optimizer, cost], feed_dict={X: minibatch_X, Y: minibatch_Y})