Chuyển tới nội dung
Home » Install Tensorflow Jupyter Notebook Windows | Jupyter With The Main Conda Environment

Install Tensorflow Jupyter Notebook Windows | Jupyter With The Main Conda Environment

How to Install Tensorflow in Jupyter Notebook (Easy Method)

Step 3: Install TensorFlow

With our new environment created, we can now install TensorFlow. There are two ways to install TensorFlow: using pip or using conda. We recommend using conda as it will automatically install all the necessary dependencies. Create a new cell in your Jupyter notebook and run the command below:


!pip install tensorflow

This will download and install the latest version of TensorFlow in your environment. If your machine support GPU, make sure to Install the NVIDIA GPU driver if you have not and verify it by

nvidia-smi

. At the end, you can run the following command:


!pip install tensorflow[and-cuda]

How to Install TensorFlow in Jupyter Notebook

As a data scientist, you may have heard about the powerful machine learning framework called TensorFlow. TensorFlow is an open-source software library developed by Google that allows you to build and train machine learning models. In this blog post, we will show you how to install TensorFlow in Jupyter Notebook, a popular web-based interactive development environment for data science.

Tired of the complexities of installing TensorFlow in Jupyter Notebook? Try Saturn Cloud for free and to set up your data science environment effortlessly!

How to Install Tensorflow in Jupyter Notebook (Easy Method)
How to Install Tensorflow in Jupyter Notebook (Easy Method)

Step 4: Test TensorFlow

To test if TensorFlow is working correctly, we can create a simple program that adds two numbers using TensorFlow. In your new notebook, type the following code:


import tensorflow as tf a = tf.constant(2) b = tf.constant(3) c = tf.add(a, b) with tf.Session() as sess: result = sess.run(c) print(result)

This program creates two constants, and , and adds them together using TensorFlow’s

add

function. The result is then printed to the console.

To run the program, click on the

Run

button in the toolbar or press

Shift+Enter

. You should see the result, , printed to the console.

Congratulations, you have successfully installed TensorFlow in Jupyter Notebook!

Tired of the complexities of installing TensorFlow in Jupyter Notebook? Try Saturn Cloud for free and to set up your data science environment effortlessly!

Conclusion

In this blog post, we have shown you how to install TensorFlow in Jupyter Notebook using Anaconda. By following these simple steps, you can start building and training machine learning models using TensorFlow in Jupyter Notebook. Remember to create a new environment specifically for TensorFlow to avoid conflicts with other Python packages.

About Saturn Cloud

Saturn Cloud is your all-in-one solution for data science & ML development, deployment, and data pipelines in the cloud. Spin up a notebook with 4TB of RAM, add a GPU, connect to a distributed cluster of workers, and more. Join today and get 150 hours of free compute per month.

How to Find Which Version of TensorFlow is Installed in My System

As a data scientist, you might be working with TensorFlow, a popular machine learning library. It’s important to know which version of TensorFlow is installed on your system in order to ensure compatibility with your projects and to take advantage of the latest features and bug fixes. In this post, we’ll cover how to find which version of TensorFlow is currently installed on your system.

Confused about which TensorFlow version you have installed? Saturn Cloud provides an intuitive system to manage your TensorFlow installations. Join for free to experience a hassle-free data science environment.

Installing Tensorflow and Keras on Anaconda
Installing Tensorflow and Keras on Anaconda

Step 4: Test TensorFlow

To test if TensorFlow is working correctly, we can create a simple program that adds two numbers using TensorFlow. In your new notebook, type the following code:


import tensorflow as tf a = tf.constant(2) b = tf.constant(3) c = tf.add(a, b) with tf.Session() as sess: result = sess.run(c) print(result)

This program creates two constants, and , and adds them together using TensorFlow’s

add

function. The result is then printed to the console.

To run the program, click on the

Run

button in the toolbar or press

Shift+Enter

. You should see the result, , printed to the console.

Congratulations, you have successfully installed TensorFlow in Jupyter Notebook!

Tired of the complexities of installing TensorFlow in Jupyter Notebook? Try Saturn Cloud for free and to set up your data science environment effortlessly!

Checking the TensorFlow Version Using the Command Line

Another way to check the TensorFlow version is to use the command line. This method can be especially useful if you don’t have Python installed on your system or if you want to quickly check the TensorFlow version without opening up a Python editor.

Here’s how to check the TensorFlow version using the command line:

  1. Open up a terminal or command prompt on your system.
  2. Type

    pip show tensorflow

    . Alternatively, you can type

    pip freeze | grep tensorflow

    (for Linux or macOS) or

    pip freeze | findstr tensorflow

    (for Windows) and hit enter.
  3. The output should show the version of TensorFlow installed on your system.

Here’s an example of what the output might look like:


tensorflow==2.4.1

Installing Tensorflow and Keras in Jupyter Notebook using Anaconda THE RIGHT WAY!
Installing Tensorflow and Keras in Jupyter Notebook using Anaconda THE RIGHT WAY!

How to Import Tensorflow in Jupyter Notebook

This part is the same for both OS. Now, let’s learn how to import TensorFlow in Jupyter Notebook.

You can open TensorFlow with Jupyter.

Note: Each time you want to open TensorFlow, you need to initialize the environment

You will proceed as follow:

  • Activate hello-tf conda environment
  • Open Jupyter
  • Import tensorflow
  • Delete Notebook
  • Close Jupyter

Step 1) Activate conda

For MacOS user:

source activate hello-tf

For Windows user:

conda activate hello-tf

Step 2) Open Jupyter

After that, you can open Jupyter from the Terminal

jupyter notebook

Your browser should open automatically, otherwise copy and paste the url provided by the Terminal. It starts by http://localhost:8888

Inside the TensorFlow Jupyter Notebook, you can see all the files inside the working directory. To create a new Notebook, you simply click on new and Python 3

Note: The new notebook is automatically saved inside the working directory.

Step 3) Import Tensorflow

Inside the notebook, you can import TensorFlow in Jupyter Notebook with the tf alias. Click to run. A new cell is created below.

import tensorflow as tf

Let’s write your first code with TensorFlow.

hello = tf.constant(‘Hello, Guru99!’) hello

A new tensor is created. Congratulation. You successfully install TensorFlow with Jupyter on your Machine.

Step 4) Delete file

You can delete the file named Untitled.ipynb inside Jupyer.

Step 5) Close Jupyter

There are two ways of closing Jupyter. The first way is directly from the notebook. The second way is by using the terminal (or Anaconda Prompt)

From Jupyter

In the main panel of Jupyter Notebook, simply click on Logout

You are redirected to the log out page.

From the terminal

Select the terminal or Anaconda prompt and run twice ctr+c.

The first time you do ctr+c, you are asked to confirm you want to shut down the notebook. Repeat ctr+c to confirm

You have successfully logged out.

TensorFlow Versions

TensorFlow supports computations across multiple CPUs and GPUs. It means that the computations can be distributed across devices to improve the speed of the training. With parallelization, you don’t need to wait for weeks to obtain the results of training algorithms.

For Windows user, TensorFlow provides two versions:

  • TensorFlow with CPU support only: If your Machine does not run on NVIDIA GPU, you can only install this version
  • TensorFlow with GPU support: For faster computation, you can download TensorFlow GPU supported version. This version makes sense only if you need strong computational capacity.

During this tutorial, the basic version of TensorFlow is sufficient.

Note: TensorFlow does not provides GPU support on MacOS.

Here is how to proceed

MacOS User:

  • Install Anaconda
  • Create a .yml file to install Tensorflow and dependencies
  • Launch Jupyter Notebook

For Windows

  • Install Anaconda
  • Create a .yml file to install dependencies
  • Use pip to add TensorFlow
  • Launch Jupyter Notebook

To run Tensorflow with Jupyter, you need to create an environment within Anaconda. It means you will install Ipython, Jupyter, and TensorFlow in an appropriate folder inside our machine. On top of this, you will add one essential library for data science: “Pandas”. The Pandas library helps to manipulate a data frame.

How to Install Tensorflow and Keras in Jupyter Notebook (Easy Method)
How to Install Tensorflow and Keras in Jupyter Notebook (Easy Method)

TensorFlow Versions

TensorFlow supports computations across multiple CPUs and GPUs. It means that the computations can be distributed across devices to improve the speed of the training. With parallelization, you don’t need to wait for weeks to obtain the results of training algorithms.

For Windows user, TensorFlow provides two versions:

  • TensorFlow with CPU support only: If your Machine does not run on NVIDIA GPU, you can only install this version
  • TensorFlow with GPU support: For faster computation, you can download TensorFlow GPU supported version. This version makes sense only if you need strong computational capacity.

During this tutorial, the basic version of TensorFlow is sufficient.

Note: TensorFlow does not provides GPU support on MacOS.

Here is how to proceed

MacOS User:

  • Install Anaconda
  • Create a .yml file to install Tensorflow and dependencies
  • Launch Jupyter Notebook

For Windows

  • Install Anaconda
  • Create a .yml file to install dependencies
  • Use pip to add TensorFlow
  • Launch Jupyter Notebook

To run Tensorflow with Jupyter, you need to create an environment within Anaconda. It means you will install Ipython, Jupyter, and TensorFlow in an appropriate folder inside our machine. On top of this, you will add one essential library for data science: “Pandas”. The Pandas library helps to manipulate a data frame.

Jupyter with the main conda environment

If you want to launch TensorFlow with jupyter for future use, you need to open a new session with

source activate hello-tf

If you don’t, Jupyter will not find TensorFlow

Install TensorFlow 2

TensorFlow is tested and supported on the following 64-bit systems:

# Requires the latest pip

pip install --upgrade pip

# Current stable release for CPU and GPU

pip install tensorflow

# Or try the preview build (unstable)

pip install tf-nightly

Download a package

Install TensorFlow with Python’s pip package manager.

Official packages available for Ubuntu, Windows, and macOS.

Run a TensorFlow container

The TensorFlow Docker images are already configured to run TensorFlow. A Docker container runs in a virtual environment and is the easiest way to set up GPU support.


docker pull tensorflow/tensorflow:latest # Download latest stable image


docker run -it -p 8888:8888 tensorflow/tensorflow:latest-jupyter # Start Jupyter server

Google Colab: An easy way to learn and use TensorFlow

No install necessary—run the TensorFlow tutorials directly in the browser with Colaboratory, a Google research project created to help disseminate machine learning education and research. It’s a Jupyter notebook environment that requires no setup to use and runs entirely in the cloud. Read the blog post.

I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.

Here is what I did.

In Anaconda, I created an environment called

tensorflow

as follows


conda create -n tensorflow

Then installed the data science Python packages, like Pandas, NumPy, etc., inside it. I also installed TensorFlow and Keras there. Here is the list of packages in that environment


(tensorflow) SFOM00618927A:dl i854319$ conda list # packages in environment at /Users/i854319/anaconda/envs/tensorflow: # appdirs 1.4.3 appnope 0.1.0 py36_0 beautifulsoup4 4.5.3 py36_0 bleach 1.5.0 py36_0 cycler 0.10.0 py36_0 decorator 4.0.11 py36_0 entrypoints 0.2.2 py36_1 freetype 2.5.5 2 html5lib 0.999 py36_0 icu 54.1 0 ipykernel 4.5.2 py36_0 ipython 5.3.0 py36_0 ipython_genutils 0.2.0 py36_0 ipywidgets 6.0.0 py36_0 jinja2 2.9.5 py36_0 jsonschema 2.5.1 py36_0 jupyter 1.0.0 py36_3 jupyter_client 5.0.0 py36_0 jupyter_console 5.1.0 py36_0 jupyter_core 4.3.0 py36_0 Keras 2.0.2 libpng 1.6.27 0 markupsafe 0.23 py36_2 matplotlib 2.0.0 np112py36_0 mistune 0.7.4 py36_0 mkl 2017.0.1 0 nbconvert 5.1.1 py36_0 nbformat 4.3.0 py36_0 notebook 4.4.1 py36_0 numpy 1.12.1 numpy 1.12.1 py36_0 openssl 1.0.2k 1 packaging 16.8 pandas 0.19.2 np112py36_1 pandocfilters 1.4.1 py36_0 path.py 10.1 py36_0 pexpect 4.2.1 py36_0 pickleshare 0.7.4 py36_0 pip 9.0.1 py36_1 prompt_toolkit 1.0.13 py36_0 protobuf 3.2.0 ptyprocess 0.5.1 py36_0 pygments 2.2.0 py36_0 pyparsing 2.1.4 py36_0 pyparsing 2.2.0 pyqt 5.6.0 py36_2 python 3.6.1 0 python-dateutil 2.6.0 py36_0 pytz 2017.2 py36_0 PyYAML 3.12 pyzmq 16.0.2 py36_0 qt 5.6.2 0 qtconsole 4.3.0 py36_0 readline 6.2 2 scikit-learn 0.18.1 np112py36_1 scipy 0.19.0 np112py36_0 setuptools 34.3.3 setuptools 27.2.0 py36_0 simplegeneric 0.8.1 py36_1 sip 4.18 py36_0 six 1.10.0 six 1.10.0 py36_0 sqlite 3.13.0 0 tensorflow 1.0.1 terminado 0.6 py36_0 testpath 0.3 py36_0 Theano 0.9.0 tk 8.5.18 0 tornado 4.4.2 py36_0 traitlets 4.3.2 py36_0 wcwidth 0.1.7 py36_0 wheel 0.29.0 wheel 0.29.0 py36_0 widgetsnbextension 2.0.0 py36_0 xz 5.2.2 1 zlib 1.2.8 3 (tensorflow) SFOM00618927A:dl i854319$

You can see that

jupyter

is also installed.

Now, when I open up the Python interpreter in this environment and I run the basic TensorFlow command, it all works fine. However, I wanted to do the same thing in the Jupyter notebook. So, I created a new directory (outside of this environment).


mkdir dl

In that, I activated

tensorflow

environment


SFOM00618927A:dl i854319$ source activate tensorflow (tensorflow) SFOM00618927A:dl i854319$ conda list

And I can see the same list of packages in that.

Now, I open up a Jupyter notebook


SFOM00618927A:dl i854319$ source activate tensorflow (tensorflow) SFOM00618927A:dl i854319$ jupyter notebook

It opens up a new notebook in the browser. But when I just import basic python libraries in that, like pandas, it says “no packages available”. I am not sure why is that when the same environment has all those packages and in the same directory, if I use Python interpreter it shows all packages.


import pandas --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last)

in

() ----> 1 import pandas ModuleNotFoundError: No module named 'pandas'


Why jupyter notebook is not picking up these modules?

So, Jupyter notebook doesn’t show env as the interpreter

Đăng nhập/Đăng ký
Ranking
Cộng đồng
|
Kiến thức
31 tháng 03, 2022
Admin
05:32 31/03/2022
Cài Đặt TensorFlow Cho Windows Và Mac – Tự Học TensorFlow
Cùng tác giả
Không có dữ liệu
0
0
0
Admin
2995 người theo dõi
1283
184
Có liên quan
Không có dữ liệu
Chia sẻ kiến thức – Kết nối tương lai
Về chúng tôi
Về chúng tôi
Giới thiệu
Chính sách bảo mật
Điều khoản dịch vụ
Học miễn phí
Học miễn phí
Khóa học
Luyện tập
Cộng đồng
Cộng đồng
Kiến thức
Tin tức
Hỏi đáp
CÔNG TY CỔ PHẦN CÔNG NGHỆ GIÁO DỤC VÀ DỊCH VỤ BRONTOBYTE
The Manor Central Park, đường Nguyễn Xiển, phường Đại Kim, quận Hoàng Mai, TP. Hà Nội
THÔNG TIN LIÊN HỆ
[email protected]
©2024 TEK4.VN
Copyright © 2024
TEK4.VN

Install tensorflow 2.0 | Deep Learning Tutorial 5 (Tensorflow Tutorial, Keras & Python)
Install tensorflow 2.0 | Deep Learning Tutorial 5 (Tensorflow Tutorial, Keras & Python)

Checking the TensorFlow Version Using Python

One way to check the TensorFlow version is to use Python, the programming language that TensorFlow is built on top of. Here are the steps:

  1. Open up your favorite Python editor or IDE.
  2. Import TensorFlow by typing

    import tensorflow as tf

    at the top of your Python script.
  3. Call the

    tf.__version__

    attribute to print out the version of TensorFlow installed on your system.

Here’s what the code should look like:


import tensorflow as tf print(tf.__version__)

When you run this code in your Python environment, it should output the version number of TensorFlow installed on your system.

Step 2: Launch Jupyter Notebook

With TensorFlow and Jupyter Notebook installed, we can now launch Jupyter Notebook. In the same terminal window, type the following command:


jupyter notebook

This will open Jupyter Notebook in your default web browser. You should see a list of files and folders in your home directory. To create a new notebook, click on the

New

button in the top right corner and select

Python 3

under

Notebooks

.

How to Install Tensorflow and Keras in Anaconda - Download Tensorflow for Jupyter Notebook or Prompt
How to Install Tensorflow and Keras in Anaconda – Download Tensorflow for Jupyter Notebook or Prompt

How to Import Tensorflow in Jupyter Notebook

This part is the same for both OS. Now, let’s learn how to import TensorFlow in Jupyter Notebook.

You can open TensorFlow with Jupyter.

Note: Each time you want to open TensorFlow, you need to initialize the environment

You will proceed as follow:

  • Activate hello-tf conda environment
  • Open Jupyter
  • Import tensorflow
  • Delete Notebook
  • Close Jupyter

Step 1) Activate conda

For MacOS user:

source activate hello-tf

For Windows user:

conda activate hello-tf

Step 2) Open Jupyter

After that, you can open Jupyter from the Terminal

jupyter notebook

Your browser should open automatically, otherwise copy and paste the url provided by the Terminal. It starts by http://localhost:8888

Inside the TensorFlow Jupyter Notebook, you can see all the files inside the working directory. To create a new Notebook, you simply click on new and Python 3

Note: The new notebook is automatically saved inside the working directory.

Step 3) Import Tensorflow

Inside the notebook, you can import TensorFlow in Jupyter Notebook with the tf alias. Click to run. A new cell is created below.

import tensorflow as tf

Let’s write your first code with TensorFlow.

hello = tf.constant(‘Hello, Guru99!’) hello

A new tensor is created. Congratulation. You successfully install TensorFlow with Jupyter on your Machine.

Step 4) Delete file

You can delete the file named Untitled.ipynb inside Jupyer.

Step 5) Close Jupyter

There are two ways of closing Jupyter. The first way is directly from the notebook. The second way is by using the terminal (or Anaconda Prompt)

From Jupyter

In the main panel of Jupyter Notebook, simply click on Logout

You are redirected to the log out page.

From the terminal

Select the terminal or Anaconda prompt and run twice ctr+c.

The first time you do ctr+c, you are asked to confirm you want to shut down the notebook. Repeat ctr+c to confirm

You have successfully logged out.

Jupyter with the main conda environment

If you want to launch TensorFlow with jupyter for future use, you need to open a new session with

source activate hello-tf

If you don’t, Jupyter will not find TensorFlow

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative’s hand-on curriculum is perfect for new learners hoping to launch a career.

TensorFlow is one of the most popular machine learning frameworks. Its popularity can be attributed to its ease of use and its large community worldwide.

Like most machine learning frameworks, TensorFlow code is usually written inside Jupyter Notebooks using the Python language.

Jupyter.org defines a Jupyter Notebook as the original web application for creating and sharing computational documents. It offers a simple, streamlined, document-centric experience. Code in Jupyter Notebooks is written in cells which are usually executed sequentially.

Before one can begin writing TensorFlow code inside a Jupyter Notebook, the TensorFlow library must be installed first in the development environment.

Developers usually leverage the power of virtual environments for developing machine learning tools because virtual environments are stable, reproducible, and portable, which saves a lot of time in the future.

In this answer, we’ll look at how TensorFlow can be installed in one of those environments, the Anaconda environment. Anaconda is a program for managing Python packages and environments and contains the most common data science packages.

Go to https://www.anaconda.com/download and choose the appropriate version for your operating system. Download the setup and follow the installation instructions.

After the installation, open the terminal and type the command below to confirm which version of Anaconda is installed:

conda –version

nuruddeen@nuruddeen-Latitude-E7440:~$ conda –versionconda 22.11.0nuruddeen@nuruddeen-Latitude-E7440:~$

Next, we will create a virtual environment named

-tensorflow_env

using the command below:

conda create -n tensorflow_env

Activate the virtual environment:

conda activate tensorflow_env

Inside the environment, we’ll install the Jupyter Notebook and TensorFlow packages using the commands below:

conda install -c anaconda jupyterconda install -c conda-forge tensorflow

If the packages are already installed in our environment, nothing will be installed. Otherwise, they will be downloaded and installed.

To get the list of all packages installed in our environment, use the

conda list

command:

conda list

Finally, after installing all the necessary packages, we launch our Jupyter Notebook from the terminal using the

jupyter notebook

command:

jupyter notebook

A browser window should automatically open launching the Jupyter server. If the browser did not start automatically, open a new browser window and type “http://localhost:8888” to launch the server.

To create a new notebook, select “Python3 (ipykernel).”

We can start using TensorFlow by importing it from inside our Jupyter Notebook with the following command:

import tensorflow as tf

Run the cell and TensorFlow will now be imported and is ready for use inside our notebook.

We have successfully installed TensorFlow in our environment and imported it into our notebook. We can start building our machine learning models.

RELATED TAGS

CONTRIBUTOR

Careers

Installing Python and Tensorflow with Jupyter Notebook Configurations

Want to share your content on python-bloggers? click here.

For a machine or deep learning modeling, Python is widely used with Tensorflow. This post explains the an installation of Python, Tensorflow and configuration of Jupyter notebook as a kickstart towards ML/DL modeling.

Python, Tensorflow, Jupyter Notebook

It is common to use Anaconda for installing Python since a variety of packages (i.e. sklearn, pandas and so on) are installed automatically. Without Anaconda, we need to install Python and lots of package manually.

After installing Anaconda, Tensorflow is installed since Anaconda does not contain Tensorflow. Next we modify the default directory for Jupyter Notebook for our working directory.

Tensorflow is of two kinds : CPU and GPU version. This post only deal with CPU version since my laptop does not have GPU and I can’t test it. Instead, I use Google Colab when GPU Tensorflow is necessary.

Python programming is usually done with user-defined virtual environments which are constructed with some specific version of Python or Tensorflow. This approach helps you avoid version conflicts. But, for the time being, it is not necessary. This will be covered when it is necessary.

A whole process of installing Python is as follows.

Install Python

Download the recent Anaconda (Python 3.9 • 64-Bit Graphical Installer for Windows) at https://www.anaconda.com/products/individual and install it (Anaconda3-2021.11-Windows-x86_64.exe). Follow the instructions below with default settings (Yes or Next).

When installation is finished, we can find the new menu items like the above figure.

To check for whether Python is installed correctly, let’s run a sample Python code. To this end, click Spyder (anaconda3) or Anaconda Navigator (anaconda3) ➜ Spyder button and run the next sample code for a testing purpose.

Spyder is an IDE tool like R studio. PyCharm or Visual Studio Code is widely used also. You can select a favorite tool which fit you.

import numpy as np

import matplotlib.pyplot as plt

from sklearn import svm

xx, yy = np.meshgrid(np.linspace(–3, 3, 500),

np.linspace(–3, 3, 500))

np.random.seed(0)

X = np.random.randn(300, 2)

Y = np.logical_xor(X[:, 0] > 0, X[:, 1] > 0)

# fit the model

clf = svm.NuSVC(gamma=“auto”)

clf.fit(X, Y)

# plot the decision function for each datapoint on the grid

Z = clf.decision_function(np.c_[xx.ravel(), yy.ravel()])

Z = Z.reshape(xx.shape)

plt.imshow(

Z,

interpolation=“nearest”,

extent=(xx.min(), xx.max(), yy.min(), yy.max()),

aspect=“auto”,

origin=“lower”,

cmap=plt.cm.PuOr_r,

contours = plt.contour(xx, yy, Z, levels=[0],

linewidths=2, linestyles=“dashed”)

plt.scatter(X[:, 0], X[:, 1], s=30, c=Y,

cmap=plt.cm.Paired, edgecolors=“k”)

plt.xticks(())

plt.yticks(())

plt.axis([–3, 3, –3, 3])

plt.show()

cs

As can be seen in the following results with a figure, we can find that Python is installed correctly

Install Tensorflow

To install Tensorflow, click Anaconda Prompt (anaconda3) as administrator and type two commands sequentially. In particular, Tensorflow requires the latest updated pip which is the Python installation command.

To see if Tensorflow is installed properly, run the following sample code in Spyder.

# -*- coding: utf-8 -*-

# TensorFlow and tf.keras

import tensorflow as tf

# Helper libraries

import numpy as np

import matplotlib.pyplot as plt

fashion_mnist = tf.keras.datasets.fashion_mnist

(train_images, train_labels), (test_images, test_labels) \

= fashion_mnist.load_data()

class_names = [‘T-shirt/top’, ‘Trouser’, ‘Pullover’,

‘Dress’, ‘Coat’,‘Sandal’, ‘Shirt’,

‘Sneaker’, ‘Bag’, ‘Ankle boot’]

plt.figure()

plt.imshow(train_images[0])

plt.colorbar()

plt.grid(False)

plt.show()

train_images = train_images / 255.0

test_images = test_images / 255.0

plt.figure(figsize=(10,10))

for i in range(25):

plt.subplot(5,5,i+1)

plt.xticks([])

plt.yticks([])

plt.grid(False)

plt.imshow(train_images[i], cmap=plt.cm.binary)

plt.xlabel(class_names[train_labels[i]])

plt.show()

model = tf.keras.Sequential([

tf.keras.layers.Flatten(input_shape=(28, 28)),

tf.keras.layers.Dense(128, activation=‘relu’),

tf.keras.layers.Dense(10)

])

model.compile(optimizer=‘adam’,

loss=tf.keras.losses.SparseCategoricalCrossentropy(\

from_logits=True),

metrics=[‘accuracy’])

model.fit(train_images, train_labels, epochs=10)

test_loss, test_acc = model.evaluate(test_images,

test_labels, verbose=2)

print(‘\nTest accuracy:’, test_acc)

cs

From the following output, we can confirm that Tensorflow is installed correctly without any problem.

Modify configurations of Jupyter Notebook

Jupyter notebook is an interactive tool which is widely used for educational or serious analytical purposes. When we click Jupyter Notebook (anaconda3) or Anaconda Navigator (anaconda3) ➜ Jupyter Notebook button , its startup page is set to a default directory which is not our working directory and Chrome is not a default browser.

To change its default directory to our favorite working directory and use Chrome as browser, two things are modified. In my case I want Jupyter to be run at D:\py_env with Chrome.

At first, like the next figure,

Window Start button ➜ Anaconda3(64-bit) ➜ Jupyter Notebook (ananconda3) ➜ mouse right click More ➜ Open file location

When the target folder is opened, right click the linker to Jupyter Notebook (anaconda3) ➜ Select Properties and delete two things like the next figure.

Then, we need to generate configuration file by typing and entering the next command at Anaconda Prompt.

The generated configuration file is located at C:\Users\ your-user-id \.jupyter\ . Open jupyter_notebook_config.py using a notepad and modify the following two things for your favorite ones.

It is worth noting that delete # for each two lines before the modifications and use “/” as a delimiter of a browser address.

Close and rerun Jupyter notebook. We can start it at our working directory.

We can also test whether the same sample codes above are running correctly in this Jupyter notebook. To create a new notebook, click New (which is located at the right combo menu) and select Python 3 (ipykernel).

As can be seen in the screen captures below, two Python programs with sklearn or Tensorflow deliver the same results as expected. I deleted some block of redundant codes only when screenshots are captured

Concluding Remarks

This post dealt with an installation of Python with Tensorflow and configurations of Jupyter notebook. To see if Python is installed correctly, two sample codes using sklearn or Tensorflow are tested in Spyder and Jupyter notebook. From now on, we can concentrate on ML/DL modeling itself. \(\blacksquare\)

Want to share your content on python-bloggers? click here.

How to Install TensorFlow in Jupyter Notebook

As a data scientist, you may have heard about the powerful machine learning framework called TensorFlow. TensorFlow is an open-source software library developed by Google that allows you to build and train machine learning models. In this blog post, we will show you how to install TensorFlow in Jupyter Notebook, a popular web-based interactive development environment for data science.

Tired of the complexities of installing TensorFlow in Jupyter Notebook? Try Saturn Cloud for free and to set up your data science environment effortlessly!

How to install tensorflow in Jupyter Notebook  ||  Windows 10
How to install tensorflow in Jupyter Notebook || Windows 10

Conclusion

In this post, we’ve covered three ways to find which version of TensorFlow is installed on your system: using Python, using the command line, and using Jupyter Notebook. By knowing which version of TensorFlow you have installed, you can ensure compatibility with your projects and take advantage of the latest features and bug fixes. Remember, keeping your software up-to-date is important for both security and functionality reasons. So, make sure to check for updates regularly and keep your TensorFlow installation up-to-date.

About Saturn Cloud

Saturn Cloud is your all-in-one solution for data science & ML development, deployment, and data pipelines in the cloud. Spin up a notebook with 4TB of RAM, add a GPU, connect to a distributed cluster of workers, and more. Join today and get 150 hours of free compute per month.

How to Download & Install Tensorflow in Jupyter Notebook

In this tutorial, we will explain how to install TensorFlow Anaconda Windows. You will learn how to use TensorFlow in Jupyter Notebook. Jupyter is a notebook viewer.

Checking the TensorFlow Version in Jupyter Notebook

If you’re using Jupyter Notebook for your data science work, you can also check the TensorFlow version using Python code. Here are the steps:

  1. Open up a new Jupyter Notebook.
  2. Create a new code cell by clicking the “+” button.
  3. Type

    import tensorflow as tf

    in the code cell.
  4. Create a new code cell below and type

    tf.__version__

    in the new code cell.
  5. Run the code cells by clicking the “run” button or by pressing “Shift + Enter”.

Here’s what the code should look like:


import tensorflow as tf tf.__version__

When you run this code in a Jupyter Notebook, it should output the version number of TensorFlow installed on your system.

Confused about which TensorFlow version you have installed? Saturn Cloud provides an intuitive system to manage your TensorFlow installations. Join for free to experience a hassle-free data science environment.

How to install TensorFlow and Keras in Python on Windows 10
How to install TensorFlow and Keras in Python on Windows 10

Step 3: Install TensorFlow

With our new environment created, we can now install TensorFlow. There are two ways to install TensorFlow: using pip or using conda. We recommend using conda as it will automatically install all the necessary dependencies. Create a new cell in your Jupyter notebook and run the command below:


!pip install tensorflow

This will download and install the latest version of TensorFlow in your environment. If your machine support GPU, make sure to Install the NVIDIA GPU driver if you have not and verify it by

nvidia-smi

. At the end, you can run the following command:


!pip install tensorflow[and-cuda]

Step 2: Launch Jupyter Notebook

With TensorFlow and Jupyter Notebook installed, we can now launch Jupyter Notebook. In the same terminal window, type the following command:


jupyter notebook

This will open Jupyter Notebook in your default web browser. You should see a list of files and folders in your home directory. To create a new notebook, click on the

New

button in the top right corner and select

Python 3

under

Notebooks

.

How To Install TensorFlow For Python 3.11.3 In Windows 10/11 |TensorFlow Installation
How To Install TensorFlow For Python 3.11.3 In Windows 10/11 |TensorFlow Installation

Create .yml file to install Tensorflow and dependencies

It includes

  • Locate the path of Anaconda
  • Set the working directory to Anaconda
  • Create the yml file (For MacOS user, TensorFlow is installed here)
  • Edit the yml file
  • Compile the yml file
  • Activate Anaconda
  • Install TensorFlow (Windows user only)

Step 1) Locate Anaconda,

The first step you need to do is to locate the path of Anaconda.

You will create a new conda environment that includes the necessaries libraries you will use during the tutorials about TensorFlow.

Windows

If you are a Windows user, you can use Anaconda Prompt and type:

C:\>where anaconda

We are interested to know the name of the folder where Anaconda is installed because we want to create our new environment inside this path. For instance, in the picture above, Anaconda is installed in the Admin folder. For you, it can the same, i.e. Admin or the user’s name.

In the next, we will set the working directory from c:\ to Anaconda3.

MacOS

for MacOS user, you can use the Terminal and type:

which anaconda

You will need to create a new folder inside Anaconda which will contains Ipython, Jupyter and TensorFlow. A quick way to install libraries and software is to write a yml file.

Step 2) Set working directory

You need to specify the working directory where you want to create the yml file.

As said before, it will be located inside Anaconda.

For MacOS user:

The Terminal sets the default working directory to Users/USERNAME. As you can see in the figure below, the path of anaconda3 and the working directory are identical. In MacOS, the latest folder is shown before the $. The Terminal will install all the libraries in this working directory.

If the path on the text editor does not match the working directory, you can change it by writing cd PATH in the Terminal. PATH is the path you pasted in the text editor. Don’t forget to wrap the PATH with ‘PATH’. This action will change the working directory to PATH.

Open your Terminal, and type:

cd anaconda3

For Windows user (make sure of the folder before Anaconda3):

cd C:\Users\Admin\Anaconda3

or the path “where anaconda” command gives you

Step 3) Create the yml file

You can create the yml file inside the new working directory.

The file will install the dependencies you need to run TensorFlow. Copy and paste this code into the Terminal.

For MacOS user:

touch hello-tf.yml

A new file named hello-tf.yml should appear inside anaconda3

For Windows user:

echo.>hello-tf.yml

A new file named hello-tf.yml should appear

Step 4) Edit the yml file

You are ready to edit the yml file.

For MacOS user:

You can paste the following code in the Terminal to edit the file. MacOS user can use vim to edit the yml file.

vi hello-tf.yml

So far, your Terminal looks like this

You enter an edit mode. Inside this mode, you can, after pressing esc:

  • Press i to edit
  • Press w to save
  • Press q! to quit

Write the following code in the edit mode and press esc followed by :w

Note: The file is case and intend sensitive. 2 spaces are required after each intend.

For MacOS

name: hello-tfdependencies: – python=3.6 – jupyter – ipython – pandas – pip: – https://storage.googleapis.com/tensorflow/MacOS/cpu/tensorflow-1.5.0-py3-none-any.whl

Code Explanation

  • name: hello-tf: Name of the yml file
  • dependencies:
  • python=3.6
  • jupyter
  • ipython
  • pandas: Install Python version 3.6, Jupyter, Ipython,and pandas libraries
  • pip: Install a Python library

    • https://storage.googleapis.com/tensorflow/MacOS/cpu/tensorflow-1.5.0-py3-none-any.whl: Install TensorFlow from Google apis.

Press esc followed by :q! to quite the edit mode.

For Windows User:

Windows does not have vim program, so the Notepad is enough to complete this step.

notepad hello-tf.yml

Enter following into the file

name: hello-tfdependencies: – python=3.6 – jupyter – ipython – pandas

Code Explanation

  • name: hello-tf: Name of the yml file
  • dependencies:
  • python=3.6
  • jupyter
  • ipython
  • pandas: Install Python version 3.6, Jupyter, Ipython,and pandas libraries

It will open the notepad, you can edit the file from here.

Note: Windows users will install TensorFlow in the next step. In this step, you only prepare the conda environment

Step 5) Compile the yml file

You can compile the .yml file with the following code :

conda env create -f hello-tf.yml

Note: For Windows users, the new environment is created inside the current user directory.

It takes times. It will take around 1.1gb of space in your hard disk.

In Windows

Step 6) Activate conda environment

We are almost done. You have now 2 conda environments.

You created an isolated conda environment with the libraries you will use during the tutorials. This is a recommended practice because each machine learning project requires different libraries. When the project is over, you can remove or not this environment.

conda env list

The asterix indicates the default one. You need to switch to hello-tf to activate the environment

For MacOS user:

source activate hello-tf

For Windows user:

activate hello-tf

You can check all dependencies are in the same environment. This is important because it allows Python to use Jupyter and TensorFlow from the same environment. If you don’t see the three of them located in the same folder, you need to start all over again.

For MacOS user:

which python which jupyter which ipython

Optional: You can check for update.

pip install –upgrade tensorflow

Step 7) Install TensorFlow For Windows user

For windows user:

where python where jupyter where ipython

As you can see, you now have two Python environments. The main one and the newly created on i.e. hello-tf. The main conda environment does not have tensorFlow installed only hello-tf. From the picture, python, jupyter and ipython are installed in the same environment. It means, you can use TensorFlow with a Jupyter Notebook.

You need to install TensorFlow using pip command. Only for Windows user

pip install tensorflow

Common Errors and Solutions

Error: “ModuleNotFoundError: No module named ‘tensorflow'”

Solution: This error indicates that TensorFlow is not installed. Install it using:


pip install tensorflow

Error: “AttributeError: module ‘tensorflow’ has no attribute ‘__version__'”

Solution: This error occurs when an older version of TensorFlow is installed. Upgrade TensorFlow using:


pip install --upgrade tensorflow

Error: “ImportError: DLL load failed: The specified module could not be found.”

Solution: This error often occurs in Windows due to missing dependencies. Ensure that Microsoft Visual C++ Redistributable is installed.

Sau Tết-Làn Sóng Thiên Di Vẫn Tiếp Diễn🇨🇦Canada Cứ Hứa🤭
Sau Tết-Làn Sóng Thiên Di Vẫn Tiếp Diễn🇨🇦Canada Cứ Hứa🤭

Create .yml file to install Tensorflow and dependencies

It includes

  • Locate the path of Anaconda
  • Set the working directory to Anaconda
  • Create the yml file (For MacOS user, TensorFlow is installed here)
  • Edit the yml file
  • Compile the yml file
  • Activate Anaconda
  • Install TensorFlow (Windows user only)

Step 1) Locate Anaconda,

The first step you need to do is to locate the path of Anaconda.

You will create a new conda environment that includes the necessaries libraries you will use during the tutorials about TensorFlow.

Windows

If you are a Windows user, you can use Anaconda Prompt and type:

C:\>where anaconda

We are interested to know the name of the folder where Anaconda is installed because we want to create our new environment inside this path. For instance, in the picture above, Anaconda is installed in the Admin folder. For you, it can the same, i.e. Admin or the user’s name.

In the next, we will set the working directory from c:\ to Anaconda3.

MacOS

for MacOS user, you can use the Terminal and type:

which anaconda

You will need to create a new folder inside Anaconda which will contains Ipython, Jupyter and TensorFlow. A quick way to install libraries and software is to write a yml file.

Step 2) Set working directory

You need to specify the working directory where you want to create the yml file.

As said before, it will be located inside Anaconda.

For MacOS user:

The Terminal sets the default working directory to Users/USERNAME. As you can see in the figure below, the path of anaconda3 and the working directory are identical. In MacOS, the latest folder is shown before the $. The Terminal will install all the libraries in this working directory.

If the path on the text editor does not match the working directory, you can change it by writing cd PATH in the Terminal. PATH is the path you pasted in the text editor. Don’t forget to wrap the PATH with ‘PATH’. This action will change the working directory to PATH.

Open your Terminal, and type:

cd anaconda3

For Windows user (make sure of the folder before Anaconda3):

cd C:\Users\Admin\Anaconda3

or the path “where anaconda” command gives you

Step 3) Create the yml file

You can create the yml file inside the new working directory.

The file will install the dependencies you need to run TensorFlow. Copy and paste this code into the Terminal.

For MacOS user:

touch hello-tf.yml

A new file named hello-tf.yml should appear inside anaconda3

For Windows user:

echo.>hello-tf.yml

A new file named hello-tf.yml should appear

Step 4) Edit the yml file

You are ready to edit the yml file.

For MacOS user:

You can paste the following code in the Terminal to edit the file. MacOS user can use vim to edit the yml file.

vi hello-tf.yml

So far, your Terminal looks like this

You enter an edit mode. Inside this mode, you can, after pressing esc:

  • Press i to edit
  • Press w to save
  • Press q! to quit

Write the following code in the edit mode and press esc followed by :w

Note: The file is case and intend sensitive. 2 spaces are required after each intend.

For MacOS

name: hello-tfdependencies: – python=3.6 – jupyter – ipython – pandas – pip: – https://storage.googleapis.com/tensorflow/MacOS/cpu/tensorflow-1.5.0-py3-none-any.whl

Code Explanation

  • name: hello-tf: Name of the yml file
  • dependencies:
  • python=3.6
  • jupyter
  • ipython
  • pandas: Install Python version 3.6, Jupyter, Ipython,and pandas libraries
  • pip: Install a Python library

    • https://storage.googleapis.com/tensorflow/MacOS/cpu/tensorflow-1.5.0-py3-none-any.whl: Install TensorFlow from Google apis.

Press esc followed by :q! to quite the edit mode.

For Windows User:

Windows does not have vim program, so the Notepad is enough to complete this step.

notepad hello-tf.yml

Enter following into the file

name: hello-tfdependencies: – python=3.6 – jupyter – ipython – pandas

Code Explanation

  • name: hello-tf: Name of the yml file
  • dependencies:
  • python=3.6
  • jupyter
  • ipython
  • pandas: Install Python version 3.6, Jupyter, Ipython,and pandas libraries

It will open the notepad, you can edit the file from here.

Note: Windows users will install TensorFlow in the next step. In this step, you only prepare the conda environment

Step 5) Compile the yml file

You can compile the .yml file with the following code :

conda env create -f hello-tf.yml

Note: For Windows users, the new environment is created inside the current user directory.

It takes times. It will take around 1.1gb of space in your hard disk.

In Windows

Step 6) Activate conda environment

We are almost done. You have now 2 conda environments.

You created an isolated conda environment with the libraries you will use during the tutorials. This is a recommended practice because each machine learning project requires different libraries. When the project is over, you can remove or not this environment.

conda env list

The asterix indicates the default one. You need to switch to hello-tf to activate the environment

For MacOS user:

source activate hello-tf

For Windows user:

activate hello-tf

You can check all dependencies are in the same environment. This is important because it allows Python to use Jupyter and TensorFlow from the same environment. If you don’t see the three of them located in the same folder, you need to start all over again.

For MacOS user:

which python which jupyter which ipython

Optional: You can check for update.

pip install –upgrade tensorflow

Step 7) Install TensorFlow For Windows user

For windows user:

where python where jupyter where ipython

As you can see, you now have two Python environments. The main one and the newly created on i.e. hello-tf. The main conda environment does not have tensorFlow installed only hello-tf. From the picture, python, jupyter and ipython are installed in the same environment. It means, you can use TensorFlow with a Jupyter Notebook.

You need to install TensorFlow using pip command. Only for Windows user

pip install tensorflow

Conclusion

In this blog post, we have shown you how to install TensorFlow in Jupyter Notebook using Anaconda. By following these simple steps, you can start building and training machine learning models using TensorFlow in Jupyter Notebook. Remember to create a new environment specifically for TensorFlow to avoid conflicts with other Python packages.

About Saturn Cloud

Saturn Cloud is your all-in-one solution for data science & ML development, deployment, and data pipelines in the cloud. Spin up a notebook with 4TB of RAM, add a GPU, connect to a distributed cluster of workers, and more. Join today and get 150 hours of free compute per month.

How to Download & Install Tensorflow in Jupyter Notebook

In this tutorial, we will explain how to install TensorFlow Anaconda Windows. You will learn how to use TensorFlow in Jupyter Notebook. Jupyter is a notebook viewer.

How to install and first impressions of NVIDIA Chat with RTX AI Chatbot
How to install and first impressions of NVIDIA Chat with RTX AI Chatbot

Keywords searched by users: install tensorflow jupyter notebook windows

How To Download & Install Tensorflow In Jupyter Notebook
How To Download & Install Tensorflow In Jupyter Notebook
How To Download & Install Tensorflow In Jupyter Notebook
How To Download & Install Tensorflow In Jupyter Notebook
How To Download & Install Tensorflow In Jupyter Notebook
How To Download & Install Tensorflow In Jupyter Notebook
How To Download & Install Tensorflow In Jupyter Notebook
How To Download & Install Tensorflow In Jupyter Notebook
How To Install Tensorflow In Jupyter Notebook (Easy Method) - Youtube
How To Install Tensorflow In Jupyter Notebook (Easy Method) – Youtube
How To Install Tensorflow And Keras In Jupyter Notebook (Easy Method) -  Youtube
How To Install Tensorflow And Keras In Jupyter Notebook (Easy Method) – Youtube
How To Install Tensorflow In Jupyter Notebook || Windows 10 - Youtube
How To Install Tensorflow In Jupyter Notebook || Windows 10 – Youtube
How To Install Python Tensorflow In Windows? - Geeksforgeeks
How To Install Python Tensorflow In Windows? – Geeksforgeeks
Installing Tensorflow And Keras In Jupyter Notebook Using Anaconda The  Right Way! - Youtube
Installing Tensorflow And Keras In Jupyter Notebook Using Anaconda The Right Way! – Youtube
How To Install Tensorflow In Jupyter Notebook | Saturn Cloud Blog
How To Install Tensorflow In Jupyter Notebook | Saturn Cloud Blog
How To Download & Install Tensorflow In Jupyter Notebook
How To Download & Install Tensorflow In Jupyter Notebook

See more here: kientrucannam.vn

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *