I'm looking for a neural network architecture that excels in counting objects. For example, CNN that can output the number of balls (or any other object) in a given image.

I already found articles about crowd counting. I'm looking for articles about different types of objects.

  • $\begingroup$ You can run YOLO, then count the number of occurrences. $\endgroup$
    – drerD
    Mar 10, 2019 at 18:30

1 Answer 1


If you want to count the number of objects using a neural network, you can use pretrained YOLO with the bottom prediction layer removed, and feed the features to a classification feed forward layer of let's say 1000 class representing 0-999 objects in the image. You can then train it and propagate the gradients through it. For example, in the pytorch code for YOLO,(source:https://github.com/eriklindernoren/PyTorch-YOLOv3) You can add a nn.Linear and use cross entropy loss to classify the number of images. You can also change the architecture completely. Maybe you can try adding layers to reset or other classifying network to count the number of objects. Hope this can help you and have a nice day!

  • $\begingroup$ May I know why such architecture changes are required? In a normal YOLO, if it detects all the balls, isn't it just a matter of using a for loop to count the output? Why should the neural network count it? $\endgroup$
    – Julia
    May 28 at 5:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .