# Regression with images

**URL:** <https://community.konduit.ai/t/regression-with-images/764>\
**Category:** DataVec\
**Created:** [August 3, 2020, 12:02am UTC](https://community.konduit.ai/t/regression-with-images/764 "2020-08-03T00:02:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lavajaw](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lavajaw/32/118_2.png) [@lavajaw](https://community.konduit.ai/u/lavajaw)\
**Post date:** [August 3, 2020, 12:02am UTC](https://community.konduit.ai/t/regression-with-images/764/1 "2020-08-03T00:02:53Z")

</div>

Hello,  
I did age and gender classification, but now i want to modify it to try regression for age.  
I have images and image name carry info about age of person.

ImageRegressionLabelGenerator labelMaker = new ImageRegressionLabelGenerator();

ImageRecordReader recordReader = new ImageRecordReader(height, width, channels, labelMaker);  
recordReader.initialize(trainingData, getImageTransform());  
DataSetIterator dataSetIterator = new RecordReaderDataSetIterator(recordReader, batchSize, 1, 1, true);  
dataNormalization.fit(dataSetIterator);  
dataSetIterator.setPreProcessor(dataNormalization);  
computationGraph.fit(dataSetIterator, numEpochs);

But when I start training, error is:  
Labels and preOutput must have equal shapes: got shapes [32, 65] vs [32, 1]

Batch size is 32, i have 90k images in range from 0 to 64.  
Last layer:  
.addLayer(“outputAge”, new OutputLayer.Builder(LossFunctions.LossFunction.MSE)  
.nOut(1)  
.activation(Activation.IDENTITY)  
.build(), “dense”);  
For architecture I am using denseNet example.

How to create this, so i can make model which for provided image return age?

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [August 13, 2020, 9:00am UTC](https://community.konduit.ai/t/regression-with-images/764/2 "2020-08-13T09:00:24Z")

</div>

Take a look at our regression example here: [deeplearning4j-examples/CSVDataModel.java at 9e971fdb782249873786a960f248247dd28650fa · eclipse/deeplearning4j-examples · GitHub](https://github.com/eclipse/deeplearning4j-examples/blob/9e971fdb782249873786a960f248247dd28650fa/dl4j-examples/src/main/java/org/deeplearning4j/examples/quickstart/modeling/feedforward/regression/CSVDataModel.java)

The key is setting up the recordreaderdatasetiterator to expect regression.

---

<div class="post-metadata">

**Author:** ![lavajaw](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lavajaw/32/118_2.png) [@lavajaw](https://community.konduit.ai/u/lavajaw)\
**Post date:** [August 23, 2020, 8:48pm UTC](https://community.konduit.ai/t/regression-with-images/764/3 "2020-08-23T20:48:14Z")

</div>

Hello,  
thank for response, but i need help with preparing dataset. I see in this example that we have as input same type of data as output (string value). But how to make this if i work with images? I should provide images as input and expect numeric value (example : image of person → 47 years). Any tips how to do it?

Thanks on your time!

---

<div class="post-metadata">

**Author:** ![cagneymoreau](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/cagneymoreau/32/296_2.png) [@cagneymoreau](https://community.konduit.ai/u/cagneymoreau)\
**Post date:** [August 24, 2020, 2:47pm UTC](https://community.konduit.ai/t/regression-with-images/764/4 "2020-08-24T14:47:17Z")

</div>

Check out this youtube video. [Computer Generates Human Faces - YouTube](https://www.youtube.com/watch?v=4VAkrUNLKSo&t=182s)  
I have not done what you are doing but to play around a bit you could crop the faces with opencv and put them into an autoencoder to see what features get picked up.

After that put a feed forward network on the end of the auto encoders encoding side and do normal regression training. If you have a large dataset I think it would work.

Have you tried something like that?
