0
$\begingroup$

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:

enter image description here

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:

enter image description here

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:

enter image description here

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.Conv2D(16, 3, padding='same', activation='relu'),
  layers.MaxPooling2D(),
  layers.Conv2D(32, 3, padding='same', activation='relu'),
  layers.MaxPooling2D(),
  layers.Conv2D(64, 3, padding='same', activation='relu'),
  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).

I've be very grateful for any advice - thanks in advance!

$\endgroup$
1
  • $\begingroup$ 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? $\endgroup$
    – Oxbowerce
    May 19 at 13:56
0
$\begingroup$

This doesn't seem like a Deep Learning problem, this could be solved by classic Computer Vision techniques, so maybe you could inspire your architecture by those.

  • Check is your model convolutional layers receptive field is large enough for the shapes you trying to count.

  • You probably won't be able to do counting without some kind of post processing

  • Check Yolo strategies, you probably will be able to do a counter with it.

  • This is a object detection problem, you will often have poor performance trying to use a architecture designed for image classification such as AlexNet while trying to face this as a regression problem.

  • Your output size should probably be a varying length vector from which the length is the desired count.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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