# on 15-Apr-2024 (Mon)

#### Flashcard 7624090324236

Tags
#tensorflow #tensorflow-certificate
Question

import tensorflow as tf

#stop training after reaching accuract of 0.99
class MyCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs={}):
if logs.get('accuracy')>=0.99:
print('\nAccuracy 0.99 achieved')
self.[...].stop_training = True


model

status measured difficulty not learned 37% [default] 0

Tensorflow - callbacks
g after reaching accuract of 0.99 class MyCallback(tf.keras.callbacks.Callback): def on_epoch_end(self, epoch, logs={}): if logs.get('accuracy')>=0.99: print('\nAccuracy 0.99 achieved') self.<span>model.stop_training = True <span>

#### Flashcard 7624234241292

Tags
#tensorflow #tensorflow-certificate
Question
# Create matrix
another_matrix = tf.constant([[10. ,66.],
[5. , 9.],
[13. , 4.]], dtype=tf.float16)
another_matrix

<tf.[...]: shape=(3, 2), dtype=float16, numpy=
array([[10., 66.],
[ 5.,  9.],
[13.,  4.]], dtype=float16)>

another_matrix.ndim
2

Tensor

status measured difficulty not learned 37% [default] 0

Tensors fundamentals - creating tensors
# Create matrix another_matrix = tf.constant([[10. ,66.], [5. , 9.], [13. , 4.]], dtype=tf.float16) another_matrix <tf.Tensor: shape=(3, 2), dtype=float16, numpy= array([[10., 66.], [ 5., 9.], [13., 4.]], dtype=float16)> another_matrix.ndim 2

#### Flashcard 7624252067084

Tags
#tensorflow #tensorflow-certificate
Question
changeable_tensor = tf.Variable([10, 7])

changeable_tensor[0] = 77

Output:
TypeError: 'ResourceVariable' object does not support item assignment

changeable_tensor[0].assign(77)

Output:
<tf.Variable 'UnreadVariable' shape=(2,) dtype=int32, numpy=array([[...]], dtype=int32)>

77, 7

status measured difficulty not learned 37% [default] 0

Tensorflow basics
= 77 Output: TypeError: 'ResourceVariable' object does not support item assignment changeable_tensor[0].assign(77) Output: <tf.Variable 'UnreadVariable' shape=(2,) dtype=int32, numpy=array([<span>77, 7], dtype=int32)> <span>

#### Annotation 7624317078796

 Tensorflow random #tensorflow #tensorflow-certificate # global seed tf.random.set_seed(42) #operation seed tf.random.shuffle(not_shuffled, seed=42)

#### Flashcard 7624318913804

Tags
#tensorflow #tensorflow-certificate
Question
# global seed
tf.random.[...](42)

#operation seed
tf.random.shuffle(not_shuffled, seed=42)

set_seed

status measured difficulty not learned 37% [default] 0

Tensorflow random
# global seed tf.random.set_seed(42) #operation seed tf.random.shuffle(not_shuffled, seed=42)

#### Flashcard 7624320486668

Tags
#tensorflow #tensorflow-certificate
Question
# global seed
tf.random.set_seed(42)

#operation seed
tf.random.shuffle(not_shuffled, [...]=42)

seed

status measured difficulty not learned 37% [default] 0

Tensorflow random
# global seed tf.random.set_seed(42) #operation seed tf.random.shuffle(not_shuffled, seed=42)

#### Annotation 7624353516812

 Properties of tensor #tensorflow #tensorflow-certificate print('Datatype of every element:', A.dtype) print('Number of dimensions (rank):', A.ndim) print('Shape of tensor:', A.shape) print('Elements along the 0 axis:', A.shape[0]) print('Elements along the last axis:', A.shape[-1]) print('Total number of elements:', tf.size(A)) print('Total number of elements:', tf.size(A).numpy()) Output: Datatype of every element: Number of dimensions (rank): 4 Shape of tensor: (2, 3, 4, 5) Elements along the 0 axis: 2 Elements along the last axis: 5 Total number of elements: tf.Tensor(120, shape=(), dtype=int32) Total number of elements: 120

#### Flashcard 7624355351820

Tags
#tensorflow #tensorflow-certificate
Question
print('Datatype of every element of tensor A:', [...])

Output:
Datatype of every element: <dtype: 'int64'>



A.dtype

status measured difficulty not learned 37% [default] 0

Properties of tensor
print('Datatype of every element:', A.dtype) print('Number of dimensions (rank):', A.ndim) print('Shape of tensor:', A.shape) print('Elements along the 0 axis:', A.shape[0]) print('Elements along the last axis:', A.shape[-1]) pri

#### Annotation 7624357973260

 Tensors indexing #tensorflow #tensorflow-certificate # Tensors can be indexed just like Python lists. # Get the first 2 elements of each dimension A[:2, :2, :2, :2]

#### Flashcard 7624359808268

Tags
#tensorflow #tensorflow-certificate
Question
# Tensors can be indexed just like Python [...].

# Get the first 2 elements of each dimension
A[:2, :2, :2, :2]

lists

status measured difficulty not learned 37% [default] 0

Tensors indexing
# Tensors can be indexed just like Python lists. # Get the first 2 elements of each dimension A[:2, :2, :2, :2]

#### Flashcard 7624361381132

Tags
#tensorflow #tensorflow-certificate
Question
# Tensors can be indexed just like Python lists.

# Get the first 2 elements of each dimension (this is 4D tensor)
A[[...]]