二十、农作物病虫害识别模型

1、准备数据集
    可以从https://www.kaggle.com/datasets中下载,Kaggle是一个数据建模和数据分析竞赛平台。企业和研究者可在其上发布数据,统计学者和数据挖掘专家可在其上进行竞赛以产生最好的模型。
    为了测试,可以使用作为训练数据一部分的验证数据进行评估。


2、模型构建

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

def get_files(directory):
    if not os.path.exists(directory):
        return 0
    count=0
    for current_path,dirs,files in os.walk(directory):
        for dr in dirs:
            count+= len(glob.glob(os.path.join(current_path,dr+"/*")))
    return count

def prepare(img_path):
    img = image.load_img(img_path,

猜你喜欢

转载自blog.csdn.net/vandh/article/details/132589306