Advertisement
alejandrotecnimaq

Prueba tensorflow GPU

Sep 6th, 2023
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. import tensorflow as tf
  2.  
  3. # Verifica si TensorFlow fue construido con soporte para CUDA (GPU)
  4. print("¿TensorFlow construido con CUDA?:", tf.test.is_built_with_cuda())
  5.  
  6. # Verifica si TensorFlow puede acceder a una GPU
  7. print("¿TensorFlow puede acceder a una GPU?:", tf.test.is_gpu_available())
  8.  
  9. # Lista las GPUs disponibles y sus capacidades
  10. gpus = tf.config.experimental.list_physical_devices('GPU')
  11. if gpus:
  12.     print("GPUs disponibles:")
  13.     for gpu in gpus:
  14.         print(gpu)
  15. else:
  16.     print("No se encontraron GPUs disponibles.")
  17.  
  18. # Verifica la versión de CUDA y cuDNN si están disponibles
  19. if tf.test.is_built_with_cuda():
  20.     print("Versión de CUDA:", tf.sysconfig.get_build_info()['cuda_version'])
  21.     print("Versión de cuDNN:", tf.sysconfig.get_build_info()['cudnn_version'])
  22.  
  23. # Crea un modelo simple con una capa convolucional
  24. model = tf.keras.models.Sequential([
  25.     tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
  26.     tf.keras.layers.MaxPooling2D((2, 2)),
  27.     tf.keras.layers.Flatten(),
  28.     tf.keras.layers.Dense(10, activation='softmax')
  29. ])
  30.  
  31. # Compila el modelo
  32. model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')
  33.  
  34. # Crea datos de entrada y salida falsos
  35. import numpy as np
  36. x = np.random.random((100, 28, 28, 1))
  37. y = np.random.randint(0, 10, size=(100,))
  38.  
  39. # Entrena el modelo
  40. model.fit(x, y, epochs=1)
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement