Tensorflow - Python - tester son GPU CPU

Est ce que votre code fonctionne en gpu ou cpu sur Tensorflow ???,

Voila un code de base trouvé sur tensorflow.org 


import sys
import numpy as np
import tensorflow as tf
import os

from datetime import datetime

print("BEGIN OF TEST") 
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' 
tf.logging.set_verbosity(tf.logging.ERROR)

device_name = sys.argv[1]  # Choose device from cmd line. Options: gpu or cpu
shape = (int(sys.argv[2]), int(sys.argv[2]))
if device_name == "gpu":
    device_name = "/gpu:0"
else:
    device_name = "/cpu:0"

with tf.device(device_name):
    random_matrix = tf.random_uniform(shape=shape, minval=0, maxval=1)
    dot_operation = tf.matmul(random_matrix, tf.transpose(random_matrix))
    sum_operation = tf.reduce_sum(dot_operation)


startTime = datetime.now()
print( startTime )
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as session:
        result = session.run(sum_operation)
        print(result)


print("\nShape:", shape, "\nDevice:", device_name)
print("\nTime taken:", datetime.now() - startTime)

print("\n")
endTime = datetime.now()
print(endTime) 

Commentaires

Posts les plus consultés de ce blog

Quand Google fait un KIT AI hyper débutant !!!

50 niveaux de RaspBerry Pi

Netflix AlphaGo - le documentaire à voir absolument