中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

做網(wǎng)站前端后端ui什么意思谷歌優(yōu)化排名怎么做

做網(wǎng)站前端后端ui什么意思,谷歌優(yōu)化排名怎么做,poi player wordpress,免費(fèi)的黃岡網(wǎng)站有哪些平臺(tái)游戲軟件文章目錄 0 前言1 項(xiàng)目背景2 花卉識(shí)別的基本原理3 算法實(shí)現(xiàn)3.1 預(yù)處理3.2 特征提取和選擇3.3 分類(lèi)器設(shè)計(jì)和決策3.4 卷積神經(jīng)網(wǎng)絡(luò)基本原理 4 算法實(shí)現(xiàn)4.1 花卉圖像數(shù)據(jù)4.2 模塊組成 5 項(xiàng)目執(zhí)行結(jié)果6 最后 0 前言 🔥 優(yōu)質(zhì)競(jìng)賽項(xiàng)目系列,今天要分享的是 &a…

文章目錄

  • 0 前言
  • 1 項(xiàng)目背景
  • 2 花卉識(shí)別的基本原理
  • 3 算法實(shí)現(xiàn)
    • 3.1 預(yù)處理
    • 3.2 特征提取和選擇
    • 3.3 分類(lèi)器設(shè)計(jì)和決策
    • 3.4 卷積神經(jīng)網(wǎng)絡(luò)基本原理
  • 4 算法實(shí)現(xiàn)
    • 4.1 花卉圖像數(shù)據(jù)
    • 4.2 模塊組成
  • 5 項(xiàng)目執(zhí)行結(jié)果
  • 6 最后

0 前言

🔥 優(yōu)質(zhì)競(jìng)賽項(xiàng)目系列,今天要分享的是

🚩 深度學(xué)習(xí)花卉識(shí)別 - python 機(jī)器視覺(jué) opencv

該項(xiàng)目較為新穎,適合作為競(jìng)賽課題方向,學(xué)長(zhǎng)非常推薦!

🥇學(xué)長(zhǎng)這里給一個(gè)題目綜合評(píng)分(每項(xiàng)滿(mǎn)分5分)

  • 難度系數(shù):3分
  • 工作量:3分
  • 創(chuàng)新點(diǎn):4分

🧿 更多資料, 項(xiàng)目分享:

https://gitee.com/dancheng-senior/postgraduate

1 項(xiàng)目背景

在我國(guó)有著成千上萬(wàn)種花卉, 但如何能方便快捷的識(shí)別辨識(shí)出這些花卉的種類(lèi)成為了植物學(xué)領(lǐng)域的重要研究課題。 我國(guó)的花卉研究歷史悠久,
是世界上研究較早的國(guó)家之一。 花卉是我國(guó)重要的物產(chǎn)資源, 除美化了環(huán)境, 調(diào)養(yǎng)身心外, 它還具有藥用價(jià)值, 并且在醫(yī)學(xué)領(lǐng)域?yàn)楸U先藗兊慕】灯鹬匾饔谩?/p>

花卉識(shí)別是植物學(xué)領(lǐng)域的一個(gè)重要課題, 多年來(lái)已經(jīng)形成一定體系化分類(lèi)系統(tǒng),但需要植物學(xué)家耗費(fèi)大量的精力人工分析。 這種方法要求我們首先去了解花卉的生長(zhǎng)環(huán)境,
近而去研究花卉的整體形態(tài)特征。 在觀察植株形態(tài)特征時(shí)尤其是重點(diǎn)觀察花卉的花蕊特征、 花卉的紋理顏色和形狀及其相關(guān)信息等。 然后在和現(xiàn)有的樣本進(jìn)行比對(duì),
最終確定花卉的所屬類(lèi)別。

2 花卉識(shí)別的基本原理

花卉種類(lèi)識(shí)別功能實(shí)現(xiàn)的主要途徑是利用計(jì)算機(jī)對(duì)樣本進(jìn)行分類(lèi)。 通過(guò)對(duì)樣本的精準(zhǔn)分類(lèi)達(dá)到得出圖像識(shí)別結(jié)果的目的。 經(jīng)典的花卉識(shí)別設(shè)計(jì)如下圖 所示,
這幾個(gè)過(guò)程相互關(guān)聯(lián)而又有明顯區(qū)別。

在這里插入圖片描述

3 算法實(shí)現(xiàn)

3.1 預(yù)處理

預(yù)處理是對(duì)處于最低抽象級(jí)別的圖像進(jìn)行操作的通用名稱(chēng), 輸入和輸出均為強(qiáng)度圖像。 為了使實(shí)驗(yàn)結(jié)果更精準(zhǔn), 需要對(duì)圖像數(shù)據(jù)進(jìn)行預(yù)處理, 比如,
根據(jù)需要增強(qiáng)圖像質(zhì)量、 將圖像裁剪成大小一致的形狀、 避免不必要的失真等等。

3.2 特征提取和選擇

要想獲取花卉圖像中的最具代表性的隱含信息, 就必須對(duì)花卉圖像數(shù)據(jù)集進(jìn)行相應(yīng)的變換。

特征提取旨在通過(guò)從現(xiàn)有特征中創(chuàng)建新特征(然后丟棄原始特征) 來(lái)減少數(shù)據(jù)集中的特征數(shù)量。 然后, 這些新的簡(jiǎn)化功能集應(yīng)該能夠匯總原始功能集中包含的大多數(shù)信息。
這樣, 可以從原始集合的組合中創(chuàng)建原始特征的摘要版本。 對(duì)所獲取的信息實(shí)現(xiàn)從測(cè)量空間到特征空間的轉(zhuǎn)換。

3.3 分類(lèi)器設(shè)計(jì)和決策

構(gòu)建完整系統(tǒng)的適當(dāng)分類(lèi)器組件的任務(wù)是使用特征提取器提供的特征向量將對(duì)象分配給類(lèi)別。 由于完美的分類(lèi)性能通常是不可能實(shí)現(xiàn)的,
因此一般的任務(wù)是確定每種可能類(lèi)別的概率。 輸入數(shù)據(jù)的特征向量表示所提供的抽象使得能夠開(kāi)發(fā)出在盡可能大程度上與領(lǐng)域無(wú)關(guān)的分類(lèi)理論。

在這里插入圖片描述
在這里插入圖片描述

在設(shè)計(jì)階段, 決策功能必須重復(fù)多次, 直到錯(cuò)誤達(dá)到特定條件為止。 分類(lèi)決策是在分類(lèi)器設(shè)計(jì)階段基于預(yù)處理、 特征提取與選擇及判決函數(shù)建立的模型,
對(duì)接收到的樣本數(shù)據(jù)進(jìn)行歸類(lèi), 然后輸出分類(lèi)結(jié)果。

3.4 卷積神經(jīng)網(wǎng)絡(luò)基本原理

卷積神經(jīng)網(wǎng)絡(luò)是受到生物學(xué)啟發(fā)的深度學(xué)習(xí)經(jīng)典的多層前饋神經(jīng)網(wǎng)絡(luò)結(jié)構(gòu)。 是一種在圖像分類(lèi)中廣泛使用的機(jī)器學(xué)習(xí)算法。

CNN 的靈感來(lái)自我們?nèi)祟?lèi)實(shí)際看到并識(shí)別物體的方式。 這是基于一種方法,即我們眼睛中的神經(jīng)元細(xì)胞只接收到整個(gè)對(duì)象的一小部分,而這些小塊(稱(chēng)為接受場(chǎng))
被組合在一起以形成整個(gè)對(duì)象。與其他的人工視覺(jué)算法不一樣的是 CNN 可以處理特定任務(wù)的多個(gè)階段的不變特征。
卷積神經(jīng)網(wǎng)絡(luò)使用的并不像經(jīng)典的人工神經(jīng)網(wǎng)絡(luò)那樣的全連接層, 而是通過(guò)采取局部連接和權(quán)值共享的方法, 來(lái)使訓(xùn)練的參數(shù)量減少, 降低模型的訓(xùn)練復(fù)雜度。

CNN 在圖像分類(lèi)和其他識(shí)別任務(wù)方面已經(jīng)使傳統(tǒng)技術(shù)的識(shí)別效果得到顯著的改善。 由于在過(guò)去的幾年中卷積網(wǎng)絡(luò)的快速發(fā)展, 對(duì)象分類(lèi)和目標(biāo)檢測(cè)能力取得喜人的成績(jī)。

典型的 CNN 含有多個(gè)卷積層和池化層, 并具有全連接層以產(chǎn)生任務(wù)的最終結(jié)果。 在圖像分類(lèi)中, 最后一層的每個(gè)單元表示分類(lèi)概率。

在這里插入圖片描述

4 算法實(shí)現(xiàn)

4.1 花卉圖像數(shù)據(jù)

花卉圖像的獲取除了通過(guò)用拍攝設(shè)備手工收集或是通過(guò)網(wǎng)絡(luò)下載已經(jīng)整理好的現(xiàn)有數(shù)據(jù)集, 還可以通過(guò)網(wǎng)絡(luò)爬蟲(chóng)技術(shù)收集整理自己的數(shù)據(jù)集。

在這里插入圖片描述

以roses種類(lèi)的訓(xùn)練數(shù)據(jù)為例,文件夾內(nèi)部均為該種類(lèi)花的圖像文件

在這里插入圖片描述

4.2 模塊組成

示例代碼主要由四個(gè)模塊組成:

  • input_data.py——圖像特征提取模塊,模塊生成四種花的品類(lèi)圖片路徑及對(duì)應(yīng)標(biāo)簽的List
  • model.py——模型模塊,構(gòu)建完整的CNN模型
  • train.py——訓(xùn)練模塊,訓(xùn)練模型,并保存訓(xùn)練模型結(jié)果
  • test.py——測(cè)試模塊,測(cè)試模型對(duì)圖片識(shí)別的準(zhǔn)確度

項(xiàng)目模塊執(zhí)行順序

運(yùn)行train.py開(kāi)始訓(xùn)練。
訓(xùn)練完成后- 運(yùn)行test.py,查看實(shí)際測(cè)試結(jié)果
input_data.py——圖像特征提取模塊,模塊生成四種花的品類(lèi)圖片路徑及對(duì)應(yīng)標(biāo)簽的List

?

import os
import math
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt# -----------------生成圖片路徑和標(biāo)簽的List------------------------------------
train_dir = 'D:/ML/flower/input_data'roses = []
label_roses = []
tulips = []
label_tulips = []
dandelion = []
label_dandelion = []
sunflowers = []
label_sunflowers = []

定義函數(shù)get_files,獲取圖片列表及標(biāo)簽列表

?

# step1:獲取所有的圖片路徑名,存放到# 對(duì)應(yīng)的列表中,同時(shí)貼上標(biāo)簽,存放到label列表中。def get_files(file_dir, ratio):for file in os.listdir(file_dir + '/roses'):roses.append(file_dir + '/roses' + '/' + file)label_roses.append(0)for file in os.listdir(file_dir + '/tulips'):tulips.append(file_dir + '/tulips' + '/' + file)label_tulips.append(1)for file in os.listdir(file_dir + '/dandelion'):dandelion.append(file_dir + '/dandelion' + '/' + file)label_dandelion.append(2)for file in os.listdir(file_dir + '/sunflowers'):sunflowers.append(file_dir + '/sunflowers' + '/' + file)label_sunflowers.append(3)# step2:對(duì)生成的圖片路徑和標(biāo)簽List做打亂處理image_list = np.hstack((roses, tulips, dandelion, sunflowers))label_list = np.hstack((label_roses, label_tulips, label_dandelion, label_sunflowers))# 利用shuffle打亂順序temp = np.array([image_list, label_list])temp = temp.transpose()np.random.shuffle(temp)# 將所有的img和lab轉(zhuǎn)換成listall_image_list = list(temp[:, 0])all_label_list = list(temp[:, 1])# 將所得List分為兩部分,一部分用來(lái)訓(xùn)練tra,一部分用來(lái)測(cè)試val# ratio是測(cè)試集的比例n_sample = len(all_label_list)n_val = int(math.ceil(n_sample * ratio))  # 測(cè)試樣本數(shù)n_train = n_sample - n_val  # 訓(xùn)練樣本數(shù)tra_images = all_image_list[0:n_train]tra_labels = all_label_list[0:n_train]tra_labels = [int(float(i)) for i in tra_labels]val_images = all_image_list[n_train:-1]val_labels = all_label_list[n_train:-1]val_labels = [int(float(i)) for i in val_labels]return tra_images, tra_labels, val_images, val_labels**定義函數(shù)get_batch,生成訓(xùn)練批次數(shù)據(jù)**# --------------------生成Batch----------------------------------------------# step1:將上面生成的List傳入get_batch() ,轉(zhuǎn)換類(lèi)型,產(chǎn)生一個(gè)輸入隊(duì)列queue,因?yàn)閕mg和lab# 是分開(kāi)的,所以使用tf.train.slice_input_producer(),然后用tf.read_file()從隊(duì)列中讀取圖像#   image_W, image_H, :設(shè)置好固定的圖像高度和寬度#   設(shè)置batch_size:每個(gè)batch要放多少?gòu)垐D片#   capacity:一個(gè)隊(duì)列最大多少定義函數(shù)get_batch,生成訓(xùn)練批次數(shù)據(jù)def get_batch(image, label, image_W, image_H, batch_size, capacity):# 轉(zhuǎn)換類(lèi)型image = tf.cast(image, tf.string)label = tf.cast(label, tf.int32)# make an input queueinput_queue = tf.train.slice_input_producer([image, label])label = input_queue[1]image_contents = tf.read_file(input_queue[0])  # read img from a queue# step2:將圖像解碼,不同類(lèi)型的圖像不能混在一起,要么只用jpeg,要么只用png等。image = tf.image.decode_jpeg(image_contents, channels=3)# step3:數(shù)據(jù)預(yù)處理,對(duì)圖像進(jìn)行旋轉(zhuǎn)、縮放、裁剪、歸一化等操作,讓計(jì)算出的模型更健壯。image = tf.image.resize_image_with_crop_or_pad(image, image_W, image_H)image = tf.image.per_image_standardization(image)# step4:生成batch# image_batch: 4D tensor [batch_size, width, height, 3],dtype=tf.float32# label_batch: 1D tensor [batch_size], dtype=tf.int32image_batch, label_batch = tf.train.batch([image, label],batch_size=batch_size,num_threads=32,capacity=capacity)# 重新排列l(wèi)abel,行數(shù)為[batch_size]label_batch = tf.reshape(label_batch, [batch_size])image_batch = tf.cast(image_batch, tf.float32)return image_batch, label_batch**model.py——CN模型構(gòu)建**import tensorflow as tf#定義函數(shù)infence,定義CNN網(wǎng)絡(luò)結(jié)構(gòu)#卷積神經(jīng)網(wǎng)絡(luò),卷積加池化*2,全連接*2,softmax分類(lèi)#卷積層1def inference(images, batch_size, n_classes):with tf.variable_scope('conv1') as scope:weights = tf.Variable(tf.truncated_normal(shape=[3,3,3,64],stddev=1.0,dtype=tf.float32),name = 'weights',dtype=tf.float32)biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[64]),name='biases', dtype=tf.float32)conv = tf.nn.conv2d(images, weights, strides=[1, 1, 1, 1], padding='SAME')pre_activation = tf.nn.bias_add(conv, biases)conv1 = tf.nn.relu(pre_activation, name=scope.name)# 池化層1# 3x3最大池化,步長(zhǎng)strides為2,池化后執(zhí)行l(wèi)rn()操作,局部響應(yīng)歸一化,對(duì)訓(xùn)練有利。with tf.variable_scope('pooling1_lrn') as scope:pool1 = tf.nn.max_pool(conv1, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], padding='SAME', name='pooling1')norm1 = tf.nn.lrn(pool1, depth_radius=4, bias=1.0, alpha=0.001 / 9.0, beta=0.75, name='norm1')# 卷積層2# 16個(gè)3x3的卷積核(16通道),padding=’SAME’,表示padding后卷積的圖與原圖尺寸一致,激活函數(shù)relu()with tf.variable_scope('conv2') as scope:weights = tf.Variable(tf.truncated_normal(shape=[3, 3, 64, 16], stddev=0.1, dtype=tf.float32),name='weights', dtype=tf.float32)biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[16]),name='biases', dtype=tf.float32)conv = tf.nn.conv2d(norm1, weights, strides=[1, 1, 1, 1], padding='SAME')pre_activation = tf.nn.bias_add(conv, biases)conv2 = tf.nn.relu(pre_activation, name='conv2')# 池化層2# 3x3最大池化,步長(zhǎng)strides為2,池化后執(zhí)行l(wèi)rn()操作,# pool2 and norm2with tf.variable_scope('pooling2_lrn') as scope:norm2 = tf.nn.lrn(conv2, depth_radius=4, bias=1.0, alpha=0.001 / 9.0, beta=0.75, name='norm2')pool2 = tf.nn.max_pool(norm2, ksize=[1, 3, 3, 1], strides=[1, 1, 1, 1], padding='SAME', name='pooling2')# 全連接層3# 128個(gè)神經(jīng)元,將之前pool層的輸出reshape成一行,激活函數(shù)relu()with tf.variable_scope('local3') as scope:reshape = tf.reshape(pool2, shape=[batch_size, -1])dim = reshape.get_shape()[1].valueweights = tf.Variable(tf.truncated_normal(shape=[dim, 128], stddev=0.005, dtype=tf.float32),name='weights', dtype=tf.float32)biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[128]),name='biases', dtype=tf.float32)local3 = tf.nn.relu(tf.matmul(reshape, weights) + biases, name=scope.name)# 全連接層4# 128個(gè)神經(jīng)元,激活函數(shù)relu()with tf.variable_scope('local4') as scope:weights = tf.Variable(tf.truncated_normal(shape=[128, 128], stddev=0.005, dtype=tf.float32),name='weights', dtype=tf.float32)biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[128]),name='biases', dtype=tf.float32)local4 = tf.nn.relu(tf.matmul(local3, weights) + biases, name='local4')# dropout層#    with tf.variable_scope('dropout') as scope:#        drop_out = tf.nn.dropout(local4, 0.8)# Softmax回歸層# 將前面的FC層輸出,做一個(gè)線性回歸,計(jì)算出每一類(lèi)的得分with tf.variable_scope('softmax_linear') as scope:weights = tf.Variable(tf.truncated_normal(shape=[128, n_classes], stddev=0.005, dtype=tf.float32),name='softmax_linear', dtype=tf.float32)biases = tf.Variable(tf.constant(value=0.1, dtype=tf.float32, shape=[n_classes]),name='biases', dtype=tf.float32)softmax_linear = tf.add(tf.matmul(local4, weights), biases, name='softmax_linear')return softmax_linear# -----------------------------------------------------------------------------# loss計(jì)算# 傳入?yún)?shù):logits,網(wǎng)絡(luò)計(jì)算輸出值。labels,真實(shí)值,在這里是0或者1# 返回參數(shù):loss,損失值def losses(logits, labels):with tf.variable_scope('loss') as scope:cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=labels,name='xentropy_per_example')loss = tf.reduce_mean(cross_entropy, name='loss')tf.summary.scalar(scope.name + '/loss', loss)return loss# --------------------------------------------------------------------------# loss損失值優(yōu)化# 輸入?yún)?shù):loss。learning_rate,學(xué)習(xí)速率。# 返回參數(shù):train_op,訓(xùn)練op,這個(gè)參數(shù)要輸入sess.run中讓模型去訓(xùn)練。def trainning(loss, learning_rate):with tf.name_scope('optimizer'):optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate)global_step = tf.Variable(0, name='global_step', trainable=False)train_op = optimizer.minimize(loss, global_step=global_step)return train_op# -----------------------------------------------------------------------# 評(píng)價(jià)/準(zhǔn)確率計(jì)算# 輸入?yún)?shù):logits,網(wǎng)絡(luò)計(jì)算值。labels,標(biāo)簽,也就是真實(shí)值,在這里是0或者1。# 返回參數(shù):accuracy,當(dāng)前step的平均準(zhǔn)確率,也就是在這些batch中多少?gòu)垐D片被正確分類(lèi)了。def evaluation(logits, labels):with tf.variable_scope('accuracy') as scope:correct = tf.nn.in_top_k(logits, labels, 1)correct = tf.cast(correct, tf.float16)accuracy = tf.reduce_mean(correct)tf.summary.scalar(scope.name + '/accuracy', accuracy)return accuracy**train.py——利用D:/ML/flower/input_data/路徑下的訓(xùn)練數(shù)據(jù),對(duì)CNN模型進(jìn)行訓(xùn)練**import input_dataimport model# 變量聲明N_CLASSES = 4  # 四種花類(lèi)型IMG_W = 64  # resize圖像,太大的話訓(xùn)練時(shí)間久IMG_H = 64BATCH_SIZE = 20CAPACITY = 200MAX_STEP = 2000  # 一般大于10Klearning_rate = 0.0001  # 一般小于0.0001# 獲取批次batchtrain_dir = 'F:/input_data'  # 訓(xùn)練樣本的讀入路徑logs_train_dir = 'F:/save'  # logs存儲(chǔ)路徑# train, train_label = input_data.get_files(train_dir)train, train_label, val, val_label = input_data.get_files(train_dir, 0.3)# 訓(xùn)練數(shù)據(jù)及標(biāo)簽train_batch, train_label_batch = input_data.get_batch(train, train_label, IMG_W, IMG_H, BATCH_SIZE, CAPACITY)# 測(cè)試數(shù)據(jù)及標(biāo)簽val_batch, val_label_batch = input_data.get_batch(val, val_label, IMG_W, IMG_H, BATCH_SIZE, CAPACITY)# 訓(xùn)練操作定義train_logits = model.inference(train_batch, BATCH_SIZE, N_CLASSES)train_loss = model.losses(train_logits, train_label_batch)train_op = model.trainning(train_loss, learning_rate)train_acc = model.evaluation(train_logits, train_label_batch)# 測(cè)試操作定義test_logits = model.inference(val_batch, BATCH_SIZE, N_CLASSES)test_loss = model.losses(test_logits, val_label_batch)test_acc = model.evaluation(test_logits, val_label_batch)# 這個(gè)是log匯總記錄summary_op = tf.summary.merge_all()# 產(chǎn)生一個(gè)會(huì)話sess = tf.Session()# 產(chǎn)生一個(gè)writer來(lái)寫(xiě)log文件train_writer = tf.summary.FileWriter(logs_train_dir, sess.graph)# val_writer = tf.summary.FileWriter(logs_test_dir, sess.graph)# 產(chǎn)生一個(gè)saver來(lái)存儲(chǔ)訓(xùn)練好的模型saver = tf.train.Saver()# 所有節(jié)點(diǎn)初始化sess.run(tf.global_variables_initializer())# 隊(duì)列監(jiān)控coord = tf.train.Coordinator()threads = tf.train.start_queue_runners(sess=sess, coord=coord)# 進(jìn)行batch的訓(xùn)練try:# 執(zhí)行MAX_STEP步的訓(xùn)練,一步一個(gè)batchfor step in np.arange(MAX_STEP):if coord.should_stop():break_, tra_loss, tra_acc = sess.run([train_op, train_loss, train_acc])# 每隔50步打印一次當(dāng)前的loss以及acc,同時(shí)記錄log,寫(xiě)入writerif step % 10 == 0:print('Step %d, train loss = %.2f, train accuracy = %.2f%%' % (step, tra_loss, tra_acc * 100.0))summary_str = sess.run(summary_op)train_writer.add_summary(summary_str, step)# 每隔100步,保存一次訓(xùn)練好的模型if (step + 1) == MAX_STEP:checkpoint_path = os.path.join(logs_train_dir, 'model.ckpt')saver.save(sess, checkpoint_path, global_step=step)except tf.errors.OutOfRangeError:print('Done training -- epoch limit reached')finally:coord.request_stop()**test.py——利用D:/ML/flower/flower_photos/roses路徑下的測(cè)試數(shù)據(jù),查看識(shí)別效果**import matplotlib.pyplot as pltimport modelfrom input_data import get_files# 獲取一張圖片def get_one_image(train):# 輸入?yún)?shù):train,訓(xùn)練圖片的路徑# 返回參數(shù):image,從訓(xùn)練圖片中隨機(jī)抽取一張圖片n = len(train)ind = np.random.randint(0, n)img_dir = train[ind]  # 隨機(jī)選擇測(cè)試的圖片img = Image.open(img_dir)plt.imshow(img)plt.show()image = np.array(img)return image# 測(cè)試圖片def evaluate_one_image(image_array):with tf.Graph().as_default():BATCH_SIZE = 1N_CLASSES = 4image = tf.cast(image_array, tf.float32)image = tf.image.per_image_standardization(image)image = tf.reshape(image, [1, 64, 64, 3])logit = model.inference(image, BATCH_SIZE, N_CLASSES)logit = tf.nn.softmax(logit)x = tf.placeholder(tf.float32, shape=[64, 64, 3])# you need to change the directories to yours.logs_train_dir = 'F:/save/'saver = tf.train.Saver()with tf.Session() as sess:print("Reading checkpoints...")ckpt = tf.train.get_checkpoint_state(logs_train_dir)if ckpt and ckpt.model_checkpoint_path:global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]saver.restore(sess, ckpt.model_checkpoint_path)print('Loading success, global_step is %s' % global_step)else:print('No checkpoint file found')prediction = sess.run(logit, feed_dict={x: image_array})max_index = np.argmax(prediction)if max_index == 0:result = ('這是玫瑰花的可能性為: %.6f' % prediction[:, 0])elif max_index == 1:result = ('這是郁金香的可能性為: %.6f' % prediction[:, 1])elif max_index == 2:result = ('這是蒲公英的可能性為: %.6f' % prediction[:, 2])else:result = ('這是這是向日葵的可能性為: %.6f' % prediction[:, 3])return result# ------------------------------------------------------------------------if __name__ == '__main__':img = Image.open('F:/input_data/dandelion/1451samples2.jpg')plt.imshow(img)plt.show()imag = img.resize([64, 64])image = np.array(imag)print(evaluate_one_image(image))

5 項(xiàng)目執(zhí)行結(jié)果

執(zhí)行train模塊,結(jié)果如下:
在這里插入圖片描述
同時(shí),訓(xùn)練結(jié)束后,在電腦指定的訓(xùn)練模型存儲(chǔ)路徑可看到保存的訓(xùn)練好的模型數(shù)據(jù)。
在這里插入圖片描述

執(zhí)行test模塊,結(jié)果如下:

在這里插入圖片描述
關(guān)閉顯示的測(cè)試圖片后,console查看測(cè)試結(jié)果如下:
在這里插入圖片描述

做一個(gè)GUI交互界面

在這里插入圖片描述

6 最后

🧿 更多資料, 項(xiàng)目分享:

https://gitee.com/dancheng-senior/postgraduate

http://www.risenshineclean.com/news/48923.html

相關(guān)文章:

  • 廣東省城鄉(xiāng)建設(shè)和管理委員會(huì)網(wǎng)站谷歌瀏覽器下載電腦版
  • 家居網(wǎng)站源碼軟文推送
  • 購(gòu)買(mǎi)網(wǎng)站服務(wù)如何做支出seo是什么崗位簡(jiǎn)稱(chēng)
  • 想學(xué)網(wǎng)站建設(shè)開(kāi)發(fā)代運(yùn)營(yíng)一般收費(fèi)
  • 蚌埠公司做網(wǎng)站網(wǎng)絡(luò)推廣員為什么做不長(zhǎng)
  • 做的網(wǎng)站怎么放在網(wǎng)上百度的人工客服電話
  • h5頁(yè)面生成青島seo精靈
  • 微信朋友圈推廣平臺(tái)seo銷(xiāo)售代表招聘
  • golang做網(wǎng)站怎么樣微信群免費(fèi)推廣平臺(tái)
  • 網(wǎng)站做違法的事情投訴百度推廣賬號(hào)登錄入口
  • 香港空間送網(wǎng)站如何利用seo賺錢(qián)
  • 昌平網(wǎng)站建設(shè)騰訊會(huì)議付費(fèi)
  • 什么是網(wǎng)站的后臺(tái)垂直搜索引擎
  • 建設(shè)思想政治教育專(zhuān)題網(wǎng)站個(gè)人網(wǎng)站首頁(yè)設(shè)計(jì)
  • 誰(shuí)可以教我做網(wǎng)站南京廣告宣傳公司seo
  • 付給招聘網(wǎng)站的費(fèi)用怎么做分錄深圳整站seo
  • 深圳網(wǎng)站建設(shè)智能 樂(lè)云踐新淘寶站內(nèi)推廣方式有哪些
  • 男人最?lèi)?ài)的做網(wǎng)站站長(zhǎng)之家統(tǒng)計(jì)
  • 怎樣創(chuàng)建網(wǎng)站詳細(xì)步驟seo技術(shù)優(yōu)化服務(wù)
  • 有經(jīng)驗(yàn)的南昌網(wǎng)站制作百度關(guān)鍵詞優(yōu)化策略
  • 廣告網(wǎng)站模板下載 迅雷下載安裝網(wǎng)站維護(hù)費(fèi)一年多少錢(qián)
  • WordPress網(wǎng)站論文微信小程序開(kāi)發(fā)文檔
  • 免費(fèi)模板建站寧德市醫(yī)院東僑院區(qū)
  • 做網(wǎng)站自動(dòng)賺錢(qián)網(wǎng)絡(luò)推廣都需要做什么
  • 佛山專(zhuān)注網(wǎng)站制作細(xì)節(jié)長(zhǎng)沙縣網(wǎng)絡(luò)營(yíng)銷(xiāo)咨詢(xún)
  • 網(wǎng)站開(kāi)發(fā)工程師培訓(xùn)seo是什么職業(yè)
  • 兼職網(wǎng)站開(kāi)發(fā)全部視頻支持代表手機(jī)瀏覽器
  • 三河建設(shè)局網(wǎng)站熱門(mén)seo推廣排名穩(wěn)定
  • 網(wǎng)站備案 修改優(yōu)化seo廠家
  • 網(wǎng)站制作 徐州晉江怎么交換友情鏈接