惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Schneier on Security
A
Arctic Wolf
Scott Helme
Scott Helme
S
Securelist
Schneier on Security
Schneier on Security
W
WeLiveSecurity
Attack and Defense Labs
Attack and Defense Labs
Security Latest
Security Latest
Project Zero
Project Zero
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
C
Check Point Blog
F
Full Disclosure
Stack Overflow Blog
Stack Overflow Blog
H
Hacker News: Front Page
T
The Blog of Author Tim Ferriss
TaoSecurity Blog
TaoSecurity Blog
Vercel News
Vercel News
A
About on SuperTechFans
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The GitHub Blog
The GitHub Blog
S
Security Affairs
Y
Y Combinator Blog
T
The Exploit Database - CXSecurity.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Forbes - Security
Forbes - Security
IT之家
IT之家
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
Jina AI
Jina AI
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
K
Kaspersky official blog
Hacker News: Ask HN
Hacker News: Ask HN
C
Cisco Blogs
MyScale Blog
MyScale Blog
博客园 - 【当耐特】
T
Threat Research - Cisco Blogs
D
Docker
G
GRAHAM CLULEY

编程与诗|飒白的个人博客|飒白的闲话仓库|一位主播和程序员的奇妙组合体

侯捷c++笔记:c++泛型与高级用法 侯捷c++笔记:c++面向对象的指针类 侯捷c++笔记:c++面向对象的无指针类 03《穷查理宝典》 查理·芒格丨读书笔记 02《穷爸爸富爸爸》 罗伯特·清崎丨读书笔记 01《影响力》罗伯特・西奥迪尼丨读书笔记 基于结构光投影三维重建:格雷码编码与解码 给CNN添加TVloss的随记 三维重建论文笔记 DeMoN:Depth and Motion Network for Learning Monocular Stereo 三维扫描系列 点云绪论 修改DCNN使其输入从无监督变为有监督模型 茫茫摄影路:好照片的基本三要素 pytorch学习日记:创建Tensor pytorch学习日记:张量数据类型 研究生涯005 利用蒙特卡洛方法实现21点问题的最优解 研究生涯003 基于最近邻法手写数字识别设计 研究生涯002 汽车模糊推理系统实验 研究生涯001 浅析机器视觉在医疗影像处理中的应用 人工智能问答NO.8 决策树与随机森林
研究生涯004 基于深度学习的水质图像分类
飒白 · 2020-12-09 · via 编程与诗|飒白的个人博客|飒白的闲话仓库|一位主播和程序员的奇妙组合体

本实验全部源码以及数据集以上架面包多(超便宜),点击购买,关注公众号[全都是码农]免费获得更多超值内容!


实验内容

某地区的多个罗非鱼池塘水样数据,包含水产专家按水色判断水质分类的数据,以及用数码相机按照标准进行水色采集的数据,如表1和图1所示。每个水质图片命名规则是“类别-编号.jpg”,如“1_1.jpg”是第一类样本的图片。请根据这些样本,利用数字图像处理技术,通过水色图像实现水质的自动评价。

水色 浅绿色(清水或浊水) 灰蓝色 黄褐色 茶褐色 (姜黄、茶褐、红褐、褐中带绿等) 绿色 (黄绿、油绿、蓝绿、墨绿、绿中带褐等)
水质类别 1 2 3 4 5

图1 水样图像

实验过程

观察样本图片,发现其几乎每张图片都有背景噪声,所以需要先对图像进行预处理,如下代码:

image-20201209112109499

输入fromdir为图片文件夹,todir为输出文件夹。

对处理过的图片进行HSV颜色矩提取并打上标签:

image-20201209112134955

image-20201209112149285

接下来编写神经网络相关代码:

分析csv数据:

image-20201209112310084

读取颜色矩:

image-20201209112329927

定义网络变量:

class NNetConfig():
    num_classes = 5  # 多分类的种类
    num_epochs = 500  # 训练总批次
    print_per_epoch = 100  # 每训练多少批次时打印训练损失函数值和预测准确率值
    # layersls = [9, 20, 30,60,120,60,30, 20, 5]  # 极其不稳定
    # layersls = [9, 20, 30, 60, 120, 60, 30, 20, 5]  # 【输入,隐藏各层节点数,输出】 500轮90%一般,2000轮100%完全拟合
    layersls = [9, 20, 60, 20, 5]  # 【输入,隐藏各层节点数,输出】 500轮 90%稳定 2000轮过拟合

    learning_rate = 0.01  # 网络学习率
    train_filename = './clour/xunshu.csv'  # 训练数据
    test_filename = './clour/ceshu.csv'  # 测试数据
    best_model_savepath = "./dnn/"  # 最好模型的存放文件夹

编写网络:

class NNet(object):
    def __init__(self, config):
        self.config = config
        self.layersls = config.layersls
        self.NNet()

    def NNet(self):  # 根据给出的输入输出及每层网络的节点数搭建深度学习网络
        """
        根据给出的输入输出及每层网络的节点数搭建深度学习网络
        :param layersls: 【输入,隐藏各层节点数,输出】
        :return:
        """
        model = tf.keras.Sequential()
        for i in range(len(config.layersls)):
            if (i == 0):  # 确定网络的输入和网络的第一层节点数
                model.add(tf.keras.layers.Dense(config.layersls[1],
                                                activation="relu",
                                                input_shape=(config.layersls[0],)))
                i += 1
            elif (i == len(config.layersls) - 1):  # 确定网络的输出
                model.add(tf.keras.layers.Dense(config.layersls[i]))
            else:  # 网络的各隐藏层节点数
                model.add(tf.keras.layers.Dense(config.layersls[i],
                                                activation="relu"))
        return model

剩下详细代码自行下载阅读


实验结果

运行zero_slip.py输出如下:

\1.  filename **is** :2_6.jpg 

\2.  the fulll name of the file **is** :.\xun\2_6.jpg 

\3.  parent **is** :.\xun 

\4.  filename **is** :2_7.jpg 

\5.  the fulll name of the file **is** :.\xun\2_7.jpg 

\6.  parent **is** :.\xun 

\7.  <......> 

\8.  the fulll name of the file **is** :.\xun\5_5.jpg 

\9.  parent **is** :.\xun 

\10. filename **is** :5_6.jpg 

\11. the fulll name of the file **is** :.\xun\5_6.jpg 

\12. 训练集集切割完毕 

切割图像部分如下:

img

如图所示切割完整,效果良好。

运行first_feature.py进行特征提取:

1.    以输出颜色矩到./clour/ceshu.csv  
2.    以输出颜色矩到./clour/xunshu.csv  

输出完整。

运行second_train.py:

输出loss值和准确率值:

img

\1.  <DatasetV1Adapter shapes: (), types: tf.string> 

\2.  当前最高准确率:0.455: 

\3.  Epoch 000: Loss: 6.768, Accuracy: 45.455%, isBest:* 

\4.  当前最高准确率:0.591: 

\5.  Epoch 100: Loss: 1.072, Accuracy: 59.091%, isBest:* 

\6.  当前最高准确率:0.636: 

\7.  Epoch 200: Loss: 0.787, Accuracy: 63.636%, isBest:* 

\8.  当前最高准确率:0.727: 

\9.  Epoch 300: Loss: 0.613, Accuracy: 72.727%, isBest:* 

\10. Epoch 400: Loss: 0.723, Accuracy: 68.182%, isBest: 

\11. 开始对已训练网络进行测试: 

\12. <DatasetV1Adapter shapes: (), types: tf.string> 

\13. 测试数据的测试结果为: 72.727% 

\14. tf.Tensor(0.7272727272727273, shape=(), dtype=float64) 

\15. 预测下面1个水质颜色矩的类别(正确答案为:三): 

\16. [[29.5469, 146.3947, 123.1732, 0.864407537, 5.590716583, 1.752484454, 1.029934609, 6.391303213, 2.040322913]] 

\17. ['三'] 

最后输出正确的验证结果。

运行th_app.py并输入图片地址 ./cep/1_50.jpg :

1.    输入图片地址:./cep/1_50.jpg  
2.    此图片为:['一']  

结果正确。


本实验全部源码以及数据集以上架面包多(超便宜),点击购买,关注公众号[全都是码农]免费获得更多超值内容!