Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does [python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"] do?

I installed tensorflow, following the steps in their official site. But, in the site, as the last step of installation, they have given a line of code to "Verify the install". But they have not told what this code would give as the output.

The line is:

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

When I typed in this code, I got the following as the output:

C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Tensor("Sum:0", shape=(), dtype=float32)

How do I know that the installation is complete, and what does this Output mean?

like image 425
Joel Neyyan Avatar asked Nov 24 '25 02:11

Joel Neyyan


2 Answers

It's just a warning, not an error. You need to downgrade numpy to version 1.16.4 to make it compatible with the your current version of tensorflow. Your installation is completed.

Check the output at the end: Tensor("Sum:0", shape=(), dtype=float32)

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

Above is a way of running python code using terminal (-c is command argument).

In this code, you are first importing tensorflow library given by import tensorflow as tf.

tf.random.normal([1000, 1000]) outputs a tensor of the shape [1000, 1000] filled with random normal values. It outputs random values from a normal distribution.

tf.reduce_sum computes the sum of elements across dimensions of a tensor. If axis is None, all dimensions are reduced, and a tensor with a single element is returned.

Since, you are printing the result without creating a session, that's why you are getting output as Tensor("Sum:0", shape=(), dtype=float32). Read about tf.Session() from here.

In order to print the actual result run below command:

python -c "import tensorflow as tf; sess=tf.Session(); print(sess.run(tf.reduce_sum(tf.random.normal([1000, 1000]))))"
like image 156
Anubhav Singh Avatar answered Nov 25 '25 16:11

Anubhav Singh


The command is to call python to execute what's after -c.
You can see FutureWarning in the output lines and it's caused by numpy version updating in the future. And you can ignore them or set in python to make them not output anymore.
The real output is the last line. And the installation is completed.

like image 37
Yixuan Wei Avatar answered Nov 25 '25 17:11

Yixuan Wei