1

I was just testing the code to verify whether the code is running in GPU or not and I got this additional information along with accuracy & loss info.

Executing op __inference_train_function_88100 in device /job:localhost/replica:0/task:0/device:GPU:0
Executing op __inference_train_function_88100 in device /job:localhost/replica:0/task:0/device:GPU:0
  81/1875 [>.............................] - ETA: 9s - loss: 1.5444 - accuracy: 0.5918Executing op __inference_train_function_88100 in device /job:localhost/replica:0/task:0/device:GPU:0
Executing op __inference_train_function_88100 in device /job:localhost/replica:0/task:0/device:GPU:0
Executing op __inference_train_function_88100 in device /job:localhost/replica:0/task:0/device:GPU:0
Executing op __inference_train_function_88100 in device /job:localhost/replica:0/task:0/device:GPU:0

The Code is given below (and code is running on jupyter notebook)

import os
tf.autograph.set_verbosity(0)

with tf.device("/gpu:0"):
    model = keras.Sequential([
        keras.layers.Dense(10, input_shape=(784,), activation='sigmoid')
    ])

    model.compile(optimizer='adam',
                  loss='sparse_categorical_crossentropy',
                  metrics=['accuracy'])

    model.fit(X_train_flattened, y_train, epochs=5)

I also referred to TensorFlow documentation but, none of the methods worked. if you have any suggestions then, please help me

Dev Patel
  • 21
  • 5

1 Answers1

0

Thank you @Dev Patel for the confirmation. For the benefit of community please refer sample code as shown below

import logging, os
logging.disable(logging.WARNING)
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
import tensorflow as tf

with tf.device("/gpu:0"):
    model = keras.Sequential([
        keras.layers.Dense(10, input_shape=(784,), activation='sigmoid')
    ])

    model.compile(optimizer='adam',
                  loss='sparse_categorical_crossentropy',
                  metrics=['accuracy'])

    model.fit(X_train_flattened, y_train, epochs=5)