Tensorflow1.x version calls gpu on the server

1. Detect gpu 

pip install tensorflow-gpu==2.5
import tensorflow as tf

# 打印TensorFlow是否使用GPU加速
print(tf.test.gpu_device_name())

2. Version problem

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

3. Keras problem

Generally, there will be problems if you do not upgrade Keras. You need to upgrade Keras to the same version as Tensorflow. In addition, some functions need to be changed.
For example: before modification (this picture is after installing the 2.x higher version of tensorflow-gpu, change back to the original code, the reason for the SGD error - keras is in tensorflow, the lower version of keras is not compatible with the higher version of tensorflow, resulting report error)

Install tensorflow-gpu, after modification:

 4. Call the GPU in the program

 Note: The original code does not contain a blue block, it is added due to the reason of calling the gpu, and then the gpu of the server can be successfully called (with code)

import tensorflow as tf
physical_devices = tf.config.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)


Guess you like

Origin blog.csdn.net/qq_62687015/article/details/130354964