Answers.Body: <p>In general <a href="https://en.wikipedia.org/wiki/Convolutional_neural_network" rel="nofollow noreferrer">Convolutional Neural Networks</a> work well with images, be it a regression or a classification problem. In your case the number of images is very small, so heavy data augmentation should be used. And the network itself has to be fairly simple, to avoid overfitting. But without access to the data it is hard to recommend any actual architecture (number of layers, kernels, activations, ...).</p>
  <p>Estimating the density is an interesting problem, it is a property of the material (assuming it isn't hollow) and is independent of the size of the object. If your objects are quite uniform in size the network might have problem with smaller and bigger objects than what you have in the training data.</p>
  <p>If your images are high resolution, I'd consider splitting them into smaller crops (optionally with varying sizes, then resizing them into a common resolution) to get more training data.</p>
  <p>I would also try altering the model to predict the weight and thickness as separate outputs, this way you can see which property is more difficult to predict and you can focus on that. If you feel fancy your model can have three outputs (weight, thickness, density) and optimize a weighted loss on all of them at once.</p>
  <p>If you can publish the data I'd be interested to implement a reference solution and see how accurate it would be. By default I would not share the source code with you, just the results and give you guidance.</p>
  <p><strong>Edit</strong>:</p>
  <p>I sorted the images by the known density, and noticed that it correlates quite well with the object's apparent size. This is unexpected (if you weren't measuring the mass), it sounds implausible that the largest objects would be the densest. The opposite could be explained if they started at a similar size and weight, and some were compressed down into a more dense form.</p>
  <p><em>Or is it that several smaller object will back denser than fewer larger ones? I had thought of this only in the context of a single object.</em> edit 2: this is irrelevant, in the data largest objects are densest.</p>
  <p>The change in hue is due to normalization, and I didn't convert the images to grayscale.</p>
  <p>Looks like the grid's first image's (_DSC3479.JPG) data entry is incorrect, it may have an extra zero after the decimal comma.</p>
  <p><a href="https://i.sstatic.net/TSSiy.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/TSSiy.jpg" alt="pebbles" /></a></p>
  <p>Anyway, fitting a linear regression to this data will give you a good starting point. It would give a prediction of 0.099 (median of the six nearest neighbours), which is off by just 5% from the presumed correct value of 0.104.</p>
  <p>It seems that CNNs will not help you much here, due to low amount of data and after all small size of the objects. There isn't much detail in the texture, but shading seems to give some hint of the 3D structure. If possible, I would take 10 photos of each object in a random orientation. Naturally you need to measure their density just once :) This would be much better than rotating the images after the fact. And try to place the camera closer, so that the objects would be 250 - 400 pixels in width.</p>
  <p>The dirty background shouldn't be an issue, actually it would be a good exercise to train a pre-processing network which would do the job for you.</p>
  <p><a href="https://i.sstatic.net/TXjma.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/TXjma.png" alt="scatter" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T18:07:18.357Z
Answers.Text: To be honest I did not load and preprocess this dataset yet since my coding knowledge is poor(I am an amateur student). I only made high-resolution images that are all same sized and have the same distance from objects: https://drive.google.com/file/d/1ZhvdIjY7SPrpkP6JgVfxqtre1Xr200ZQ/view?usp=sharing
  I also forgot to mention that I should calculate some interesting properties such as the area/volume of an object(in this case fertilizer granule). But the output is the estimation of the density of an object as said in the post.
  However, I really appreciate your help and potential guidance.
Answers.UserDisplayName: Sevcenko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T18:21:16.810Z
Answers.Text: Thanks for the link, images are indeed high resolution but the objects are rather small (100 - 200 px wide). Could you also upload a file which has known densities of these objects? It could be for example a CSV, with columns "filename" and "density".
Answers.UserDisplayName: NikoNyrh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T19:45:00.643Z
Answers.Text: https://docs.google.com/spreadsheets/d/1kcmNRK3EcWkmYErK1rKAwJsNKnfaDOe8/edit?usp=sharing&ouid=101648245388903582171&rtpof=true&sd=true 
  Here is the link for the CSV file for manually measured weights. The excel automatically remove some 0s on the end so two and one-digit numbers are actually three-digit numbers (0.06 = 0.060 or 0.1 = 0.100). Column A is the filename and Column B is a weight, which is easy to notice.  Btw, do you know some good tutorial to load and process images?
Answers.UserDisplayName: Sevcenko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T20:39:38.223Z
Answers.Text: There are several image libraries for python, such as Scipy, Python Image Library and OpenCV. Any convolutional neural network tutorial should have examples as well, although they might load a pre-existing dataset such as MNIST. Oh and Kaggle is full of examples, for all the popular deep learning libraries.
Answers.UserDisplayName: NikoNyrh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T23:43:45.780Z
Answers.Text: Thanks for the help and suggestions, but I think I did not explain it well and led you to misunderstand. The weights in CSV file are mass estimations expressed in grams measured manually on a scale. I think I need to measure area/volume using object localization(deep learning?) through CNNs and in the end calculate density with the simple formula g/mm. Anyway, I am thinking about making more photos tomorrow from a closer distance. Did you think of angles when you said taking pictures in a random orientation? I am very low on time and that is also a big setback.
Answers.UserDisplayName: Sevcenko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-03T00:37:52.207Z
Answers.Text: Also, the data entry on the image DSC3479 is wrong. The 0 is mistakenly added after comma. Now I am so confused now I think it's impossible to be made.  Could you please send me a portion of the code that made crops of these pictures and merged it into this plot. That would help me a lot.
Answers.UserDisplayName: Sevcenko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-03T08:15:14.940Z
Answers.Text: If you want to train a network to predict the density, you need to provide it such training data. But ah if the CSV had masses, then this is actually quite solvable by a simple neural network even without extra data. (With more photos I thought of removing and re-placing the object in camera's view.) If this is a school project I think you should write the code yourself, and if you are stuck then ask a new question here. My code for cropping doesn't involve any AI, it just checks the row and column with the lowest mean pixel brightness.
Answers.UserDisplayName: NikoNyrh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-03T11:41:27.353Z
Answers.Text: I did some research last night. I used LabelImage to add a bit more data to the object. I think of adding more photos and also using Convex Hull to estimate the area/volume of an object after that or do you think there are easier ways to compute it? Maybe I do not need CNNs at all for this task. 
  Input > Object localization > Area estimation using Convex Hull > Some pooling layer?> Simple formula computation in dense output layer. Do you think this looks like good idea of a project? And what do you think which activation layer should I use and should I use different angles for images of objec
Answers.UserDisplayName: Sevcenko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-03T12:34:48.210Z
Answers.Text: I tried a simple regression with Keras and it was suprisingly difficult to get working. I might ask a separate issue on this topic some day. Start with something simple and get it working first, and I suggest you to use Scipy rather than neural networks for simple "y = ax + b" regression.
Answers.UserDisplayName: NikoNyrh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-02T15:26:19.827Z
Answers.LastActivityDate: 2022-02-03T08:08:34.810Z
Answers.LastEditDate: 2022-02-03T08:08:34.810Z
Answers.UserDisplayName: NikoNyrh
Body: <p>What are the best Deep learning models(with how many layers) to use in a regression task for a custom dataset containing around 100 images of only one object per image which is more or less centralized? The object is measured manually with a weight scale and the output of the model is the estimation of the density of an object expressed in g/mm.</p>
  
Tags: <deep-learning><convolutional-neural-networks><image-recognition><image-processing><regression>
Title: What's the best model to use for CNN(deep learning) regression task for small image dataset?
UserDisplayName: Sevcenko
ThreadText: # What's the best model to use for CNN(deep learning) regression task for small image dataset?
  
  (Asked by: username_0 on 2022-02-02)
  
  What are the best Deep learning models(with how many layers) to use in a regression task for a custom dataset containing around 100 images of only one object per image which is more or less centralized? The object is measured manually with a weight scale and the output of the model is the estimation of the density of an object expressed in g/mm.
  
  **Tags:** deep-learning, convolutional-neural-networks, image-recognition, image-processing, regression
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-02-02. Score: 0
  
  In general [Convolutional Neural Networks](https://en.wikipedia.org/wiki/Convolutional_neural_network) work well with images, be it a regression or a classification problem. In your case the number of images is very small, so heavy data augmentation should be used. And the network itself has to be fairly simple, to avoid overfitting. But without access to the data it is hard to recommend any actual architecture (number of layers, kernels, activations, ...).
  
  Estimating the density is an interesting problem, it is a property of the material (assuming it isn't hollow) and is independent of the size of the object. If your objects are quite uniform in size the network might have problem with smaller and bigger objects than what you have in the training data.
  
  If your images are high resolution, I'd consider splitting them into smaller crops (optionally with varying sizes, then resizing them into a common resolution) to get more training data.
  
  I would also try altering the model to predict the weight and thickness as separate outputs, this way you can see which property is more difficult to predict and you can focus on that. If you feel fancy your model can have three outputs (weight, thickness, density) and optimize a weighted loss on all of them at once.
  
  If you can publish the data I'd be interested to implement a reference solution and see how accurate it would be. By default I would not share the source code with you, just the results and give you guidance.
  
  **Edit**:
  
  I sorted the images by the known density, and noticed that it correlates quite well with the object's apparent size. This is unexpected (if you weren't measuring the mass), it sounds implausible that the largest objects would be the densest. The opposite could be explained if they started at a similar size and weight, and some were compressed down into a more dense form.
  
  *Or is it that several smaller object will back denser than fewer larger ones? I had thought of this only in the context of a single object.* edit 2: this is irrelevant, in the data largest objects are densest.
  
  The change in hue is due to normalization, and I didn't convert the images to grayscale.
  
  Looks like the grid's first image's (\_DSC3479.JPG) data entry is incorrect, it may have an extra zero after the decimal comma.
  
  [![pebbles](https://i.sstatic.net/TSSiy.jpg)](https://i.sstatic.net/TSSiy.jpg)
  
  Anyway, fitting a linear regression to this data will give you a good starting point. It would give a prediction of 0.099 (median of the six nearest neighbours), which is off by just 5% from the presumed correct value of 0.104.
  
  It seems that CNNs will not help you much here, due to low amount of data and after all small size of the objects. There isn't much detail in the texture, but shading seems to give some hint of the 3D structure. If possible, I would take 10 photos of each object in a random orientation. Naturally you need to measure their density just once :) This would be much better than rotating the images after the fact. And try to place the camera closer, so that the objects would be 250 - 400 pixels in width.
  
  The dirty background shouldn't be an issue, actually it would be a good exercise to train a pre-processing network which would do the job for you.
  
  [![scatter](https://i.sstatic.net/TXjma.png)](https://i.sstatic.net/TXjma.png)
  
  > **Comments:**
  > **username_0**: To be honest I did not load and preprocess this dataset yet since my coding knowledge is poor(I am an amateur student). I only made high-resolution images that are all same sized and have the same distance from objects: https://drive.google.com/file/d/1ZhvdIjY7SPrpkP6JgVfxqtre1Xr200ZQ/view?usp=sharing I also forgot to mention that I should calculate some interesting properties such as the area/volume of an object(in this case fertilizer granule). But the output is the estimation of the density of an object as said in the post. However, I really appreciate your help and potential guidance.  
  > **username_1**: Thanks for the link, images are indeed high resolution but the objects are rather small (100 - 200 px wide). Could you also upload a file which has known densities of these objects? It could be for example a CSV, with columns "filename" and "density".  
  > **username_0**: https://docs.google.com/spreadsheets/d/1kcmNRK3EcWkmYErK1rKAwJsNKnfaDOe8/edit?usp=sharing&ouid=101648245388903582171&rtpof=true&sd=true  Here is the link for the CSV file for manually measured weights. The excel automatically remove some 0s on the end so two and one-digit numbers are actually three-digit numbers (0.06 = 0.060 or 0.1 = 0.100). Column A is the filename and Column B is a weight, which is easy to notice.  Btw, do you know some good tutorial to load and process images?  
  > **username_1**: There are several image libraries for python, such as Scipy, Python Image Library and OpenCV. Any convolutional neural network tutorial should have examples as well, although they might load a pre-existing dataset such as MNIST. Oh and Kaggle is full of examples, for all the popular deep learning libraries.  
  > **username_0**: Thanks for the help and suggestions, but I think I did not explain it well and led you to misunderstand. The weights in CSV file are mass estimations expressed in grams measured manually on a scale. I think I need to measure area/volume using object localization(deep learning?) through CNNs and in the end calculate density with the simple formula g/mm. Anyway, I am thinking about making more photos tomorrow from a closer distance. Did you think of angles when you said taking pictures in a random orientation? I am very low on time and that is also a big setback.  
  > **username_0**: Also, the data entry on the image DSC3479 is wrong. The 0 is mistakenly added after comma. Now I am so confused now I think it's impossible to be made.  Could you please send me a portion of the code that made crops of these pictures and merged it into this plot. That would help me a lot.  
  > **username_1**: If you want to train a network to predict the density, you need to provide it such training data. But ah if the CSV had masses, then this is actually quite solvable by a simple neural network even without extra data. (With more photos I thought of removing and re-placing the object in camera's view.) If this is a school project I think you should write the code yourself, and if you are stuck then ask a new question here. My code for cropping doesn't involve any AI, it just checks the row and column with the lowest mean pixel brightness.  
  > **username_0**: I did some research last night. I used LabelImage to add a bit more data to the object. I think of adding more photos and also using Convex Hull to estimate the area/volume of an object after that or do you think there are easier ways to compute it? Maybe I do not need CNNs at all for this task.  Input > Object localization > Area estimation using Convex Hull > Some pooling layer?> Simple formula computation in dense output layer. Do you think this looks like good idea of a project? And what do you think which activation layer should I use and should I use different angles for images of objec  
  > **username_1**: I tried a simple regression with Keras and it was suprisingly difficult to get working. I might ask a separate issue on this topic some day. Start with something simple and get it working first, and I suggest you to use Scipy rather than neural networks for simple "y = ax + b" regression.  
  
  ---
  
  