0
$\begingroup$

I have this CNN based model architecture that takes an RGB image. Now I'm trying to change it for a color classification case on an object (10 color classes: white, black, yellow, etc). This current architecture has achieved good accuracy for a binary classification task before, but I think for color case, it doesn't need to be this complex. So trying to shrink it and make it faster. I want it to be very fast.

How would you change it to make it smaller and faster? Anything like reducing layers, filters, kernel sizes, functions, etc as appicable. Also, feel free to propose other efficient approaches for the purpose of object color classification. Objects are already cropped but can be under different light conditions.

def create_model():
    channels = 3 
    model = Sequential()
    #change first one to 64
    model.add(Conv2D(16, kernel_size = (3, 3), activation='relu', input_shape=(IMAGE_SIZE, IMAGE_SIZE, channels)))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    model.add(Conv2D(32, kernel_size=(3,3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    model.add(Conv2D(64, kernel_size=(3,3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    model.add(Conv2D(128, kernel_size=(3,3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    
    model.add(Conv2D(32, kernel_size=(3,3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    model.add(Dropout(0.2))
    model.add(Flatten())
    model.add(Dense(128, activation='relu'))
    model.add(Dropout(0.2))
    model.add(Dense(64, activation='relu'))
    model.add(Dense(4, activation = 'softmax'))
    
    return model
$\endgroup$
2
  • $\begingroup$ This may be a gross oversimplification, but if you have the objects already cropped, have you considered just taking the average over all of the pixels? $\endgroup$ Commented Feb 11 at 8:25
  • $\begingroup$ Yeah it is not accurate. I need something smarter. Objects are under different lighting condition $\endgroup$
    – Mary
    Commented Feb 11 at 13:59

1 Answer 1

0
$\begingroup$

From looking at what you've provided for your problem i'd consider the following;

Reduce the Number of Layers: The original model had multiple convolutional and dense layers, which increased the model's complexity and computational load. By removing some of these layers, we simplify the architecture, which can improve speed and reduce overfitting, especially for a color classification task that may not require as many layers as a more complex task like object detection.

Decrease Filters and Kernel Sizes: While the number of filters and kernel sizes was kept relatively similar to the original model, the overall complexity was reduced by removing a convolutional layer and simplifying the dense layers. This reduction in complexity can help in achieving faster inference times and reducing computational load while still capturing important features for color classification.

Optimized Functions: The number of filters was reduced, and the structure of the dense layers was simplified to reduce the computational load and improve speed. This adjustment aims to strike a balance between model complexity and performance, ensuring that the model remains efficient for color classification while achieving faster inference times.

Adjust Output Dense Layer: The number of output classes in the final dense layer was changed to 10 to match the 10 color classes for color classification. This modification aligns the model's output with the specific color classification task, ensuring that the model is tailored to predict the color classes accurately.

from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, BatchNormalization, Flatten, Dense, Dropout

def create_model():
    channels = 3 
    model = Sequential()
    model.add(Conv2D(16, kernel_size=(3, 3), activation='relu', input_shape=(IMAGE_SIZE, IMAGE_SIZE, channels)))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    model.add(Conv2D(32, kernel_size=(3,3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    model.add(Conv2D(64, kernel_size=(3,3), activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2)))
    model.add(BatchNormalization())
    model.add(Dropout(0.2))
    model.add(Flatten())
    model.add(Dense(64, activation='relu'))
    model.add(Dense(10, activation='softmax'))  # Changed to 10 classes for color classification
    
    return model

Hope this is useful to you!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.