1.
System Explanation
Our system, Snake Image Classification, is designed to classify snake images as venomous or
non-venomous using supervised ML models (Logistic Regression, KNN classification. Random
Forest Classification, while we tested with the former 2, the main focus remained on the
Random Forest Classification). The objective is to demonstrate how computer vision techniques
combined with ensemble learning can produce reliable and efficient results. Furthermore, due to
the limitations that inherently come from using Random Forest Classifier, the team also chose to
implement a CNN model.
The following figure shows the Random Forest AI pipeline, which follows five stages.
The following figure shows an overview of the CNN pipeline. Since we ran out of time we could
not get proper images for the CNN pipeline. The CNN is implemented with 8 convolutions and
Max Poolings on 512x512 pixel images.
Data Source: The dataset for Random Forest was obtained from Kaggle, containing
pre-labelled images of snakes, which were already organized into two categories: venomous
and non-venomous. There are a total of 1775 images of snakes, divided into 80/20 for training
and test purposes. These images serve as the foundation for training and evaluating the model.
The data for training the CNN model was obtained from kagglehub as well. This new data set
contained about 3000 labeled snake images that were pre-partitioned into training and
validation sets. These images were 512x512 pixels with 3 color channels BRG and all 3
channels were used to train and validate the CNN.
Preprocessing: Each image for Random Forest was preprocessed to ensure uniformity across
the dataset. Using OpenCV, all images in the dataset are resized to 128*128 pixels and
converted to the RGB colour space for consistency. Pixel values are normalized to scale them
between the value of 0 and 1. This improves the computational efficiency and stability of the
model.
The data for CNN was preprocessed via PIL and TorchVision functions. PIL was used to open
the image and torchvision was used to apply transformations to tensorize and normalize the
0-255 bit pixel values to be between 0 and 1. Functions RandomHorizontalFlip() and
RandomRotation are used to randomize the image so that the model does not overfit.
Feature Extraction:
Random Forest: Two types of features are extracted from images:
1. Colour features
2. Texture features
The colour and texture features are combined into a single feature vector with 106 dimensions
in total to represent each image.
CNN:
8 convolutions -extracting 200 feature maps total- on all 3 channels is being applied.
Furthermore, the kernel size for creating the feature maps is 3x3. Finally, ReLU activation
function, MaxPool2d, and some dropout is used to properly extract the features and construct
feature maps to then be fed into the Neural Net. The poisonous vs not poisonous feature was
also extracted by first turning the given Csv file into a pandas dataframe and then reading the
poisonous column of the dataframe.
Model Training: Random Forest Classifier is then trained on the extracted features. This
method was chosen because it handles the imbalance in the class effectively and is robust to
overfitting. This model uses 150 decision trees with a balanced subsample weighting strategy.
For CNN, after the feature maps were extracted, they were flattened using the Flatten() and
Linear() and then fed directly into the neural net and backpropagated on using functions in
[Link].
Evaluation: After training, the model predicts the classes from the unseen images from the test
category. Evaluation is done using metrics such as accuracy, precision, recall, and F1 score. A
confusion matrix visualizes the model’s performance in both classes, helping to identify where
misclassification occurs. Lastly we perform a Cross-Validation to realize the true test accuracy
across numerous folds.
For CNN, we couldn’t properly get to this part as we ran out of time.
Limitations and Observation:
Data imbalance between the venomous and non-venomous classes leads to bias towards
venomous(more venomous images than non-venomous). This gives us the high recall for
venomous as well as the high false positives for
For CNN, we observed that the code is extremely slow and takes a while to train. We were
training the CNN in google colab using the T4 GPU and it was still taking upwards of 2-3 hours.
As the epochs were executing we saw that the model was barely learning anything. It started
out at about 56-60% accuracy but only improved to about 64-66% accuracy.
We presume that the sheer amount of feature maps was confusing the neural net and that the
learning rate in the backpropagation was too small at learning_rate=0.0001.
Given more time, the team is confident that we can implement a CNN with 90% accuracy that
also trains faster.
Feature Table
Description Platfor Completene Code Auth Notes
m ss ors
Data Cleaning & Local 5 Python Team Resize images from
Preprocessing preprocessed dataset
from kaggle to 128 * 128.
Standardize image RGB
values.
Feature Extraction: Local 5 Python (OpenCV) Team Extract histogram
Color Histogram features(RGB, 1d) -
capture dominant
coloration patterns across
snake species
Feature Extraction: Local 5 Python Team Extract texture-based
Local Binary (skimage/OpenCV) descriptors useful for
Patterns (LBP) differentiating scale
patterns and roughness –
critical for species with
similar coloration but
different textures.
KNN Classifier Local 4 Python Team Served as baseline
distance-based model.
Accuracy lower due to
high feature
dimensionality and
overlapping species
clusters.
Logistic Regression Local 4 Python Team Linear model used as
benchmark. Could not
capture non-linear feature
relationships in
color/texture data
inducing lower accuracy.
Random Forest Local 5 Python Team Final model. Handles
Classifier high-dimensional color +
texture features well.
Showed strongest
performance (≈66% on
test, ≈63.49% ± 0.58% in
CV). Here the model
accounts for the
imbalance in the dataset.
Cross-Validation Local 5 Python Team 5-fold CV provided robust
Evaluation performance validation
and reduced sensitivity to
train/test split variance.
RF remained the
strongest model.
Confusion Matrix + Local 5 Python Team Revealed class-level
Classification performance issues –
Report certain species visually
similar leading to
confusion. Helps guide
future dataset balancing +
feature tuning.
Visualizations Local 4 Python (matplotlib) Team Effectively communicates
(Model comparison results. Could be
+ confusion matrix) improved with feature
importance charts to
highlight which
color/texture bins matter
most.
Data Cleaning & Google 5 Python (PIL, Team Made sure the data set
Preprocessing Colab TorchVision) was properly normalized
(CNN) and tensorized into
tensors for the CNN to
compute
Feature Extraction: Google 3 Python (Pandas, Team Extracted texture-based
Convolutions and Colab [Link], Numpy) descriptors useful for
Label Extraction differentiating scale
(CNN) patterns and roughness –
critical for species with
similar coloration but
different textures.
External Tools & Libraries
Our project, Snake Image Classification, uses a combination of open-source libraries to work
with our dataset, like image processing and model training. The project code is entirely written in
Python with the help of the following external tools:
● OpenCV: This is used for image loading from the dataset, resizing, colour-space
conversion, and histogram computation. OpenCV provides efficient, optimized methods
for the operations at the pixel level, which form the foundation of our preprocessing and
feature extraction pipeline.
● Scikit-image: This helped capture local shape variations in snake skin patterns, as the
local binary pattern function was employed to extract the texture-based features by
Scikit-image.
● Scikit-learn: This is the core ML library for model training, evaluation, and reporting. We
used RandomForestClassifier for the classification, train_test_split for data partitioning,
and metrics such as classification_report and confusion matrix for the evaluation of the
model.
● Numpy: This is used for numerical computations and array manipulations throughout the
preprocessing, feature extraction, and combination steps.
● Matplotlib: This is used for the visualization of data distributions and confusion matrices
and for performing comparisons between model predictions.
● Torch/[Link]/TorchVision: Recognises the color patterns to then determine if the
snake is poisonous or not.
● Pandas: Converts Csv to pandas dataframe to then extract the correct labels.
● Kagglehub: Used to import the kagglehub dataset.
Dataset and Dependencies
The datasets used in this project are from Kaggle, which consists of pre-classified images of
snakes labelled as "venomous" and "non-venomous." No proprietary data sources or external
APIs were used.
The CNN uses a prelabeled, pre-partitioned data set from kagglehub. The following is the link to
the kagglehub CNN dataset:
[Link]
Platform and Installation
The project runs on standard Python environments. Dependencies are managed via a
[Link] file, which includes packages such as OpenCV, scikit-learn, matplotlib,
scikit-image, etc. Installation is straightforward using:
pip install -r [Link]
For CNN, just run the CNN in the python environment of Google Colab with the T4 GPU for
training. Google Colab Link for CNN:
[Link]
ng