Tuesday, July 28, 2026
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
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6973 POSTS0 COMMENTS