# on 14-Apr-2024 (Sun)

#### Flashcard 7624065944844

Tags
#tensorflow #tensorflow-certificate
Question

from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense
import numpy as np

model = Sequential(Dense(1, input_shape=[1]))
model.compile(optimizer='sgd', [...]='mean_squared_error')
xs = np.array([1,5,12,-1,10], dtype=float)
ys = np.array([5,13,27,1,23], dtype=float)
model.fit(xs, ys, epochs=500)
model.predict(x=[15])

loss

status measured difficulty not learned 37% [default] 0

Tensorflow basics - typical flow of model building
from tensorflow.keras import Sequential from tensorflow.keras.layers import Dense import numpy as np model = Sequential(Dense(1, input_shape=[1])) model.compile(optimizer='sgd', loss='mean_squared_error') xs = np.array([1,5,12,-1,10], dtype=float) ys = np.array([5,13,27,1,23], dtype=float) model.fit(xs, ys, epochs=500) model.predict(x=[15])

#### Flashcard 7624086129932

Tags
#tensorflow #tensorflow-certificate
Question

import tensorflow as tf

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


on_epoch_end

status measured difficulty not learned 37% [default] 0

Tensorflow - callbacks
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.model.stop_training = True

#### Flashcard 7624235289868

Tags
#tensorflow #tensorflow-certificate
Question
# Create matrix
another_matrix = tf.[...]([[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