日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > pytorch >内容正文

pytorch

深度学习-Tensorflow2.2-tf.data输入模块{2}-tf.data输入实例-10

發布時間:2024/9/15 pytorch 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 深度学习-Tensorflow2.2-tf.data输入模块{2}-tf.data输入实例-10 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
# -*- coding: utf-8 -*- import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 修改警告級別,不顯示警告 import tensorflow as tf# 下載數據集并劃分為訓練集和測試集 (train_images,train_lables),(test_images,test_labels) = tf.keras.datasets.mnist.load_data() # 歸一化 train_images = train_images/255 test_images = test_images/255 print(train_images.shape) # 建立模型創建dataset ds_train_img = tf.data.Dataset.from_tensor_slices(train_images) print(ds_train_img)

# -*- coding: utf-8 -*- import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 修改警告級別,不顯示警告 import tensorflow as tf# 下載數據集并劃分為訓練集和測試集 (train_images,train_lables),(test_images,test_labels) = tf.keras.datasets.mnist.load_data() # 歸一化 train_images = train_images/255 test_images = test_images/255 print(train_images.shape) # 創建dataset ds_train_img = tf.data.Dataset.from_tensor_slices(train_images) print(ds_train_img) ds_train_lab = tf.data.Dataset.from_tensor_slices(train_lables) print(ds_train_lab) # 合并(元組) ds_train = tf.data.Dataset.zip((ds_train_img,ds_train_lab)) print(ds_train) # 取出其中10000個組件進行亂序,無限重復每次輸出64張圖片 ds_train = ds_train.shuffle(10000).repeat().batch(64)# 建立模型 model = tf.keras.Sequential([tf.keras.layers.Flatten(input_shape=(28,28)),tf.keras.layers.Dense(128,activation="relu"),tf.keras.layers.Dense(10,activation="softmax") ]) # 編譯模型 model.compile(optimizer="adam",loss="sparse_categorical_crossentropy",metrics=["accuracy"]) steps_per_epochs = train_images.shape[0]//64 # 我們上面是無限循環迭代,定義每一個epochs訓練多少步 # 訓練模型 一共訓練5次每次訓練 train_images.shape[0]//64個組件 model.fit(ds_train,epochs=5,steps_per_epoch=steps_per_epochs)

# -*- coding: utf-8 -*- import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 修改警告級別,不顯示警告 import tensorflow as tf# 下載數據集并劃分為訓練集和測試集 (train_images,train_lables),(test_images,test_labels) = tf.keras.datasets.mnist.load_data() # 歸一化 train_images = train_images/255 test_images = test_images/255 # print(train_images.shape) # 創建dataset ds_train_img = tf.data.Dataset.from_tensor_slices(train_images) # print(ds_train_img) ds_train_lab = tf.data.Dataset.from_tensor_slices(train_lables) # print(ds_train_lab)# 合并(元組形式放入) ds_train = tf.data.Dataset.zip((ds_train_img,ds_train_lab))# print(ds_train) # 取出其中10000個組件進行亂序,無限重復每次輸出64張圖片 ds_train = ds_train.shuffle(10000).repeat().batch(64) ds_test = tf.data.Dataset.from_tensor_slices((test_images,test_labels))# 創建test數據集放入一個元組 ds_test = ds_test.batch(64)# 每次輸出64個組件 # 建立模型 model = tf.keras.Sequential([tf.keras.layers.Flatten(input_shape=(28,28)),tf.keras.layers.Dense(128,activation="relu"),tf.keras.layers.Dense(10,activation="softmax") ]) # 編譯模型 model.compile(optimizer="adam",loss="sparse_categorical_crossentropy",metrics=["accuracy"]) steps_per_epochs = train_images.shape[0]//64 # 我們上面是無限循環迭代,定義每一個epochs訓練多少步 # 訓練模型 一共訓練5次每次訓練 train_images.shape[0]//64個組件/測試數據ds_test 每次測試10000整除64個組件 model.fit(ds_train,epochs=5,steps_per_epoch=steps_per_epochs,validation_data=ds_test,validation_steps=10000//64)

總結

以上是生活随笔為你收集整理的深度学习-Tensorflow2.2-tf.data输入模块{2}-tf.data输入实例-10的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。