欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度學(xué)習(xí)環(huán)境的方法

 更新時(shí)間:2022年06月21日 11:56:46   作者:末世燈光  
這篇文章主要介紹了win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度學(xué)習(xí)環(huán)境,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

避坑1:RTX30系列顯卡不支持cuda11.0以下版本,具體上限版本可自行查閱:

方法一,在cmd中輸入nvidia-smi查看

方法二:

由此可以看出本電腦最高適配cuda11.2.1版本;

注意需要版本適配,這里我們選擇TensorFlow-gpu = 2.5,cuda=11.2.1,cudnn=8.1,python3.7

接下來可以下載cudn和cundnn:

官網(wǎng):https://developer.nvidia.com/cuda-toolkit-archive

 下載對應(yīng)版本exe文件打開默認(rèn)安裝就可;

驗(yàn)證是否安裝成功:

官網(wǎng):cuDNN Archive | NVIDIA Developer

把下載文件進(jìn)行解壓把bin+lib+include文件復(fù)制到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2文件下;

進(jìn)入環(huán)境變量設(shè)置(cuda會(huì)自動(dòng)設(shè)置,如果沒有的補(bǔ)全):

查看是否安裝成功:

cd C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\extras\demo_suite
bandwidthTest.exe

 安裝tensorflow-gpu:

pip install tensorflow-gpu==2.5

最后我們找相關(guān)程序來驗(yàn)證一下:

第一步:

import tensorflow as tf
print(tf.__version__)
print('GPU', tf.test.is_gpu_available())

第二步:

# _*_ coding=utf-8 _*_
'''
@author: crazy jums
@time: 2021-01-24 20:55
@desc: 添加描述
'''
# 指定GPU訓(xùn)練
import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"  ##表示使用GPU編號為0的GPU進(jìn)行計(jì)算
import numpy as np
from tensorflow.keras.models import Sequential  # 采用貫序模型
from tensorflow.keras.layers import Dense, Dropout, Conv2D, MaxPool2D, Flatten
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.callbacks import TensorBoard
import time
def create_model():
    model = Sequential()
    model.add(Conv2D(32, (5, 5), activation='relu', input_shape=[28, 28, 1]))  # 第一卷積層
    model.add(Conv2D(64, (5, 5), activation='relu'))  # 第二卷積層
    model.add(MaxPool2D(pool_size=(2, 2)))  # 池化層
    model.add(Flatten())  # 平鋪層
    model.add(Dropout(0.5))
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(10, activation='softmax'))
    return model
def compile_model(model):
    model.compile(loss='categorical_crossentropy', optimizer="adam", metrics=['acc'])
    return model
def train_model(model, x_train, y_train, batch_size=32, epochs=10):
    tbCallBack = TensorBoard(log_dir="model", histogram_freq=1, write_grads=True)
    history = model.fit(x_train, y_train, batch_size=batch_size, epochs=epochs, shuffle=True, verbose=2,
                        validation_split=0.2, callbacks=[tbCallBack])
    return history, model
if __name__ == "__main__":
    import tensorflow as tf
    print(tf.__version__)
    from tensorflow.python.client import device_lib
    print(device_lib.list_local_devices())
    (x_train, y_train), (x_test, y_test) = mnist.load_data()  # mnist的數(shù)據(jù)我自己已經(jīng)下載好了的
    print(np.shape(x_train), np.shape(y_train), np.shape(x_test), np.shape(y_test))
    x_train = np.expand_dims(x_train, axis=3)
    x_test = np.expand_dims(x_test, axis=3)
    y_train = to_categorical(y_train, num_classes=10)
    y_test = to_categorical(y_test, num_classes=10)
    print(np.shape(x_train), np.shape(y_train), np.shape(x_test), np.shape(y_test))
    model = create_model()
    model = compile_model(model)
    print("start training")
    ts = time.time()
    history, model = train_model(model, x_train, y_train, epochs=2)
    print("start training", time.time() - ts)

驗(yàn)證成功。

以上就是win10+RTX3050ti+TensorFlow+cudn+cudnn配置深度學(xué)習(xí)環(huán)境的詳細(xì)內(nèi)容,更多關(guān)于win10+RTX3050ti+TensorFlow+cudn+cudnn深度學(xué)習(xí)的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論