Friday, February 6, 2026
HomeLanguagesPython – tensorflow.DeviceSpec.device_type Attribute

Python – tensorflow.DeviceSpec.device_type Attribute

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. 

device_type is used to get the device type of DeviceSpec.

Syntax: tensorflow.DeviceSpec.device_type

Returns: It returns the device type.

Example 1:

Python3




# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg", device_type ="CPU", device_index = 1)
  
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)
  
# Getting device type
device_type = device_spec.device_type
  
# Printing the result
print('Device Type: ', device_type)


Output:


Device Spec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fe5ba96af48>
Device Type:  CPU

Example 2:

Python3




# Importing the library
import tensorflow as tf
  
# Initializing Device Specification
device_spec = tf.DeviceSpec(job ="gfg", device_type ="GPU", device_index = 1)
  
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)
  
# Getting device type
device_type = device_spec.device_type
  
# Printing the result
print('Device Type: ', device_type)


Output:


Device Spec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fe5ba96aee8>
Device Type:  GPU

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32490 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11985 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12073 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6931 POSTS0 COMMENTS