Wednesday, October 22, 2025
HomeLanguagesPython – tensorflow.DeviceSpec.from_string()

Python – tensorflow.DeviceSpec.from_string()

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

from_string is used to generate DeviceSpec from string.

Syntax: tensorflow.DeviceSpec.from_string( spec )

Parameters:

  • spec: It is a string of the form  /job:/replica:/task:/device:CPU: or /job:/replica:/task:/device:GPU with all entries being optional.

Returns: It returns a DeviceSpec object generated by the string.

Example 1:

Python3




# Importing the library
import tensorflow as tf
  
# Formatting the string
spec = '/job:gfg / replica:1 / task:2'
  
# Initializing Device Specification
device_spec = tf.DeviceSpec.from_string(spec)
  
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)


Output:


Device Spec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fadb9428168>

Example 2:

Python3




# Importing the library
import tensorflow as tf
  
# Formatting the string
spec = '/job:gfg / replica:2 / task:3'
  
# Initializing Device Specification
device_spec = tf.DeviceSpec.from_string(spec)
  
# Printing the DeviceSpec object
print('Device Spec: ', device_spec)


Output:


Device Spec:  <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fadb9428228>

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

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS