使用Google Colab时,如何将Tensorflow2.x版本转换到1.x版本

在2020年3月27日,Google Colab将Tensorflow的版本默认设置为2.x版本,不在将1.x版本设置为Tensorflow的默认版本。

这就导致了,很多用Tensorflow 1.x版本写的代码放到Google Colab上运行的时候出现很多版本不匹配错误。

例如在Tensorflow2.x版本就弃用了Contirb包,AttributeError: module ‘tensorflow’ has no attribute ‘contrib’。

这时可能就想把Google Colab中Tensorflow的版本转换到1.x。

转换过程就下面几句代码,在申请了GPU之后,就输入以下代码就OK。

%tensorflow_version 1.x

TensorFlow 1.x selected.

import tensorflow
print(tensorflow.__version__)

1.15.2

OK,以上代码就能把Google Colab中默认的2.xTensorflow版本切换为1.x版本。

参考文献

  • https://blog.csdn.net/qq_44262417/article/details/105222696

猜你喜欢

转载自blog.csdn.net/weixin_35770067/article/details/121538157