<p>The short answer is &quot;<strong>yes</strong>&quot;: <em>it is a good idea to have as many neurons in output as you have in input, i.e. to output an image with the same resolution of the input images</em>.</p>
<p>The network architecture will have an input layer with a neuron for each pixel, then typically the hidden layers will shrink to less neurons, probably with <em>convolutional</em> layers, and then some more layers will re-expand the number of neurons, up to the output layer, which in principle may have the same number of neurons as the input layer.</p>
<p>The most common architecture in this type of problem is the <strong>U-net architecture</strong>, described in the article &quot;<em>U-Net: Convolutional Networks for Biomedical Image Segmentation</em>&quot;, by Ronneberger, Fischer, and Brox, published on the open arxiv: <a href="https://arxiv.org/abs/1505.04597" rel="nofollow noreferrer">https://arxiv.org/abs/1505.04597</a>.</p>
<p>[<img src="https://i.stack.imgur.com/ZBIFe.png" alt="U-net architecture, as described in the article &quot;U-Net: Convolutional Networks for Biomedical Image Segmentation&quot;, by Ronneberger, Fischer, and Brox, published on the open arxiv: ][1]" /></p>
How to design a model for contour recognition? In particular, how to shape the output layer?
<p>I want to design and train a <strong>neural network</strong> for the <strong>automatic recognition of the edges</strong>, in some microscopic images.
I am using Keras for a start, I may consider PyTorch later.</p>
<p>The <strong>structure</strong> of the images is rather simple, with some <strong>dark areas</strong>, and some <strong>clear areas</strong>, relatively easy to distinguish, and the task is to select the pixels of the contour between <em>dark</em> and <em>clear</em> areas. The transition between dark and clear is gradual, so my result is not a single line of edge pixels, but rather a 10 or 15 pixels wide &quot;ribbon&quot; at the edge.</p>
<p>I have manually annotated 200-something images, so for each image I have another image, of the same size, where the pixels of the contours are black, and all the other pixels are white.</p>
<p>I have seen many tutorials on how to <em>design</em>, <em>compile</em> and <em>fit</em> a model (a neural network), and then how to test it, using the manually annotated data.</p>
<p>However, most of the tutorials work on problems of classification, where the number of neurons in the output layer is the number of categories.</p>
<p>My problem is <strong>not a problem of classification</strong>, and ideally my output should be an image of the same size of the input.</p>
<p>So, here is my question:</p>
<p><em>What is the best way to design the output layer? Is a layer with a number of neurons equal to the number of pixels the best idea? Or this is a waste, and there is a more efficient way?</em></p>
<hr />
<p><strong>Addendum</strong></p>
<ol>
<li>The images are &quot;easy&quot;, but it is still difficult to find the contour pixels, so I believe that it is worth using the machine learning approach.</li>
<li>The transition between dark and clear is a little gradual, so my result is not a single line of pixels on the edge, but rather a band, a 10 or 15 wide ribbon of edge pixels. Since I am after a ribbon of pixels, my categories should be &quot;edge&quot; and &quot;not-edge&quot;. If I use the categories &quot;dark pixels&quot; and &quot;clear pixels&quot;, and then numerically find the pixels between the two areas I do not get the &quot;ribbon&quot; result, which I need.</li>
</ol>