christozonnev / TensorFlow-Course

https://lab.github.com/everydeveloper/introduction-to-tensorflow
0 stars 0 forks source link

Import Packages #2

Open github-learning-lab[bot] opened 3 years ago

github-learning-lab[bot] commented 3 years ago

Pip Installing Packages

To complete this project we will need a few packages; these are add-ons available to Python but not included in the base install. Very luckily, we installed the latest Python 3, which includes the Pip Installation module of Python. Pip is a fast and easy way to install packages and their dependencies. As we are doing an NN-based project, we will need to use TensorFlow. For those who only recognize TensorFlow by its association with NNs, it may be shocking to learn that TensorFlow is a more general tool for the manipulation of mathematical entities called tensors. NNs are just a single use of tenor mechanics, and therefore TensorFlow.

As tensors and TensorFlow can be fairly complex to manage, there exists another package named Keras that acts as a high-level API (Application Programming Interface), allowing users to easily generation, define and manipulate the structures within TensorFlow.

Finally, as we wish to visualize aspects of our dataset and generate some informational plots, we will want Python's Mathematical Plotting Library, MatPlotLib. Additionally, MatPlotLib facilitates the generation of graphical plots in new windows, even when executed from the Command Line. And finally, to handle numerical computations and array-based operations we will import Numpy.

Starting from the c-prompt (where we left off above), you will need to tell the easy Python package manager (a program that helps you install, uninstall, update and upgrade ancillary features to a larger application) that we want to install Numpy, MatPlotLib, and Tensorflow.

pip install Numpy
pip install MatPlotLib
pip install Tensorflow

If you encounter a permissions error, you may need to add --user to the end of each install. For example pip install Numpy --user.

After each of these actions, pip will display that it is downloading and installing the package. If you have an existing (but not up-to-date) version, pip will first uninstall the old version before installing the new. If you have previously installed the current version of any package, pip will inform you that the 'requirement already exists'.

Now we can test if Python has installed our Tensorflow correctly (this being the testier of the three packages), by returning to the Python Environment and printing the version of our Tensorflow:

python
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 13:35:33) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> print(tf.__version__)
1.14.0
>>> exit()

We can see that I have Tensorflow version 1.14.0 installed! Unless you have specified an earlier version (and dialing in the version that you need for any particular existing project can be a hassle with Tensorflow) you will have automatically installed the newest stable release, which at the time of this writing was version 2.0.0. And yes, I have intentionally had to enter and exit the Python environment from the CMD several times. This is called Reinforcement Learning; you've been subjected to the human equivalent of another machine learning technique you will learn about later.

Leave a comment with the letter (A, B, C, or D) that is false about TensorFlow

A. TensorFlow can be installed using pip B. TensorFlow is only used for Neural Networks C. TensorFlow is used to manipulate tensors D. The Keras package can make using TensorFlow more easy

christozonnev commented 3 years ago

B

github-learning-lab[bot] commented 3 years ago

That's right! Remember that TensorFlow is a more general tool for working with tensors. Therefore, it is not only used for Neural Networks.

Import Packages

We will be executing all of our Python code using the command line interface and a Python interpretor. This provides us with a degree of immediate responsiveness and the ability to see all messages passed during operations instead of just fail or pass state messages.

To import packaged into a specific Python environment, you need only use the 'import' command.

python
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 13:35:33) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>

We are also able to give packages nicknames, really useful so we don't have to type out matplotlib or tensorflow thousands of times. We assign these nicknames by "importing as".

>>> import matplotlib.pyplot as plt
>>>

And finally, we import Tensorflow and its Keras interface. Note that we can always call Keras as a Tensorflow object (i.e. tf.keras.command() ), but that takes too much typing. To save us time, we will import Keras from Tensorflow.

>>> import tensorflow as tf
>>> from tensorflow import keras
>>>

All of our prerequisite packages are now installed!

Leave a comment after you have imported the libraries above for the next step.