DEV Community

Cover image for 4 reasons why ditching Machine Learning and falling in love with Deep Learning might be a good idea
Vishnu Ajit
Vishnu Ajit

Posted on

4 reasons why ditching Machine Learning and falling in love with Deep Learning might be a good idea

In this project we make the AI learn how to recognize the difference between two flowers. We train the AI on images upward of 500qty . Then we give a Machine Learning AI model (ML model) the same set of two folders - Rose flower folder and Carnation flower folder.

We make the ML model (Machine Learning model ) analyze both folders.

We make the DL model (Deep Learning model ) analyze both folders.

Then we try to interpret the results and see which model obtained higher accuracy.

Note: We are going to purposefully make things difficult for AI . Which is why we chose two red colour flowers. Both of which are almost the same shape geometrically. If we had chosen Rose flowers vs Jasmine flowers. Or Rose flowers vs Tulip flowers the AI models would get an advantage of deciding which is which by looking at the color difference between the flower. In this case, that is not possible. Both AI models - the Machine Learning model & the Deep Learning model has to figure out which is which with pure hardwork and render us our required results.

TLDR - Find the complete source code in this notebook

https://github.com/ruforavishnu/Project_Machine_Learning/blob/master/rose_vs_carnation_ml_vs_dl.ipynb
Enter fullscreen mode Exit fullscreen mode

Complete source code in google colab notebook format can be obtained here

Dataset Exploration

We used the Flowers Kaggle Dataset and extracted Rose and Carnation images. To understand the challenge, we previewed 10 random images per class.

Even for humans, distinguishing these two red flowers is tricky — imagine how the AI has to work!

Machine Learning Approach

We resized images to 128x128 pixels and converted them to grayscale. Then we extracted HOG features to capture the flowers’ textures and shapes.

from skimage.feature import hog

# Convert to grayscale
X_gray = np.array([cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) for img in X])

# Extract HOG features
hog_features = []
for img in X_gray:
    features = hog(
        img,
        orientations=9,
        pixels_per_cell=(16,16),
        cells_per_block=(2,2),
        block_norm='L2-Hys'
    )
    hog_features.append(features)

hog_features = np.array(hog_features)
print("HOG features shape:", hog_features.shape)
Enter fullscreen mode Exit fullscreen mode

We trained a Support Vector Machine (SVM) classifier on these features. ML achieved an accuracy of 74.29%.

# Initialize & train SVM
ml_model = SVC(kernel='rbf')
ml_model.fit(X_train, y_train)

# Predictions
ml_preds = ml_model.predict(X_test)

# Accuracy
ml_accuracy = accuracy_score(y_test, ml_preds)
print("Machine Learning Accuracy: {:.2f}%".format(ml_accuracy*100))

# Optional: Confusion matrix
cm = confusion_matrix(y_test, ml_preds)
print("Confusion Matrix:\n", cm)

Enter fullscreen mode Exit fullscreen mode
Machine Learning Accuracy: 74.29%
Confusion Matrix:
 [[137  58]
 [ 41 149]]
Enter fullscreen mode Exit fullscreen mode

The ML model does reasonably well, but its performance is limited by handcrafted features.

Deep Learning Approach

Next, we trained a Convolutional Neural Network (CNN) that can automatically learn features from the images. This CNN extracts petal shapes, textures, and subtle details that ML might miss.

import tensorflow as tf
from tensorflow.keras import layers, models

dl_model = models.Sequential([
    layers.Conv2D(32, (3,3), activation='relu', input_shape=(IMG_SIZE,IMG_SIZE,3)),
    layers.MaxPooling2D(2,2),

    layers.Conv2D(64, (3,3), activation='relu'),
    layers.MaxPooling2D(2,2),

    layers.Conv2D(128, (3,3), activation='relu'),
    layers.MaxPooling2D(2,2),

    layers.Flatten(),
    layers.Dense(128, activation='relu'),
    layers.Dropout(0.5),
    layers.Dense(1, activation='sigmoid')  # binary classification
])

dl_model.summary()
Enter fullscreen mode Exit fullscreen mode

We trained the CNN for 30 epochs with data augmentation. After evaluation, the DL model achieved 85.71% accuracy, much higher than ML.

Epoch 1/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 49s 1s/step - accuracy: 0.8056 - loss: 0.6186 - val_accuracy: 0.8961 - val_loss: 0.3063
Epoch 2/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 45s 1s/step - accuracy: 0.7519 - loss: 0.4839 - val_accuracy: 0.8929 - val_loss: 0.2516
Epoch 3/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 46s 1s/step - accuracy: 0.7734 - loss: 0.4461 - val_accuracy: 0.9286 - val_loss: 0.2301
Epoch 4/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 82s 1s/step - accuracy: 0.8113 - loss: 0.4200 - val_accuracy: 0.8961 - val_loss: 0.2441
Epoch 5/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 48s 1s/step - accuracy: 0.8309 - loss: 0.3724 - val_accuracy: 0.9253 - val_loss: 0.2124
Epoch 6/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 46s 1s/step - accuracy: 0.8378 - loss: 0.3800 - val_accuracy: 0.8636 - val_loss: 0.3138
Epoch 7/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 49s 1s/step - accuracy: 0.8483 - loss: 0.3569 - val_accuracy: 0.9156 - val_loss: 0.2071
Epoch 8/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 46s 1s/step - accuracy: 0.8589 - loss: 0.3541 - val_accuracy: 0.9318 - val_loss: 0.2196
Epoch 9/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 47s 1s/step - accuracy: 0.8877 - loss: 0.2699 - val_accuracy: 0.9253 - val_loss: 0.2291
Epoch 10/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 46s 1s/step - accuracy: 0.8797 - loss: 0.2974 - val_accuracy: 0.9253 - val_loss: 0.1862
Epoch 11/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 47s 1s/step - accuracy: 0.8735 - loss: 0.3012 - val_accuracy: 0.9091 - val_loss: 0.2100
Epoch 12/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 81s 1s/step - accuracy: 0.8671 - loss: 0.2905 - val_accuracy: 0.9318 - val_loss: 0.2048
Epoch 13/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 49s 1s/step - accuracy: 0.8845 - loss: 0.2824 - val_accuracy: 0.9188 - val_loss: 0.2141
Epoch 14/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 46s 1s/step - accuracy: 0.8760 - loss: 0.2807 - val_accuracy: 0.9481 - val_loss: 0.1933
Epoch 15/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 47s 1s/step - accuracy: 0.8828 - loss: 0.2720 - val_accuracy: 0.8831 - val_loss: 0.2699
Epoch 16/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 46s 1s/step - accuracy: 0.8917 - loss: 0.2562 - val_accuracy: 0.8994 - val_loss: 0.2205
Epoch 17/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 49s 1s/step - accuracy: 0.9075 - loss: 0.2298 - val_accuracy: 0.9058 - val_loss: 0.2410
Epoch 18/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 46s 1s/step - accuracy: 0.9200 - loss: 0.2157 - val_accuracy: 0.9351 - val_loss: 0.1972
Epoch 19/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 47s 1s/step - accuracy: 0.9239 - loss: 0.1891 - val_accuracy: 0.9123 - val_loss: 0.2217
Epoch 20/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 45s 1s/step - accuracy: 0.9130 - loss: 0.2367 - val_accuracy: 0.8766 - val_loss: 0.2751
Epoch 21/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 47s 1s/step - accuracy: 0.9105 - loss: 0.2186 - val_accuracy: 0.9221 - val_loss: 0.2224
Epoch 22/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 46s 1s/step - accuracy: 0.9146 - loss: 0.1949 - val_accuracy: 0.9188 - val_loss: 0.2191
Epoch 23/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 49s 1s/step - accuracy: 0.9288 - loss: 0.1793 - val_accuracy: 0.8994 - val_loss: 0.2418
Epoch 24/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 46s 1s/step - accuracy: 0.9088 - loss: 0.2447 - val_accuracy: 0.9091 - val_loss: 0.2558
Epoch 25/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 47s 1s/step - accuracy: 0.9203 - loss: 0.1905 - val_accuracy: 0.9188 - val_loss: 0.2165
Epoch 26/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 46s 1s/step - accuracy: 0.9444 - loss: 0.1624 - val_accuracy: 0.9123 - val_loss: 0.2458
Epoch 27/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 47s 1s/step - accuracy: 0.9347 - loss: 0.1750 - val_accuracy: 0.9318 - val_loss: 0.2091
Epoch 28/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 45s 1s/step - accuracy: 0.9213 - loss: 0.1778 - val_accuracy: 0.9091 - val_loss: 0.2497
Epoch 29/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 47s 1s/step - accuracy: 0.9247 - loss: 0.1981 - val_accuracy: 0.9221 - val_loss: 0.2465
Epoch 30/30
39/39 ━━━━━━━━━━━━━━━━━━━━ 46s 1s/step - accuracy: 0.9331 - loss: 0.1870 - val_accuracy: 0.9221 - val_loss: 0.2095
Enter fullscreen mode Exit fullscreen mode

Comparison

Model Accuracy
ML (HOG + SVM) 74.29%
DL (CNN + Augmentation) 85.71%

Results

Machine Learning AI model obtained an accuracy of 74.29%
Deep Learning AI model obtained an accuracy of 85.71%

that is a huge 11% increase in accuracy.

4 Reasons to spend more time with DL ❤️

  1. Feature Engineering Limitations – ML needs handcrafted features, DL learns them automatically.
  2. Scalability – DL scales better with large and complex datasets.
  3. Pattern Recognition – DL captures subtle shapes and textures that ML may miss.
  4. Modern Workflows – DL integrates seamlessly with images, audio, text, and end-to-end pipelines.

At the end of the day the ML is a machine. And has to be taught what is what and which is which . The DL model since its been inspired by the way the human brain works and uses Artificial Neurons to learn things rather than using a mathematical approach. In scenarios where images, videos are present the DL model surely shall bring about effective results.

The ML has to be told and taught what to do. DL recognizes patterns and learns things automatically.

Deep Learning surely wins over Machine Learning.

⭐️ Vishnu Ajit's Kaggle url

🛠️ Vishnu Ajit's Github url

Top comments (0)