by Suf | Apr 7, 2022 | Programming, Python, TensorFlow, Tips
The simplest way to convert a TensorFlow Tensor to a Numpy array is to use the numpy() method. For example, numpy_array = tensor.numpy(). This tutorial will go through how to convert a TensorFlow Tensor to a NumPy array for both TensorFlow 2.x and 1.x with the help of...
by Suf | Mar 26, 2022 | Machine Learning, Programming, Python, Tips
TensorFlow 2 has integrated deep-learning Keras API as tensorflow.keras. If you try to import from the standalone Keras API with a Tensorflow 2 installed on your system, this can raise incompatibility issues, and you may raise the AttributeError: module...
by Suf | Mar 25, 2022 | Machine Learning, Programming, Python, Tips
In TensorFlow 2.0, tf.Session is no longer in use. TensorFlow 2.0 encapsulates graph computations as Python functions instead of using Session making TensorFlow more Pythonic. If you want to continue using Session in TensorFlow 2.0, use tf.compat.v1.Session() instead....
by Suf | Mar 25, 2022 | Machine Learning, Programming, Python, Tips
In TensorFlow 2.0, tf.ConfigProto is no longer in use. The functionalities of ConfigProto are now under tf.config.experimental. If you want to continue using ConfigProto in TensorFlow 2.0 use tf.compat.v1.ConfigProto() instead. You can follow the migration guide if...
by Suf | Mar 16, 2022 | Machine Learning, Programming, Python, PyTorch
Concatenating joins a sequence of tensors along an existing axis. The PyTorch function for concatenation is cat(). Stacking joins a sequence of tensors along a new axis. The PyTorch function for stacking is stack(). This tutorial will go through the two PyTorch...
by Suf | Mar 14, 2022 | Programming, Python, PyTorch, Tips
To convert a NumPy array to a PyTorch tensor you can: Use the from_numpy() function, for example, tensor_x = torch.from_numpy(numpy_array)Pass the NumPy array to the torch.Tensor() constructor or by using the tensor function, for example, tensor_x =...