# CNN Design for Counting on Simple Images

This is the first CNN I'm designing following college examples and assignments. I'm working on a CNN that I'd like to use to classify images by the number of shapes on them. My basic problem is that I can't seem, to get the CNN to respond (accuracy and val_accuracy are flat) after n EPOCHS (I have varied n these along with Steps and Batch Size) The images are 98 x 150 pixels and look like this:

This is 10 data squares on a by background. The image set has been built by varying the position of the shapes on the image, changing the background color (4 colors), changing the shape color (3 colors), changing the shape type (square, circle, hexagon), flipping the images (vert/horiz). The images are stored in folders (1-26) with 1 having 1 shape per image, 26 having 26 shapes per image. There are 3300 images per folder totaling ~86k images (I have experimented with a lower number of shapes). Here's an images of the training/validation file counts:

The problem I'm seeing is the model never seems to "initialize" in other words the accuracy and validation accuracy do not change much while training the model:

The accuracy and val_accuracy are very different to any models I've worked with - normally I see a fast ramp rate which tapers off as the model trains. In this case both are flat and never increase. Even after larger EPOCHs.

Here's one of the models I've tried:

# Define the Model
model = models.Sequential([
layers.experimental.preprocessing.Rescaling(1./255, input_shape=(img_height, img_width, 3)),
layers.MaxPooling2D(),
layers.MaxPooling2D(),
layers.MaxPooling2D(),
layers.flatten(),
layers.Dense(512, activation='relu'),
layers.Dense(num_classes)
])


I've tried several variants of this model along with an AlexNET all yield the same results.

I'm thinking that maybe the images are too simple/varied for the model to train? Maybe putting the shapes on a pixelated background would help make them more complex/varied? I'm also wondering whether initializing the model with random weights/biasses might help? I'm using Tensorflow 2.x and don't know whether this is done automatically.

Does anyone have any thoughts/advice on how I may improve the model and at least see accuracy/validation increase rather than it being flat? I could deal with overfitting later (if it occurs).

• Have you tried predicting bounding boxes or a density map from which you count the number of objects instead of directly predicting the number of objects in the image? – Oxbowerce May 19 at 13:56