How to Check if Tensorflow is Using GPU

Share This Post

Is your Tensorflow taking much GPU or space? Want to know how? Good to hear today’s topic, it is really interesting.

So, if you are a developer and you are a user of Tensorflow as well so, you should have an idea of how you can check if Tensorflow is using GPU.

Let’s get started!

How to Check if Tensorflow is Using GPU?

There are a few ways to check.

# For TensorFlow 2

The following code will help you in Tensorflow version 2.0 and this will help for those who already have updated their version.

import tensorflow as tf

print(tf.test.gpu_device_name())

print("Check GPU: ", len(tf.config.list_physical_devices('GPU')))
  • The above line code is just help to check physical devices.
tf.test.is_gpu_available
  • The above code is built-in you do not need to make your own function if you are using this.

# For TensorFlow 1:

Here you must have version 1.0, then you must consider the following code.

import tensorflow as tf
print(tf.test.gpu_device_name())

new_var = tf.Session(config=tf.ConfigProto(log_device_placement=True))

print(new_var)
  • First of all, you have to import Tensorflow library then mention a short name such as tf.
  • Okay, now just use the built-in function as well that is: tf.test.gpu_device_name().
  • Now create a new variable with any name.
  • Here you are creating a config of all log devices.
  • Just print out your made variable.

Are you getting AttributeError: module ‘tensorflow’ has no attribute ‘Session’? It is very tough to solve. Now you are to free out of it. I hope this official guide will help as well.

spot_img

Related Posts

Python for Loop Iteration: How to Easily Manipulate a List

One of the most powerful features of the Python...

How To Get First Characters of a String in Python

Way to find the first characters of a string...

How To Convert Tuple To String In Python

In this post, you will learn how to convert...

How To Convert String to Double in Python

Good to hear, that you want to convert a...

Python TypeError: String Index Out Of Range Solution

A string is an array of characters and part...

How To Remove Empty Strings From a List Of Strings

On this page, we will discuss how to remove...
- Advertisement -spot_img