Simple neural network (conceptual) be used for bounding box prediction? I am writing a very simple neural network to see whether it can be used for my scoped case of drawing a bounding box around a specific object (barcode) in an image.
The layers i am thinking of are:

*

*One convolution to detect edges and learn features of the barcode

*a few dense layers to adjust for predicting the 4 data points (x1,y1,x2,y2) of the specific object in the image.

In code, this is the basic schema:
// Generate a sequential model
const baseModel = tf.sequential();

// Layer 1: Convolutional
baseModel.add(
  tf.layers.conv2d({
    inputShape: [224, 224, 1],
    filters: 64,
    kernelSize: 4,
    padding: "same",
    activation: "relu",
  })
);

baseModel.add(tf.layers.flatten())
baseModel.add(tf.layers.dense({ units: 128, activation: "relu" }))
baseModel.add(tf.layers.dense({ units: 64, activation: "relu" }))
baseModel.add(tf.layers.dense({ units: 4, activation: "sigmoid" }))
baseModel.compile({
  optimizer: tf.train.adam(0.00001), //could be a parameter as well.
  loss: tf.losses.meanSquaredError,
});

Would this steps be reasonable towards my goal of predicting bounding boxes?
I have read other posts and models, they normally use huge models with pretrained weights, but I wonder if, for a specific case, this schema could be enough.

Detecting edges with several filters in a single layer seems like it could recognize a barcode, but you have to train 64x4x4 weights. Is that really neccesary. And why 64 filters? To capture multiple orientations?
Possibly a more complex architecture with multiple layers (but less parameters) may help to improve the performance with less training. Here is a wild guess:
Try to mimic the process of a real laser scanner,

*

*You scan for high contrast stripes (or edges). This can be done with a few 3x3 filters that detect high contrast lines. Or alternatively a few 1xn filters that operate on several preprocessed rotated versions of the image.
The coefficients of this convolution layer might not need to be trained. It can be seen as a preprocessing step.
Possibly you can also detect the stripes by detecting first edges and in the image with the edges you detect nearby maximum and minimum peaks. That might be more robust to barcode stripes that cover more than one pixel. Anyway, the point is that you might tackle the edge/line detection more as a preprocessing step that you do not include into the learning of the neural network.


*You have an additional layer that arranges the sensitivity. A scanner will only respond when the lines are

*

*wide (a second convolution layer)

*multiple in a row (a third convolution layer)



With those convolutions you can detect whether a barcode is present in a similar way as a real barcode scanner does it. Finally you add those relu-layers to find the end, start and orientation of the barcode.
