Python – tensorflow.DeviceSpec.from_string()
Last Updated :
01 Aug, 2020
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
import tensorflow as tf
spec = '/job:gfg / replica:1 / task:2'
device_spec = tf.DeviceSpec.from_string(spec)
print ( 'Device Spec: ' , device_spec)
|
Output:
Device Spec: <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fadb9428168>
Example 2:
Python3
import tensorflow as tf
spec = '/job:gfg / replica:2 / task:3'
device_spec = tf.DeviceSpec.from_string(spec)
print ( 'Device Spec: ' , device_spec)
|
Output:
Device Spec: <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x7fadb9428228>
Share your thoughts in the comments
Please Login to comment...