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
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS