Answers.Body: <p>Well, if you are using high-level libraries, you don't have to find filters by yourself. Kernel types might change throughout the process, if you are trying to find different patterns, there will be different type of filters too.</p>
  <p>Here is a Keras functional api code that might help you in this context. Also notice that there is a stride of 2 which means your image would shrink into half by each Conv2D layers, this also helps your filters to find bigger patterns since they are covering more space on the image.</p>
  <pre><code>i = Input(shape=x_train[0].shape)
  x = Conv2D(32, (3,3), strides=2, activation='relu')(i)
  x = Conv2D(64, (3,3), strides=2, activation='relu')(x)
  x = Conv2D(128, (3,3), strides=2, activation='relu')(x)
  x = Flatten()(x)
  x = Dropout(0.5)(x)
  x = Dense(1024, activation='relu')(x)
  x = Dropout(0.2)(x)
  x = Dense(4, activation='softmax')(x)
  model = Model(i, x)
  </code></pre>
  <p>How you find the most fitting layers with filters is mostly intuition. These types of variables are called <code>hyper-parameters</code>. There are conventions about these too.</p>
  <p>How you label your data is basically training your neural network with a vector of targets, which would correspond to your training data's indexes.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-22T06:27:32.947Z
Answers.Text: This network's structure doesn't really correspond to the question's case. They have `n` input images, looking to identify and count `m` different classes and outputting their total numbers.
Answers.UserDisplayName: NikoNyrh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-23T03:13:48.553Z
Answers.LastActivityDate: 2023-01-23T03:13:48.553Z
Answers.UserDisplayName: murat.sahin.dev
Answers.Body: <p>You can probably look at <a href="https://machinethink.net/blog/object-detection-with-yolo/" rel="nofollow noreferrer">object detection</a> models. Then count the number of boxes for each category that is created by the network. See for example the following image from the linked blog post:</p>
  <p><a href="https://i.sstatic.net/GTEbs.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GTEbs.png" alt="enter image description here" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-20T16:30:13.960Z
Answers.LastActivityDate: 2023-10-20T16:30:13.960Z
Answers.UserDisplayName: Ron
Body: <p>Let's say there are three images in the test set, the first with three triangles, the second with two triangles and two circles, the third with four circles and two squares, and the final tally is a total of 5 triangles, 6 circles, 2 squares and 0 pentagrams (if the &quot;pentagram &quot; is also included in the labels in the training set)
  How should I design the layers of this neural network and do I need to use more than one sort of kernel and filter? How could I label the images in my training set (for instance, the training set I mentioned above)?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-02-22T06:24:36.327Z
Comments.Text: Is a cumulative count really necessary, if you have separate input images? Adding up the number of predicted items / image is tricky for the loss function, since 3 + 2 + 0 triangles = 5, but so is 0 + 0 + 5.
Comments.UserDisplayName: NikoNyrh
Tags: <convolutional-neural-networks><computer-vision><image-recognition>
Title: How can I use CNN to make a cumulative count of the number of occurrences of each of the different objects in all the images in the test set?
UserDisplayName: El J 1e2
ThreadText: # How can I use CNN to make a cumulative count of the number of occurrences of each of the different objects in all the images in the test set?
  
  (Asked by: username_0 on 2023-01-02)
  
  Let's say there are three images in the test set, the first with three triangles, the second with two triangles and two circles, the third with four circles and two squares, and the final tally is a total of 5 triangles, 6 circles, 2 squares and 0 pentagrams (if the "pentagram " is also included in the labels in the training set)
  How should I design the layers of this neural network and do I need to use more than one sort of kernel and filter? How could I label the images in my training set (for instance, the training set I mentioned above)?
  
  **Tags:** convolutional-neural-networks, computer-vision, image-recognition
  
  > **Comments:**
  > **username_1**: Is a cumulative count really necessary, if you have separate input images? Adding up the number of predicted items / image is tricky for the loss function, since 3 + 2 + 0 triangles = 5, but so is 0 + 0 + 5.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2023-01-23. Score: 1
  
  Well, if you are using high-level libraries, you don't have to find filters by yourself. Kernel types might change throughout the process, if you are trying to find different patterns, there will be different type of filters too.
  
  Here is a Keras functional api code that might help you in this context. Also notice that there is a stride of 2 which means your image would shrink into half by each Conv2D layers, this also helps your filters to find bigger patterns since they are covering more space on the image.
  
  ```
  i = Input(shape=x_train[0].shape)
  x = Conv2D(32, (3,3), strides=2, activation='relu')(i)
  x = Conv2D(64, (3,3), strides=2, activation='relu')(x)
  x = Conv2D(128, (3,3), strides=2, activation='relu')(x)
  x = Flatten()(x)
  x = Dropout(0.5)(x)
  x = Dense(1024, activation='relu')(x)
  x = Dropout(0.2)(x)
  x = Dense(4, activation='softmax')(x)
  model = Model(i, x)
  
  ```
  
  How you find the most fitting layers with filters is mostly intuition. These types of variables are called `hyper-parameters`. There are conventions about these too.
  
  How you label your data is basically training your neural network with a vector of targets, which would correspond to your training data's indexes.
  
  > **Comments:**
  > **username_1**: This network's structure doesn't really correspond to the question's case. They have `n` input images, looking to identify and count `m` different classes and outputting their total numbers.  
  
  ---
  
  ### Answer by username_3 on 2023-10-20. Score: 0
  
  You can probably look at [object detection](https://machinethink.net/blog/object-detection-with-yolo/) models. Then count the number of boxes for each category that is created by the network. See for example the following image from the linked blog post:
  
  [![enter image description here](https://i.sstatic.net/GTEbs.png)](https://i.sstatic.net/GTEbs.png)
  
  
  ---
  
  