tensorflow2.0 使用keras一般通过tensorflow.keras来使用,但是pycharm没有提示,原因是因为实际的keras路径放在tensorflow/python/keras,但是在程序中tensorflow有没有python这个目录,解决方法如下:
1 try: 2 import tensorflow.python.keras as keras 3 except: 4 import tensorflow.keras as keras
这样pycharm既可以有提示,同时也不需要在程序运行的时候修改代码了。非常完美的解决手段,当然如果你不适用ide就不需要这些东西了。