top of page
Search

Meat-Adulteration-Detection-Using-TF-and-CNN



Red meat is an excellent source of essential nutrients such as protein, iron, niacin, zinc and vitamin B12. But in certain regions at butcher shop they mix one type of red meat with other in order to make quick money. For instance in Vijayawada, the butchers allegedly mixed beef with mutton as a measure to earn quick money as beef is much cheaper than mutton. The beef is available at an affordable price of Rs. 250 to Rs. 300 per kg, in comparison to the mutton being sold at approximately Rs. 500 to Rs. 600 per kg in Vijayawada.


Meat Adulteration Detector helps to solve the problem of substitution of red meat. In a particular season and region sometimes one particular red meat can be expensive. In that case the meat vendors may substitute the required red meat with some other red meat like pork, buffalo meat, etc. This can be harmful to the consumers who are allergic to certain red meat.


Using the meat adulteration detector application all that the consumer will have to do is to take a picture of the raw red meat that he/she is going to purchase and the application rightly tells whether the meat is adulterated by mixing with other red meat or not. The application is based on the concepts of machine learning and computer vision. The image captured by the consumer is compared with the repository of images in the dataset containing images of unadulterated red meat. Using Tensorflow – keras libraries the captured image is converted to gray scale and partitioned into layers, based on the layering done by Keras the image is categorized as adulterated or unadulterated.


This way the customers can ensure whether they are eating the red meat they asked for.


Now we will move on to the coding part,


Initially we import all the necessary packages.


Tensorflow package is used here to categorize adulterated and unadulterated images,

Keras is for layering the image, matplotlib is for visualizing the categorization applied to our test and train dataset.

The other packages - pillow, re, glob, image are supporting packages for iterating the images in the program.

All the images which are to be trained and tested should be in jpeg/jpg format with 100*100 dimensions which is the maxsize preset in the code. The images which adhere to those conditions are converted to 8 bit greyscale images (black and white) which is later layered and categorized.


Now in the training images folder the images should be in a way that all the adulterated images are named as, ad.1.jpg, ad.2.jpg... and the unadulterated images are named as, unad.1.jpg, unad.2.jpg... as the class_names are set to be 'ad' and 'unad'.

We set the dataset directory path to the respective train and test folders containing the images.


We check whether the correct folder by, finding its file size using '.shape' attribute and the naming convention is checked by printing its label. Here 0's represent the adulterated meat images and 1's represent the unadulterated meat images.


display_images function with images and its corresponding labels (ad - adulterated and unad- unadulterated) attributes is for displaying the image categorization in grid format


Using the previously defined function we display the images in the training folder with its label, so that we could check whether the correct directory is set for training


Similarly we check whether the test dataset folder is correctly set by checking its shape and labels, for which the code runs and displays the output


Now, we divide both the test and train images into 255 layers of shades and we particularly test on 128, 16, 2 layers as they differ significantly and we save to the Machine Learning model


We compile the saved model to fit it for training, testing and to determine the accuracy metrics of the categorization model.


We do two steps, one is to assign variable prediction to the testing process using model which we compiled. The next is to train the model with the images in the train dataset.

We train the model with 100 epochs (number of passes of the entire training dataset the machine learning program has completed) for better accuracy.

We can infer that the accuracy increases gradually from epoch to epoch and in the reaches to 1.0(100%). We take the average of all epochs' accuracy and compute the model's accuracy


Once all the epochs are completed, we find the accuracy of the model to be 82% which is a descent score for a Machine Learning, Image Processing model.


As we trained the model now we test the model for the images in the test dataset folder where the images are unlabelled, we use the model to predict their label and display.

On printing predictions matrix, we can see SGD - optimizers value and categorical cross entropy value.

On passing the predictions variable to display_images function, we can visually see the categorization model applied to the images in test directory and infer the results.


You can find the explained project as a github repository at:


This is one of the way to predict adulteration in meat for a larger dataset,

Thanks for your patience, Happy Reading !!!






















Comentarios


Post: Blog2_Post
bottom of page