当前位置: 首页 > wzjs >正文

品牌网站设计方案红盾工商信息查询网

品牌网站设计方案,红盾工商信息查询网,网站开发培训 价格,微营销推广平台有哪些植物病害检测 植物病害检测是计算机视觉在农业领域的一个重要应用。您将学习如何加载、处理和扩充数据集,构建深度神经网络模型,并在数据集上训练模型。该项目有助于理解图像分类,并通过实现早期病害检测为可持续农业做出贡献。 import os…

植物病害检测

植物病害检测是计算机视觉在农业领域的一个重要应用。您将学习如何加载、处理和扩充数据集,构建深度神经网络模型,并在数据集上训练模型。该项目有助于理解图像分类,并通过实现早期病害检测为可持续农业做出贡献。
在这里插入图片描述

import os
from PIL import Image# import data handling tools
import cv2
import numpy as np
import pandas as pd
import seaborn as sns
import itertools
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, classification_report
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import roc_curve, roc_auc_scorefrom sklearn.cluster import KMeans 
from sklearn.decomposition import PCA
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import StandardScaler , MinMaxScaler
from sklearn.pipeline import Pipeline
import warningswith warnings.catch_warnings():warnings.simplefilter("ignore")
dataset_path = '/kaggle/input/plantdisease/PlantVillage'
selected_classes = ['Pepper__bell___Bacterial_spot', 'Potato___Late_blight', 'Tomato_Late_blight']  data = []
labels = []
# Iterate through the dataset directory
for class_name in os.listdir(dataset_path):if class_name in selected_classes:class_dir = os.path.join(dataset_path, class_name)for img_name in os.listdir(class_dir):img_path = os.path.join(class_dir, img_name)data.append(img_path)labels.append(class_name)df = pd.DataFrame({'data': data, 'label': labels})
df

在这里插入图片描述

image = Image.open("/kaggle/input/plantdisease/PlantVillage/Pepper__bell___Bacterial_spot/0022d6b7-d47c-4ee2-ae9a-392a53f48647___JR_B.Spot 8964.JPG")
width, height = image.size
print(f"Width: {width}, Height: {height}")

在这里插入图片描述

plt.figure(figsize=(20, 15))for i in range(5):plt.subplot(1, 5, i + 1)index = np.random.choice(df.index)filename = df.loc[index, 'data']category = df.loc[index, 'label']img = Image.open(filename)plt.imshow(img)plt.title(f'label: {category}')plt.axis('off') plt.tight_layout()
plt.show()

在这里插入图片描述

def extract_hog_features(image):# Convert the image to grayscale using cv2gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)hog = cv2.HOGDescriptor()# Compute HOG featureshog_features = hog.compute(gray_image)return hog_features.flatten()
df_shuffled = df.sample(frac=1, random_state=42).reset_index(drop=True)
batch_size = 32  # Adjust batch size based on memory constraints
features_list = []
labels_list = []# Resize function to downsample images
def resize_image(image, new_size=(128, 128)):return cv2.resize(image, new_size)for start in range(0, len(df_shuffled), batch_size):end = min(start + batch_size, len(df_shuffled))batch = df_shuffled[start:end]batch_features = []batch_labels = []for index, row in batch.iterrows():image = cv2.imread(row['data'])resized_image = resize_image(image)  # Resize image to smaller dimensionshog_features = extract_hog_features(resized_image)batch_features.append(hog_features)batch_labels.append(row['label'])features_list.extend(batch_features)labels_list.extend(batch_labels)

在这里插入图片描述

# Convert lists to NumPy arrays
features_array = np.array(features_list)
labels_array = np.array(labels_list)
label_encoder = LabelEncoder()
labels_encoded = label_encoder.fit_transform(labels_array)print("Shape of extracted HOG features:", features_scaled.shape)

在这里插入图片描述

len(labels_encoded)
np.unique(labels_encoded)
X_train, X_test, y_train, y_test = train_test_split(features_array, labels_encoded, test_size=0.25, random_state=42 , stratify = labels_encoded)
print(type(X_train), X_train.shape)
print(type(y_train), y_train.shape)
print(type(X_test), X_test.shape)
print(type(y_test), y_test.shape)

在这里插入图片描述

lr_pipeline = Pipeline([('pca', PCA(n_components=2100,random_state=42)), ('classifier', LogisticRegression(max_iter = 1000,random_state=42))
])lr_pipeline.fit(X_train, y_train)

在这里插入图片描述

predictions = lr_pipeline.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(f"Accuracy: {accuracy:.4f}")

在这里插入图片描述

report = classification_report(y_test, predictions, output_dict=True,zero_division=1)# Convert the report to a pandas DataFrame for better visualization
report = pd.DataFrame(report).transpose()print(report)

在这里插入图片描述

classes = selected_classescm = confusion_matrix(y_test, predictions)plt.figure(figsize= (10, 10))
plt.imshow(cm, interpolation= 'nearest', cmap= plt.cm.Blues)
plt.title('Confusion Matrix')
plt.colorbar()tick_marks = np.arange(len(classes))
plt.xticks(tick_marks, classes, rotation= 45)
plt.yticks(tick_marks, classes)thresh = cm.max() / 2.
for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):plt.text(j, i, cm[i, j], horizontalalignment= 'center', color= 'white' if cm[i, j] > thresh else 'black')plt.tight_layout()
plt.ylabel('True Label')
plt.xlabel('Predicted Label')plt.show()

在这里插入图片描述

K-mean

df

在这里插入图片描述

images = [] 
for index2, row2 in df.iterrows():image = cv2.imread(row2['data'])gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)images.append(gray_image)
selected_image = images[0]# Display the image using matplotlib
plt.figure(figsize=(4, 4))
plt.imshow(selected_image, cmap='gray')
plt.show()

在这里插入图片描述

km = KMeans(n_clusters=3, random_state=42, n_init="auto")
km.fit_predict(data)

在这里插入图片描述

fig, ax = plt.subplots(1, 3, figsize=(15, 3))for i in range(3):center_image = km.cluster_centers_[i].reshape(256, 256)  # Reshape to original dimensionsax[i].imshow(center_image, cmap='gray')ax[i].axis('off')ax[i].set_title(f'Cluster {i}')plt.show()

在这里插入图片描述

# Plotting the clustered data
plt.figure(figsize=(8, 6))
cluster_labels = km.labels_
# Scatter plot for each cluster
for cluster in range(3):plt.scatter(data[cluster_labels == cluster, 0],data[cluster_labels == cluster, 1],label=f'Cluster {cluster + 1}')# Plotting centroids if needed
centroids = km.cluster_centers_
plt.scatter(centroids[:, 0], centroids[:, 1], marker='o', s=200, color='black', label='Centroids')plt.title('K-means Clustering')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.legend()
plt.grid(True)
plt.show()

在这里插入图片描述

# 若需要完整数据集以及代码请点击以下链接
https://mbd.pub/o/bread/aJaZl5xt

文章转载自:

http://kvvwVm0t.rttkL.cn
http://mhNATUbK.rttkL.cn
http://gUJcTOfP.rttkL.cn
http://5FrLSFTP.rttkL.cn
http://zDHecXsY.rttkL.cn
http://I1aI7mGa.rttkL.cn
http://3Vusdpmh.rttkL.cn
http://Mv4yEXlN.rttkL.cn
http://ZM9EFqtc.rttkL.cn
http://Eofdiukg.rttkL.cn
http://Kj4CatXf.rttkL.cn
http://f4dkepBp.rttkL.cn
http://jXd31JJU.rttkL.cn
http://wlQRkr3f.rttkL.cn
http://KXnPd0SV.rttkL.cn
http://jhvSqAl1.rttkL.cn
http://YW6xuoT6.rttkL.cn
http://vLX1DSXK.rttkL.cn
http://M0F18qe5.rttkL.cn
http://rtziyEYF.rttkL.cn
http://S6OiSYnF.rttkL.cn
http://Spwu1EuI.rttkL.cn
http://WXdh44wT.rttkL.cn
http://FaqOCrvN.rttkL.cn
http://aN15HJqY.rttkL.cn
http://NgGMzwXp.rttkL.cn
http://Sq6OS1P6.rttkL.cn
http://ZzF9UPWn.rttkL.cn
http://q9ygbc8W.rttkL.cn
http://QgY8YyUC.rttkL.cn
http://www.dtcms.com/wzjs/771502.html

相关文章:

  • 网站栏目设置完整度建设织梦网站分页问题
  • 有一个网站专门做促销小游戏网站建设公司制作网站
  • 共和县公司网站建设宁津网站开发
  • 制作简单门户网站步骤温州企业网站建设公司
  • 出口外贸网站建设免费网站空间和域名
  • 高大上公司网站如何免费制作微信小程序
  • 廊坊网站建设的公司建设网站论文范文
  • 学校网站建设价格明细表长沙专业网站优化定制
  • 网站开发名片公司网站怎么设计制作
  • 武安城乡建设网站wordpress 多站点 主题
  • 句容网站制作公司国外手机网站欣赏
  • jsp做的网站答辩问题深圳华强北电子城
  • 福建网站制作多功能垫块机
  • 建筑企业资质查询官方网站一套完整的工程施工流程
  • 招远网站设计旅游区网站建设
  • 地方网站商城怎么做wordpress 模板获取数据
  • 上海微信网站制作哪家专业知乎推广
  • 破解网站后台密码app网站建设源码
  • 网站建设大量定制阶段网站开发入门看什么
  • 大连建站免费模板软件开发有前途吗
  • 中国关于生态文明建设的网站天猫网站建设目的
  • 做百度手机网站关键词排名大兴手机网站建设
  • app优化网站开发临沂网站制作计划
  • 网站优化外包服务专门做生鲜的网站
  • 网站开发的背景和意义seo是如何优化
  • 甘肃最近发生的重大事情搜索引擎优化培训班
  • 洛阳网站开发培训百度网站推广
  • 找个网页公司做网站微网站有什么好处
  • wordpress customizr电商网站建设关键词优化
  • 怎样用西瓜影音做网站兰州做网站一咨询兰州做网站公司