The method of running tensorflow1.x code with tensorflow2

Problem background:

Since tensorflow1.x only supports CUDA10 at the highest, and CUDA11 is the minimum requirement for the 30 series graphics card to run, this makes it impossible for my 3090 graphics card to directly run many open source codes of tensorflow1.x.

After searching and practicing, I found an easy-to-use method to run tensorflow1.x code with tensorflow2 framework under the 30 series graphics card

Solution

First make sure you installed the tensorflow2 library, for example, I use tensorflow-gpu2.10.1, CUDA11.7

Change the import tensorflow as tf in the original tf1.x code to the following two lines of code

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

These two lines of code achieve compatibility with the old API of tf1 in tf2, and turn off the new features of tf2, so that the code of tf1.x can be run with tf2

Guess you like

Origin blog.csdn.net/qq_28941587/article/details/128466526