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

tensorflow 2.1.0 安裝與實戰(zhàn)教程(CASIA FACE v5)

 更新時間:2020年06月30日 10:21:28   作者:博二兔  
這篇文章主要介紹了tensorflow 2.1.0 安裝與實戰(zhàn)(CASIA FACE v5),本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

1.0tensorflow的安裝

1.1安裝python

python下載 需要python3.x<=3.7
https://www.python.org/ftp/python/3.7.7/python-3.7.7-amd64.exe

python安裝

安裝時勾選Add Python 3.7 to PATH,把python添加到環(huán)境變量。

1.2安裝tensorflow

打開命令行,執(zhí)行

pip install tensorflow==2.1.0

pip install tensorflow==2.1.0
pip install tensorflow 2

pip 會安裝tensorflow和一些其他的依賴

1.3安裝vc++2015-2019redist…

tensorflow的另一個依賴(很多tensorflow安裝失敗的原因就是這個沒安裝)
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

1.4安裝CUDA和CUDNN

cuda: https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal
cudnn: https://developer.nvidia.com/rdp/cudnn-download(需要注冊nvidia賬號)
cudnn下載后是個壓縮文件,要把他解壓出來放在CUDA里,如下圖

cudnn
dll缺失

高版本CUDA缺失cudart64_101.dll,下載后放在C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\bin里
https://cn.dll-files.com/cudart64_101.dll.html

2.0CASIA實戰(zhàn)

2.1CASIA數(shù)據(jù)集

casia

可以從網(wǎng)上下載casia數(shù)據(jù)集,
這里以casia數(shù)據(jù)集為例,現(xiàn)實中可以使用自己需要的數(shù)據(jù)集。

2.2數(shù)據(jù)集的處理

建立data和test兩個文件夾,把casia復(fù)制到里面
目錄是這樣的./data/000/000_0.bmp
data.py處理數(shù)據(jù),其實就是遍歷,匹配,刪除

import os 
data = './data'
dirs = os.listdir(data) 
for dir in dirs:
 for file in os.listdir(data + '/' + dir):
  if file.endswith("4.bmp"):
   os.remove(data + '/' + dir + '/' + file)
test = './test'
tdirs = os.listdir(test)
for dir in tdirs:
 for file in os.listdir(test + '/' + dir):
  if file.endswith("0.bmp"):
   os.remove(test + '/' + dir + '/' + file)
  if file.endswith("1.bmp"):
   os.remove(test + '/' + dir + '/' + file)
  if file.endswith("2.bmp"):
   os.remove(test + '/' + dir + '/' + file)
  if file.endswith("3.bmp"):
   os.remove(test + '/' + dir + '/' + file)

2.3訓(xùn)練代碼

casia.py

import os
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Conv2D, Flatten, Dropout, MaxPooling2D
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import numpy as np
/*我直接建立了個0000,1111,...這樣的數(shù)組作為標(biāo)簽*/
#data標(biāo)簽
arr = []
for i in range(100):
 for j in range(4):
  arr.append(i)
arr = np.array(arr)
#test標(biāo)簽
tarr = []
for i in range(100):
 tarr.append(i)
tarr = np.array(tarr)

#訓(xùn)練集
pwd='./data'
dirs = os.listdir(pwd)
imgs = []

for dir in dirs:
 for file in os.listdir(pwd + '/' + dir):
  image = tf.io.read_file(pwd + '/' + dir + '/' + file)
  img = tf.image.decode_bmp(image,channels=3)
  imgs.append(img)
print("[*]訓(xùn)練集加載完畢")
print(imgs[0].shape)
#驗證集(測試集)
tpwd='./test'
tdirs = os.listdir(tpwd)
timgs = []
for tdir in tdirs:
 for tfile in os.listdir(tpwd + '/' + tdir):
  timage = tf.io.read_file(tpwd + '/' + tdir + '/' + tfile)
  timg = tf.image.decode_bmp(timage,channels=3)
  timgs.append(timg)
print("[*]驗證集加載完畢")
print(timgs[0].shape)
#神經(jīng)網(wǎng)絡(luò)模型
model = Sequential([
 Conv2D(16, (3,3), padding='same', activation='relu',input_shape=(480,640,3)),
 MaxPooling2D(),
 Conv2D(64, (3,3), padding='same', activation='relu'),
 MaxPooling2D(),
 Conv2D(128, (3,3), padding='same', activation='relu'),
 MaxPooling2D(),
 Flatten(),
 Dense(128, activation='relu'),
 Dense(100, activation='softmax'),
])
model.summary()//打印神經(jīng)網(wǎng)絡(luò)模型
#優(yōu)化器
model.compile(optimizer=tf.keras.optimizers.Adam(),
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy'])
#訓(xùn)練
ds = tf.data.Dataset.from_tensor_slices((imgs,arr))
ds = ds.batch(16)
ds = ds.prefetch(buffer_size=tf.data.experimental.AUTOTUNE)
model.fit(ds,epochs=20)
tds = tf.data.Dataset.from_tensor_slices((timgs,tarr))
tds = ds.prefetch(buffer_size=tf.data.experimental.AUTOTUNE)
model.evaluate(tds, verbose=2)
#保存
tf.saved_model.save(model, "./tmp/")

2.4訓(xùn)練與驗證

在命令行運行 python casia.py進行訓(xùn)練
predict.py

import os
import tensorflow as tf
import numpy as np
/*這里顯卡內(nèi)存不夠了*/
from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession

config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)
/*顯卡內(nèi)存*/

model_path = './tmp' //加載模型
test_path = "./test/002/002_4.bmp"http://這里就是個栗子
model = tf.keras.models.load_model(model_path, custom_objects=None, compile=True)

image = tf.io.read_file(test_path)
img = tf.image.decode_bmp(image,channels=3)
img = img[tf.newaxis, ...]
res = model.predict(
 img, batch_size=None, verbose=0, steps=None, callbacks=None, max_queue_size=10,
 workers=1, use_multiprocessing=False
)
pred = tf.argmax(res, axis=1)
print (pred[0])
print (res[0,pred[0]])

總結(jié)

到此這篇關(guān)于tensorflow 2.1.0 安裝與實戰(zhàn)(CASIA FACE v5)的文章就介紹到這了,更多相關(guān)tensorflow 2.1.0 安裝內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 帶你徹底搞懂python操作mysql數(shù)據(jù)庫(cursor游標(biāo)講解)

    帶你徹底搞懂python操作mysql數(shù)據(jù)庫(cursor游標(biāo)講解)

    這篇文章主要介紹了帶你徹底搞懂python操作mysql數(shù)據(jù)庫(cursor游標(biāo)講解),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • Python無頭爬蟲下載文件的實現(xiàn)

    Python無頭爬蟲下載文件的實現(xiàn)

    這篇文章主要介紹了Python無頭爬蟲下載文件的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • Python實現(xiàn)打乒乓小游戲

    Python實現(xiàn)打乒乓小游戲

    這篇文章主要為大家詳細(xì)介紹了Python實現(xiàn)打乒乓小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • python matplotlib工具欄源碼探析二之添加、刪除內(nèi)置工具項的案例

    python matplotlib工具欄源碼探析二之添加、刪除內(nèi)置工具項的案例

    這篇文章主要介紹了python matplotlib工具欄源碼探析二之添加、刪除內(nèi)置工具項的案例,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-02-02
  • 5款實用的python 工具推薦

    5款實用的python 工具推薦

    工欲善其事必先利其器,一個好的工具能讓起到事半功倍的效果,Python 社區(qū)提供了足夠多的優(yōu)秀工具來幫助開發(fā)者更方便的實現(xiàn)某些想法,下面這幾個工具給我的工作也帶來了很多便利,推薦給追求美好事物的你。
    2020-10-10
  • Python快速實現(xiàn)分列轉(zhuǎn)到行的示例代碼

    Python快速實現(xiàn)分列轉(zhuǎn)到行的示例代碼

    這篇文章主要為大家詳細(xì)介紹了如何利用Python快速實現(xiàn)分列轉(zhuǎn)到行的效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)一下
    2023-03-03
  • python的launcher用法知識點總結(jié)

    python的launcher用法知識點總結(jié)

    在本篇文章里小編給大家整理的是一篇關(guān)于python的launcher用法知識點總結(jié)內(nèi)容,有興趣的朋友們可以學(xué)習(xí)下。
    2020-08-08
  • Python3.9.0 a1安裝pygame出錯解決全過程(小結(jié))

    Python3.9.0 a1安裝pygame出錯解決全過程(小結(jié))

    這篇文章主要介紹了Python3.9.0 a1安裝pygame出錯解決全過程(小結(jié)),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • Python中atexit模塊的基本使用示例

    Python中atexit模塊的基本使用示例

    這篇文章主要介紹了Python中atexit模塊的基本使用示例,示例代碼基于Python2.x版本,注意其和Python3的兼容性,需要的朋友可以參考下
    2015-07-07
  • Python 按比例獲取樣本數(shù)據(jù)或執(zhí)行任務(wù)的實現(xiàn)代碼

    Python 按比例獲取樣本數(shù)據(jù)或執(zhí)行任務(wù)的實現(xiàn)代碼

    這篇文章主要介紹了Python 按比例獲取樣本數(shù)據(jù)或執(zhí)行任務(wù),本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12

最新評論