Hashwanth Gogineni's other Models Reports

Major Concepts

 

Sign-Up/Login to access Several ML Models and also Deploy & Monetize your own ML solutions for free

Models Home » Domain Usecases » Agriculture » Pisciculture Species Detection

Pisciculture Species Detection

Models Status

Model Overview

Pisciculture:


'Pisciculture' or Fish culture is the breeding and rearing of fishes in ponds, reservoirs (dams), lakes, rivers, and paddy fields. It is the farming of economically important fish under controlled conditions. 'Pisciculture' helps integrate rural development by generating employment and income for fishing communities and fish farmers.

Few types of fish cultures:


a)Extensive fish culture: Fish culture in large areas with low stocking and natural feeding.


b)Intensive fish culture: Fish culture in small areas with high stocking density and artificial feeding increases production.


c)Pond culture: Fish rearing in pond water area.


d) Riverine fish culture: Fish rearing in lotic water area.

e)Dam culture: Fish culture in artificially built reservoirs.


f)Lake culture: Rearing of fish in lakes are natural standing water bodies.


g)Monoculture: Culture of a single type of fish in a water body. It is also called 'mono species culture.'


h)Polyculture: More than one type of fish culture in a water body. It is also called 'composite fish culture.


i)Animal husbandry farming: Rearing of fish along with paddy, poultry, cattle, pig, and ducks.




Why Pisciculture Species Detection?

The project can help organizations in the seafood industry detect multiple aquatic animals that are consumable to humans.


Dataset:


This dataset contains nine different aquatic animal types extracted from a supermarket in Izmir, Turkey


for a university-industry collaboration project at Izmir University of Economics, and this work


was published in ASYU 2020.


The dataset includes gilt head bream, red sea bream, sea bass, red mullet, horse mackerel,


black sea sprat, striped red mullet, trout, shrimp image samples.


The dataset includes a total of '9,000' images, i.e.,' 1000' images per class.

   

Convolutional neural networks:

'
CNN' is a Deep Learning algorithm that can take in an input, assign importance to various objects in the image, and differentiate one image from another image. The pre-processing part required in a ConvNet is much lower as compared to other algorithms. While in primitive methods, filters are engineered by hand, with high training, ConvNets can learn these characteristics.


The architecture of a 'CNN' is analogous to that of the pattern of neurons in the human brain and was inspired by the 'Visual Cortex' organization. Individual neurons respond to stimuli only in a restricted visual field region known as the Receptive Field. A collection of such fields overlap to cover the entire visual area.


The higher performance of convolutional neural networks with pictures, voice, or audio signal inputs sets them apart from conventional neural networks. They are divided into three sorts of layers:

1) Layer of convolutions

2)Pooling layer is a layer that is used to collect water.

3) FC (Fully Connected) layer

A convolutional network's initial layer is the convolutional layer. While further convolutional or pooling layers can be added after convolutional layers, the fully-connected layer is the last. The CNN becomes more complicated with each layer, detecting larger areas of the picture. Earlier layers concentrate on basic elements like colours and borders. As the visual data travels through the CNN layers, it begins to distinguish bigger components or features of the item, eventually identifying the target object.

Understanding Code:

First, let us import the required libraries for our project.


import numpy as np
import pandas as pd
import os
from pathlib import Path

import matplotlib.pyplot as plt
import seaborn as sns
import cv2

from sklearn.metrics import classification_report
from sklearn.model_selection import train_test_split

import tensorflow as tf
from keras.models import Sequential, Model
from keras.layers import Dense, Flatten, Dropout, GlobalAveragePooling2D
from tensorflow.keras.optimizers import Adam

Now, let us load the data into our system and convert the data into a dataframe.


image_dir = Path('Fish_Dataset')

# Get filepaths and labels
filepaths = list(image_dir.glob(r'**/*.png'))
labels = list(map(lambda x: os.path.split(os.path.split(x)[0])[1], filepaths))

filepaths = pd.Series(filepaths, name='Filepaths').astype(str)
labels = pd.Series(labels, name='Labels')

# Concatenate filepaths and labels
df = pd.concat([filepaths, labels], axis=1)

# Show the result
df.head()

As you can see we extracted data from the data's directory and concatenated 'file paths' and 'labels' into a data frame.

Let us also split the data frame for testing and training purposes.


# Separate in train and test data
train_df, test_df = train_test_split(df, train_size=0.85, shuffle=True, random_state=1)

As you can see I used the "train_test_split" function to split the data frame.


train_generator = tf.keras.preprocessing.image.ImageDataGenerator(
preprocessing_function=tf.keras.applications.mobilenet_v2.preprocess_input,
validation_split=0.15
)

test_generator = tf.keras.preprocessing.image.ImageDataGenerator(
preprocessing_function=tf.keras.applications.mobilenet_v2.preprocess_input
)

As you can see, I used the 'ImageDataGenerator' function for data augmentation purposes.


train_images = train_generator.flow_from_dataframe(
dataframe=train_df,
x_col='Filepaths',
y_col='Labels',
target_size=(224, 224),
color_mode='rgb',
class_mode='categorical',
batch_size=64,
shuffle=True,
seed=42,
subset='training'
)

val_images = train_generator.flow_from_dataframe(
dataframe=train_df,
x_col='Filepaths',
y_col='Labels',
target_size=(224, 224),
color_mode='rgb',
class_mode='categorical',
batch_size=64,
shuffle=True,
seed=42,
subset='validation'
)

test_images = test_generator.flow_from_dataframe(
dataframe=test_df,
x_col='Filepaths',
y_col='Labels',
target_size=(224, 224),
color_mode='rgb',
class_mode='categorical',
batch_size=64,
shuffle=False
)

Also, I loaded train and test data using the 'flow_from_dataframe' function into the kernel.

Next, let us get into the modelling part of the project.


input_shape = (224, 224, 3)
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(64, (3,3), activation='relu', input_shape=input_shape ),
tf.keras.layers.MaxPool2D(pool_size = (2,2)),
tf.keras.layers.Conv2D(64, (3,3), activation='relu'),
tf.keras.layers.MaxPool2D(pool_size = (2,2)),
tf.keras.layers.Conv2D(32, (3,3), activation='relu'),
tf.keras.layers.MaxPool2D(pool_size = (2,2)),
tf.keras.layers.Conv2D(32, (3,3), activation='relu'),
tf.keras.layers.MaxPool2D(pool_size = (2,2)),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(512, activation='relu'),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(9, activation='softmax')
])

model.summary()

Here I used 4 'Conv2D' layers, 4 'MaxPool2D' layers and 1 'flatten' layer, 2 'Dropout' layers, 4 'Dense' layers to get the best out of our data.

Now, let us compile our model and fit the data.


model.compile(optimizer="adam", loss='categorical_crossentropy', metrics=["accuracy"])

callback = tf.keras.callbacks.EarlyStopping(monitor='accuracy', patience=2)

history = model.fit(train_images, validation_data=val_images, epochs=20, callbacks=callback)

As you can see I used 'categorical_crossentropy' and 'accuracy' as accuracy metrics.


accuracy = history.history['accuracy']
val_accuracy = history.history['val_accuracy']

loss = history.history['loss']
val_loss = history.history['val_loss']

plt.figure(figsize=(15,10))

plt.subplot(2, 2, 1)
plt.plot(accuracy, label = "Training accuracy")
plt.plot(val_accuracy, label="Validation accuracy")
plt.legend()
plt.title("Training vs validation accuracy")


plt.subplot(2,2,2)
plt.plot(loss, label = "Training loss")
plt.plot(val_loss, label="Validation loss")
plt.legend()
plt.title("Training vs validation loss")

plt.show()



Finally, I used 'matplotlib.pyplot' to generate our model's performance's graph.


Also, let us have a look at our model's classification report.


# Classification Report

from sklearn.metrics import classification_report
test_labels=test_generator.classes
predictions=model.predict_generator(test_generator, verbose=1)
y_pred = np.argmax(predictions, axis=-1)
print(classification_report(test_labels, y_pred))



As you can see I used the "classification_report" function to generate our model's report.



Thank you for your time.


0 comments