บทนำ
Agriculture is more than just a job for many Indians; it’s a way of life. It’s the means through which they support their livelihoods and contribute immensely to India’s economy. Determination of the type of soil that has the clay, sand, and silt particles in the respective proportions is important for suitable crop selection and identifying the weed’s growth. Discover the potential of Deep Learning in Agriculture. Understand the importance of soil types and weed detection for India.
เรียนรู้อย่างลึกซึ้ง is an emerging technology that is helpful in every field. Deep learning has been popularly applied in smart agriculture across scales for field monitoring, field operation, robotics, predicting soil, water, climate conditions, and landscape-level land and crop types monitoring. We can feed the photo of soil to a deep learning architecture, guide it to learn to detect features, and then use the deep learning architecture to classify the soil.
In this blog, we will discuss the importance of soil in agriculture. We will classify soil using machine learning and deep learning models.
วัตถุประสงค์การเรียนรู้
- You will understand how important soil is in agriculture.
- You will learn how machine learning algorithms can classify soil types.
- You will implement a deep learning model in agriculture to classify soil types.
- Explore the concept of multi-stacking ensemble learning to increase the accuracy of our predictions.
บทความนี้เผยแพร่โดยเป็นส่วนหนึ่งของไฟล์ Blogathon วิทยาศาสตร์ข้อมูล
สารบัญ
The Role of Soil in Agriculture
Organic matter, minerals, gases, liquids, and other substances excreted from plants and animals form important soil, a foundation for agriculture. The foundation of agriculture lies in the gases, minerals, organic matter, and other substances that come from plants and animals, forming the soil system.
India’s economy purely relies on agriculture; the soil is important for the crops, and it leads to the development of unwanted weeds due to its fertility.
Moisture and temperature are the physical variables that impact the formation of pores and particles in the soil, affecting root growth, water infiltration, and plant emergence speed.
But mainly, the soil has particles of sand and clay. Amidst the prevalently available soil particles, clay is plentiful in the exploration site. Clay particle’s availability on the surface is due to the plentiful nutrition supplied. The peat and loam are hardly present. The clay-type soil is spacious in between, wherein the water is retained.
ชุด
Feature extraction is one of the main steps in building a good deep-learning model. It is important to identify features that may be necessary for building the machine learning algorithms. We will use the มโหตร library to extract Haralick features, which have spatial and texture information of the images.
We will use skimage library to convert images to grayscale and to extract Histogram of Gradient (HOG) features which are useful for object detection. Finally, we will concatenate the values of the features into an array and later use them in machine learning and deep learning algorithms.
import mahotas as mh
from skimage import color, feature, io
import numpy as np
# Function to extract features from an image
def extract_features(image_path):
img = io.imread(image_path)
gray_img = color.rgb2gray(img) # Converting image to grayscale
# Converting the grayscale image to integer type
gray_img_int = (gray_img * 255).astype(np.uint8)
# Extracting Haralick features using mahotas
haralick_features = mh.features.haralick(gray_img_int).mean(axis=0)
# Extracting Histogram of Gradients (HOG) features
hog_features, _ = feature.hog(gray_img, visualize=True)
# Printing the first few elements of each feature array
print("Haralick Features:", haralick_features[:5])
print("HOG Features:", hog_features[:5])
# Concatenating the features into a single array
all_features = np.concatenate((haralick_features, hog_features))
return all_features
image_path = '/kaggle/input/soil-classification-dataset/Soil-Dataset/Yellow Soil/20.jpg'
features = extract_features(image_path)
print("Extracted Features:", features)
Machine Learning Algorithms in Soil Classification
Now, let’s build a machine-learning model using the soil images we got from the Kaggle.
First, we will import all the libraries and then build a function named extract_features to extract features from images. The images are then imported and processed, which includes converting to grayscale, and then we get these features. Then, after features are extracted for each image, labels are encoded using Label Encoder.
import os
import numpy as np
import mahotas as mh
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.ensemble import RandomForestClassifier, StackingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score, classification_report
from skimage import color, feature, io
# Function to extract features from an image
def extract_features(image_path):
img = io.imread(image_path)
gray_img = color.rgb2gray(img) # Converting image to grayscale
gray_img_int = (gray_img * 255).astype(np.uint8)
haralick_features = mh.features.haralick(gray_img_int).mean(axis=0)
hog_features, _ = feature.hog(gray_img, visualize=True)
hog_features_flat = hog_features.flatten() # Flattening the HOG features
# Ensuring both sets of features have the same length
hog_features_flat = hog_features_flat[:haralick_features.shape[0]]
return np.concatenate((haralick_features, hog_features_flat))
data_dir = "/kaggle/input/soil-classification-dataset/Soil-Dataset"
image_paths = []
labels = []
class_indices = {'Black Soil': 0, 'Cinder Soil': 1, 'Laterite Soil': 2,
'Peat Soil': 3, 'Yellow Soil': 4}
for soil_class, class_index in class_indices.items():
class_dir = os.path.join(data_dir, soil_class)
class_images = [os.path.join(class_dir, image) for image in os.listdir(class_dir)]
image_paths.extend(class_images)
labels.extend([class_index] * len(class_images))
# Extracting features from images
X = [extract_features(image_path) for image_path in image_paths]
# Encoding labels
le = LabelEncoder()
y = le.fit_transform(labels)
# Splitting the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Initializing and training a Random Forest Classifier
rf_classifier = RandomForestClassifier(n_estimators=100, random_state=42)
rf_classifier.fit(X_train, y_train)
# Making predictions
y_pred_rf = rf_classifier.predict(X_test)
# Evaluating the Random Forest model
accuracy_rf = accuracy_score(y_test, y_pred_rf)
report_rf = classification_report(y_test, y_pred_rf)
print("Random Forest Classifier:")
print("Accuracy:", accuracy_rf)
print("Classification Report:n", report_rf)
เครือข่ายประสาทลึก
It works based on computation units and the number of neurons. Each neuron accepts inputs and provides output. It is used to increase accuracy and make better predictions, while machine learning algorithms rely on interpreting the data, and decisions will be made based on them.
อ่านได้ด้วย: An Introductory Guide to Deep Learning and Neural Networks
Now, let’s build the model defined using Sequential API from Keras. This model will have a Conv2D convolution layer, MaxPooling2D, a flattening layer Flatten, and dense layers Dense.
Finally, the model is compiled using the อาดัม optimizer and categorical cross-entropy loss.
import tensorflow as tf
from tensorflow.keras.preprocessing import image_dataset_from_directory
data_dir = "/kaggle/input/soil-classification-dataset/Soil-Dataset"
# Setting up data generators
batch_size = 32
image_size = (224, 224)
# Using image_dataset_from_directory to load and preprocess the images
train_dataset = image_dataset_from_directory(
data_dir,
labels='inferred',
label_mode='categorical',
validation_split=0.2,
subset='training',
seed=42,
image_size=image_size,
batch_size=batch_size,
)
validation_dataset = image_dataset_from_directory(
data_dir,
labels='inferred',
label_mode='categorical',
validation_split=0.2,
subset='validation',
seed=42,
image_size=image_size,
batch_size=batch_size,
)
# Displaying the class indices
print("Class indices:", train_dataset.class_names)
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(224, 224, 3)),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(len(train_dataset.class_names), activation='softmax')
])
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
# Training the model
epochs = 10
history = model.fit(train_dataset, epochs=epochs, validation_data=validation_dataset)
import numpy as np
from tensorflow.keras.preprocessing import image
# Function to load and preprocess an image for prediction
def load_and_preprocess_image(img_path):
img = image.load_img(img_path, target_size=image_size)
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array /= 255.0
return img_array
image_path = '/kaggle/input/soil-classification-dataset/Soil-Dataset/Peat Soil/13.jpg'
new_image = load_and_preprocess_image(image_path)
# Making predictions
predictions = model.predict(new_image)
predicted_class = np.argmax(predictions[0])
# Getting the class label based on the class indices
class_labels = {0: 'Black Soil', 1: 'Cinder Soil', 2: 'Laterite Soil',
3: 'Peat Soil', 4: 'Yellow Soil'}
predicted_label = class_labels[predicted_class]
# Displaying the prediction
print("Predicted Class:", predicted_class)
print("Predicted Label:", predicted_label)
As you can see, the predicted class is 0, which is Black Soil. So, our model is classifying the type of soil correctly.
Proposed Multi-stacking Ensemble Learning Model Architectures
พื้นที่ StackingClassifier is initialized with the baseClassifiers and a การถดถอยโลจิสติก meta-classifier final_estimator. This combines the outputs of the baseClassifiers to make a final prediction. Then, after training and predicting, accuracy is calculated.
base_classifiers = [
('rf', RandomForestClassifier(n_estimators=100, random_state=42)),
('knn', KNeighborsClassifier(n_neighbors=5)),
('svm', SVC(kernel='rbf', C=1.0, probability=True)),
('nb', GaussianNB())
]
# Initializing the stacking classifier with a logistic regression meta-classifier
stacking_classifier = StackingClassifier(estimators=base_classifiers,
final_estimator=LogisticRegression())
# Training the stacking classifier
stacking_classifier.fit(X_train, y_train)
# Making predictions with Stacking Classifier
y_pred_stacking = stacking_classifier.predict(X_test)
# Evaluating the Stacking Classifier model
accuracy_stacking = accuracy_score(y_test, y_pred_stacking)
report_stacking = classification_report(y_test, y_pred_stacking)
print("nStacking Classifier:")
print("Accuracy:", accuracy_stacking)
print("Classification Report:n", report_stacking)
สรุป
Soil is an important element in yielding a good crop. Knowing which soil type is necessary to produce that specific crop is important. So, classifying the type of soil becomes important. Since manually classifying the type of soil is a time-consuming task, hence using deep learning models to classify them becomes easy. There are many machine learning models and deep learning models to implement this problem statement. Choosing the best one depends on the quality and amount of the data present in the dataset and the problem statement at hand. Another way to choose the best algorithm is by evaluating each. We can do that by measuring the accuracy, by how much they can correctly classify the soil. Finally, we implemented a Multi-Stacking ensemble model, using multiple models to build the best model.
ประเด็นที่สำคัญ
- For effective crop selection, one should understand the soil completely.
- Deep learning in agriculture is a powerful tool, from predicting plant disease to soil types and water needs.
- We have done feature extraction to get features from soil images.
- In this blog, we explored machine learning and deep learning models for classifying soil and a Multi-stacked ensemble model for improved accuracy.
คำถามที่พบบ่อย
A. It is important for suitable crop selection and identifying weed growth.
A. Features, including sand, clay, silt, peat, and loam, are considered.
A. Deep learning allows the model to make intelligent decisions, while traditional machine learning makes decisions by interpreting data.
A. The Multi-Stacking ensemble model increases the accuracy of classifying soil type.
สื่อที่แสดงในบทความนี้ไม่ได้เป็นของ Analytics Vidhya และถูกใช้ตามดุลยพินิจของผู้เขียน
ที่เกี่ยวข้อง
- เนื้อหาที่ขับเคลื่อนด้วย SEO และการเผยแพร่ประชาสัมพันธ์ รับการขยายวันนี้
- PlatoData.Network Vertical Generative Ai เพิ่มพลังให้กับตัวเอง เข้าถึงได้ที่นี่.
- เพลโตไอสตรีม. Web3 อัจฉริยะ ขยายความรู้ เข้าถึงได้ที่นี่.
- เพลโตESG. คาร์บอน, คลีนเทค, พลังงาน, สิ่งแวดล้อม แสงอาทิตย์, การจัดการของเสีย. เข้าถึงได้ที่นี่.
- เพลโตสุขภาพ เทคโนโลยีชีวภาพและข่าวกรองการทดลองทางคลินิก เข้าถึงได้ที่นี่.
- ที่มา: https://www.analyticsvidhya.com/blog/2024/01/deep-learning-in-agriculture-improving-soil-crop-yields/
- :มี
- :เป็น
- :ไม่
- $ ขึ้น
- 1
- 10
- 13
- 224
- 32
- 33
- 43
- 46
- 51
- 7
- 9
- a
- ยอมรับ
- ความถูกต้อง
- ข้าม
- อาดัม
- น่าสงสาร
- หลังจาก
- เกษตรกรรม
- ขั้นตอนวิธี
- อัลกอริทึม
- ทั้งหมด
- ช่วยให้
- ท่ามกลาง
- จำนวน
- an
- การวิเคราะห์
- การวิเคราะห์ วิทยา
- และ
- สัตว์
- อื่น
- API
- ประยุกต์
- สถาปัตยกรรม
- เป็น
- แถว
- บทความ
- AS
- At
- ความพร้อมใช้งาน
- ใช้ได้
- ตาม
- BE
- จะกลายเป็น
- รับ
- ที่ดีที่สุด
- ดีกว่า
- ระหว่าง
- Black
- บล็อก
- บล็อกกาธอน
- ทั้งสอง
- สร้าง
- การก่อสร้าง
- by
- คำนวณ
- CAN
- Choose
- เลือก
- ชั้น
- การจัดหมวดหมู่
- แยกประเภท
- ภูมิอากาศ
- สี
- รวม
- อย่างไร
- รวบรวม
- อย่างสมบูรณ์
- การคำนวณ
- แนวคิด
- เงื่อนไข
- ถือว่า
- สนับสนุน
- แปลง
- การแปลง
- ได้อย่างถูกต้อง
- พืชผล
- พืช
- ข้อมูล
- การตัดสินใจ
- ลึก
- การเรียนรู้ลึก ๆ
- กำหนด
- หนาแน่น
- ขึ้นอยู่กับ
- ตรวจจับ
- การตรวจพบ
- การกำหนด
- พัฒนาการ
- แตกต่าง
- ค้นพบ
- ดุลพินิจ
- สนทนา
- โรค
- แสดง
- do
- ทำ
- ทำ
- สอง
- แต่ละ
- ง่าย
- เศรษฐกิจ
- มีประสิทธิภาพ
- ธาตุ
- องค์ประกอบ
- ภาวะฉุกเฉิน
- กากกะรุน
- เทคโนโลยีใหม่
- เข้ารหัส
- การเข้ารหัส
- การสร้างความมั่นใจ
- ยุค
- อีเธอร์ (ETH)
- การประเมินการ
- ทุกๆ
- การสำรวจ
- สำรวจ
- สารสกัด
- การสกัด
- ลักษณะ
- คุณสมบัติ
- สองสาม
- สนาม
- สุดท้าย
- ในที่สุด
- ชื่อจริง
- สำหรับ
- ป่า
- ฟอร์ม
- การสร้าง
- รากฐาน
- ราคาเริ่มต้นที่
- ฟังก์ชัน
- เครื่องกำเนิดไฟฟ้า
- ได้รับ
- ได้รับ
- ดี
- ได้
- การไล่ระดับสี
- เฉดสีเทา
- การเจริญเติบโต
- ให้คำแนะนำ
- มือ
- มี
- เป็นประโยชน์
- ด้วยเหตุนี้
- ประวัติ
- สรุป ความน่าเชื่อถือของ Olymp Trade?
- HTTPS
- ประจำตัว
- แยกแยะ
- ระบุ
- ภาพ
- ภาพ
- อย่างมาก
- ส่งผลกระทบ
- การดำเนินการ
- การดำเนินการ
- นำเข้า
- ความสำคัญ
- สำคัญ
- การปรับปรุง
- การปรับปรุง
- in
- รวมถึง
- รวมทั้ง
- เพิ่ม
- เพิ่มขึ้น
- อินเดีย
- ดัชนี
- ข้อมูล
- ปัจจัยการผลิต
- ฉลาด
- เข้าไป
- เบื้องต้น
- IT
- ITS
- การสัมภาษณ์
- jpg
- เพียงแค่
- Keras
- คีย์
- รู้ดี
- ฉลาก
- ป้ายกำกับ
- ที่ดิน
- ต่อมา
- ชั้น
- ชั้น
- นำไปสู่
- เรียนรู้
- การเรียนรู้
- ความยาว
- ห้องสมุด
- ห้องสมุด
- ตั้งอยู่
- ชีวิต
- วิถีชีวิต
- โหลด
- ปิด
- เครื่อง
- เรียนรู้เครื่อง
- ทำ
- หลัก
- ส่วนใหญ่
- ทำ
- ทำให้
- การทำ
- ด้วยมือ
- หลาย
- เรื่อง
- อาจ..
- วิธี
- การวัด
- ภาพบรรยากาศ
- ตัวชี้วัด
- แร่ธาตุ
- แบบ
- โมเดล
- การตรวจสอบ
- ข้อมูลเพิ่มเติม
- มาก
- หลาย
- ที่มีชื่อ
- จำเป็น
- ความต้องการ
- เพื่อนบ้าน
- ประสาท
- เซลล์ประสาท
- จำนวน
- มึน
- โภชนาการ
- วัตถุ
- การตรวจจับวัตถุ
- of
- on
- ONE
- การดำเนินการ
- อินทรีย์
- OS
- อื่นๆ
- ของเรา
- เอาท์พุต
- เอาท์พุท
- เป็นเจ้าของ
- ส่วนหนึ่ง
- เส้นทาง
- ภาพถ่าย
- กายภาพ
- พืช
- พืช
- เพลโต
- เพลโตดาต้าอินเทลลิเจนซ์
- เพลโตดาต้า
- ที่มีศักยภาพ
- ที่มีประสิทธิภาพ
- ที่คาดการณ์
- ทำนาย
- คำทำนาย
- การคาดการณ์
- นำเสนอ
- การพิมพ์
- ปัญหา
- การประมวลผล
- ก่อ
- เสนอ
- ให้
- การตีพิมพ์
- หมดจด
- คุณภาพ
- สุ่ม
- RBF
- ถดถอย
- วางใจ
- รายงาน
- ว่า
- เก็บไว้
- กลับ
- หุ่นยนต์
- บทบาท
- ราก
- เดียวกัน
- SAND
- ตาชั่ง
- วิทยาศาสตร์
- เห็น
- การเลือก
- ชุดอุปกรณ์
- การตั้งค่า
- น่า
- แสดง
- ตั้งแต่
- เดียว
- เว็บไซต์
- สมาร์ท
- So
- ดิน
- เกี่ยวกับอวกาศ
- โดยเฉพาะ
- ความเร็ว
- การสุม
- คำแถลง
- ขั้นตอน
- เหมาะสม
- ที่จัดมา
- สนับสนุน
- พื้นผิว
- SVC
- ระบบ
- งาน
- เทคโนโลยี
- tensorflow
- การทดสอบ
- กว่า
- ที่
- พื้นที่
- ของพวกเขา
- พวกเขา
- แล้วก็
- ที่นั่น
- ล้อยางขัดเหล่านี้ติดตั้งบนแกน XNUMX (มม.) ผลิตภัณฑ์นี้ถูกผลิตในหลายรูปทรง และหลากหลายเบอร์ความแน่นหนาของปริมาณอนุภาคขัดของมัน จะทำให้ท่านได้รับประสิทธิภาพสูงในการขัดและการใช้งานที่ยาวนาน
- พวกเขา
- นี้
- ตลอด
- ต้องใช้เวลามาก
- ไปยัง
- เครื่องมือ
- หัวข้อ
- แบบดั้งเดิม
- การฝึกอบรม
- ชนิด
- ชนิด
- เข้าใจ
- หน่วย
- ที่ไม่พึงประสงค์
- ใช้
- มือสอง
- การใช้
- การตรวจสอบ
- ความคุ้มค่า
- คือ
- น้ำดื่ม
- ทาง..
- we
- webp
- วัชพืช
- อะไร
- ความหมายของ
- ที่
- ในขณะที่
- ทำไม
- จะ
- กับ
- โรงงาน
- X
- สีเหลือง
- ยอมให้
- อัตราผลตอบแทน
- เธอ
- ลมทะเล