- 安装anaconda
https://www.anaconda.com/products/individual#windows
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64
conda config --set show_channel_urls yes
// 删除用户 目录下“.condarc”中的--defaults
- 安装tensorflow
点击Anaconda Prompt
安装的时候关掉vpn
// 创建虚拟环境
conda create --name tensorflow python=3.9
// 激活虚拟环境
activate tensorflow
// 安装tensorflow-gpu
conda install -c aaronzs tensorflow-gpu
// 安装keras(2.7.0报错 same metric)
pip install keras==2.6.0
- pycharm调试
添加解释器
运行代码进行测试
import numpy as np
from keras.models import Sequential
from keras.layers import Dense, Dropout
# Generate dummy data
x_train = np.random.random((1000, 20))
y_train = np.random.randint(2, size=(1000, 1))
x_test = np.random.random((100, 20))
y_test = np.random.randint(2, size=(100, 1))
model = Sequential()
model.add(Dense(64, input_dim=20, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
model.fit(x_train, y_train,
epochs=20,
batch_size=128)
score = model.evaluate(x_test, y_test, batch_size=128)
这个是日志 不是报错(应该是这样)