Read tensor shapes and perform basic calculations before studying model training.

Before starting: Python arrays and basic arithmetic; learn train/test separation before training a model.

Practice project: Extend the examples into a small TensorFlow study demo. Explain the setup, one normal case and one failure or boundary case.

Start here: concepts and guided practice

  1. TensorFlow: compute with a tensor

    A tensor stores values with a shape and dtype. This rank-one tensor has three elements. Adding a compatible scalar broadcasts it across the elements; this arithmetic does not train a model.

    Python with a compatible TensorFlow 2 installation; save as tensors.py and run python tensors.py.

    import tensorflow as tf
    values = tf.constant([2, 4, 6], dtype=tf.int32)
    print((values + 1).numpy().tolist())
    Check the output
    [3, 5, 7]

    Use a scalar of 0 and predict the unchanged values.

  2. TensorFlow: read dimensions before computing

    Shape tells you the size of each dimension. Rank is the number of dimensions, not the total number of elements. Here two rows each contain three values.

    Python with a compatible TensorFlow 2 installation; save as tensors.py and run python tensors.py.

    import tensorflow as tf
    values = tf.constant([[1, 2, 3], [4, 5, 6]])
    print(values.shape.as_list())
    print(tf.reduce_sum(values, axis=1).numpy().tolist())
    Check the output
    [2, 3]
    [6, 15]

    Use axis=0 and predict [5, 7, 9].

Open the TensorFlow learning path on DevStudyHub · Play coding games on this blog

logoblog

No comments:

Post a Comment

Please do not enter any spam link in the comment box.