Image Classification of Fresh Fish and Non Fresh Fish
The fish sorting process carried out by fishermen or sellers, to select fish based on quality is still using manual methods and sometimes misses due to the limited sense of sight when tired.
So far the examination has only been seen physically.
As a result, the fish will often be damaged when consumed.
This research tries to apply the Convolutional Neural Network (CNN) algorithm to distinguish between fresh and non-fresh fish.
This work has been published in the Indonesian Journal of Applied Informatics - Universitas Sebelas Maret and is Nationally accredited with SINTA 4. To view articles from this research journal, click on the following link.
Import The Library
Import some required libraries. In this project, the required library is TensorFlow to create a Convolution Neural Network (CNN) model.
print("images preview of fresh fish train")
images_preview("/content/drive/My Drive/fresh and non-fresh fish/train/fresh/*")
print("\nimages preview of non-fresh fish train")
images_preview("/content/drive/My Drive/fresh and non-fresh fish/train/non-fresh/*")
images preview of fresh fish train
images preview of non-fresh fish train
print("images preview of fresh fish validation")
images_preview("/content/drive/My Drive/fresh and non-fresh fish/val/fresh/*")
print("\nimages preview of non-fresh fish validation")
images_preview("/content/drive/My Drive/fresh and non-fresh fish/val/non-fresh/*")
images preview of fresh fish validation
images preview of non-fresh fish validation
Because the number of datasets is limited, which is only 40 datasets. Then the augmentation process is carried out on the dataset
After carrying out several stages such as exploratory data analysis, modeling, and creating functions to visualize the accuracy and function values, the next step is to run the model. The model is compiled to carry out the training process and model testing on the defined data.
After completing training and validating the model. The next step is to visualize the accuracy and loss values obtained. The graph below shows the comparison of the accuracy value and the loss value obtained from the training and validation process.
Create a function to convert the index obtained from the prediction results into a label that will display whether the entered image is a fresh fish image or not. Then I try to load the image from my storage and try the model which has been trained and validated. So that it produces predictions like the one below.
returndict((v,k) for k,v in this_dict.items())
nama_train_data = switch_dict_key_values(train_data.class_indices)
uploaded = files.upload()
for fn in uploaded.keys():
# predicting images
path = fn
fig = plt.figure(figsize=(2, 2))
img = plt.imread(ini)
img = image.load_img(path, target_size = (size, size))
img = image.img_to_array(img)
img = np.expand_dims(img, axis =0)
hasil = model.predict_classes(img)
jenis ="tidak segar"print("Predicted as ", hasil, "labeled as ",jenis)
Saving fresh fish sample.jpg to fresh fish sample.jpg
fresh fish sample.jpg
Predicted as [] labeled as segar
From the training and validation processes, both produce high accuracy values, the training process produces an accuracy value of 100% and the validation process is 95%. Then the model is tested to predict the eye pupil images of fresh fish taken from file explorer and identified as fresh fish. This shows that the model has good performance.