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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > 卷积神经网络 >内容正文

卷积神经网络

深度学习之基于卷积神经网络实现服装图像识别

發布時間:2023/12/15 卷积神经网络 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 深度学习之基于卷积神经网络实现服装图像识别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本博客與手寫數字識別大同小異。

1.導入所需庫

import tensorflow as tf from tensorflow.keras import datasets, layers, models from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Conv2D, Flatten, Dropout, MaxPooling2D from tensorflow.keras.preprocessing.image import ImageDataGenerator import os import numpy as np import matplotlib.pyplot as plt

2.數據準備

本階段需要做的工作:
①下載好我們所需要的服裝圖像庫。
②將圖片標準化。
③調整圖像的大小。
(類比與手寫數字識別的數據處理階段)
訓練集和測試集分別為60000和10000

def DataPre():# 導入數據(train_x, train_y), (test_x, test_y) = datasets.fashion_mnist.load_data()# 標準化train_x, test_x = train_x / 255.0, test_x / 255.0# 調整數據???train_x = train_x.reshape((60000, 28, 28, 1))test_x = test_x.reshape((10000, 28, 28, 1))return train_x,train_y,test_x,test_y

3.搭建網絡

網絡結構為:3層卷積池化層+Flatten+兩層全連接層。
(可以嘗試一下更深的網絡結構,硬件條件允許的情況下

def ModelBuild():# 搭建模型model = models.Sequential([layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),layers.MaxPooling2D((2, 2)),layers.Conv2D(64, (3, 3), activation='relu'),layers.MaxPooling2D((2, 2)),layers.Conv2D(64, (3, 3), activation='relu'),layers.Flatten(),layers.Dense(64, activation=tf.nn.softmax),layers.Dense(10)])model.summary() # 打印網絡結構model.compile(optimizer = 'adam',loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),metrics = ['accuracy'])return model

網絡模型為:

Model: "sequential" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= conv2d (Conv2D) (None, 26, 26, 32) 320 _________________________________________________________________ max_pooling2d (MaxPooling2D) (None, 13, 13, 32) 0 _________________________________________________________________ conv2d_1 (Conv2D) (None, 11, 11, 64) 18496 _________________________________________________________________ max_pooling2d_1 (MaxPooling2 (None, 5, 5, 64) 0 _________________________________________________________________ conv2d_2 (Conv2D) (None, 3, 3, 64) 36928 _________________________________________________________________ flatten (Flatten) (None, 576) 0 _________________________________________________________________ dense (Dense) (None, 0) 0 _________________________________________________________________ dense_1 (Dense) (None, 64) 64 _________________________________________________________________ dense_2 (Dense) (None, 10) 650 ================================================================= Total params: 56,458 Trainable params: 56,458 Non-trainable params: 0 _________________________________________________________________ Train on 60000 samples, validate on 10000 samples

4.模型訓練

由于硬件原因,epochs設置的是10,經過實驗證明,epochs在50的時候,效果是明顯好于10的情況。

def Modeltrain(model,train_x,train_y,test_x,test_y):# 訓練模型history = model.fit(train_x, train_y, epochs=10,validation_data=(test_x, test_y))return history

5.結果可視化

accuracy = history.history["accuracy"]test_accuracy = history.history["val_accuracy"]loss = history.history["loss"]test_loss = history.history["val_loss"]epochs_range = range(10)plt.figure(figsize=(50, 5))plt.subplot(1, 2, 1)plt.plot(epochs_range, accuracy, label="Training Acc")plt.plot(epochs_range, test_accuracy, label="Test Acc")plt.legend()plt.title("Training and Test Acc")plt.subplot(1, 2, 2)plt.plot(epochs_range, loss, label="Training loss")plt.plot(epochs_range, test_loss, label="Test loss")plt.legend()plt.title("Training and Test loss")plt.show()

6.結果

10000/1 - 1s - loss: 0.2716 - accuracy: 0.8840


并沒有出現過擬合的情況,但是準確率并不是特別高,在增加epochs的情況下是可以提高準確率的。但是訓練速度會明顯變慢,而且提升效果并不大。可以嘗試一下利用遷移學習,利用別人搭建好的網絡,準確率可能會上升。
努力加油a啊

總結

以上是生活随笔為你收集整理的深度学习之基于卷积神经网络实现服装图像识别的全部內容,希望文章能夠幫你解決所遇到的問題。

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