1. 安装anaconda

    https://www.anaconda.com/products/individual#windows

    1. conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64
    2. conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64
    3. conda config --set show_channel_urls yes
    4. // 删除用户 目录下“.condarc”中的--defaults
    1. 安装tensorflow

    点击Anaconda Prompt
    安装的时候关掉vpn

    1. // 创建虚拟环境
    2. conda create --name tensorflow python=3.9
    3. // 激活虚拟环境
    4. activate tensorflow
    5. // 安装tensorflow-gpu
    6. conda install -c aaronzs tensorflow-gpu
    7. // 安装keras(2.7.0报错 same metric)
    8. pip install keras==2.6.0
    1. pycharm调试

    添加解释器
    image.png
    运行代码进行测试

    1. import numpy as np
    2. from keras.models import Sequential
    3. from keras.layers import Dense, Dropout
    4. # Generate dummy data
    5. x_train = np.random.random((1000, 20))
    6. y_train = np.random.randint(2, size=(1000, 1))
    7. x_test = np.random.random((100, 20))
    8. y_test = np.random.randint(2, size=(100, 1))
    9. model = Sequential()
    10. model.add(Dense(64, input_dim=20, activation='relu'))
    11. model.add(Dropout(0.5))
    12. model.add(Dense(64, activation='relu'))
    13. model.add(Dropout(0.5))
    14. model.add(Dense(1, activation='sigmoid'))
    15. model.compile(loss='binary_crossentropy',
    16. optimizer='rmsprop',
    17. metrics=['accuracy'])
    18. model.fit(x_train, y_train,
    19. epochs=20,
    20. batch_size=128)
    21. score = model.evaluate(x_test, y_test, batch_size=128)

    这个是日志 不是报错(应该是这样)
    image.png