-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draw a random coefficient sample in MoMoInstance #94
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am somehow not sure if we should provide this functionality in the MoMoInstance or MoMoCoefficients class. Of course, at the moment they have a very strict setting they are applied to in our framework but others might reuse them without the restriction of each coefficient being standard Gaussian distributed. This property is induced by using a specific model and not from the coefficients class.
@@ -17,6 +17,7 @@ | |||
package scalismo.faces.momo | |||
|
|||
import breeze.linalg.DenseVector | |||
import breeze.stats.distributions.Gaussian |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do not move the functionality from MoMoInstance to here then this import is not needed.
|
||
/** create a random coefficient vector with its elements N(0,1) distributed. */ | ||
def sample(model: MoMo, modelURI: URI)(implicit rnd: Random): MoMoInstance = { | ||
val fullShapeCoeffs = for (_ <- 0 until model.neutralModel.shape.rank) yield Gaussian(0, 1).draw() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why creating a Gaussian(0,1) three times? You could also use rng.breezeRandBasis.gaussian.draw() instead.
@@ -141,6 +143,20 @@ object MoMoInstance { | |||
modelURI: URI): MoMoInstance = { | |||
fromCoefficients(MoMoCoefficients.zeros(shapeComponents, colorComponents, expressionComponents), modelURI) | |||
} | |||
|
|||
/** create a random coefficient vector with its elements N(0,1) distributed. */ | |||
def sample(model: MoMo, modelURI: URI)(implicit rnd: Random): MoMoInstance = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first part of this function should go to MoMoCoefficients.sample() and then call this function here.
val fullShapeCoeffs = for (_ <- 0 until model.neutralModel.shape.rank) yield Gaussian(0, 1).draw() | ||
val fullColorCoeffs = for (_ <- 0 until model.neutralModel.color.rank) yield Gaussian(0, 1).draw() | ||
val expressionRank = model.expressionModel.get.expression.rank | ||
val coeff = if(expressionRank > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not need to check. The if and else branch do exactly the same for values smaller or equal zero.
In this implementation the coefficients are always of full rank of the model. In practice it is often desired to have only the first x parameters. The MoMo itself has already a sample function which gives the VertexColorMesh directly. Without the possibility to use less parameters I see no benefit... |
@Andreas-Forster
|
Just a side note: In |
@sschoenborn Thank you for pointing that out. I think this is maybe the best solution for this. I provided the implementation in addition to the former one. @BernhardEgger I think it is a rare case where you want to have coefficients with a lot of different length in one application. So given this new solution, you would truncate the model first before sampling the coefficients. This makes also the generation of instances faster afterward. @andreas-schneider It would now be possible to write: val model: MoMo = ???
val modelURI: URI = ???
val renderer = MoMoRenderer(model)
val parameter = RenderParameter.defaultSquare.withMoMo(MoMoInstance.fromCoefficients(model.sampleCoefficients(),modelURI))
val randomRendering = renderer.renderImage(parameter) What do you think about this solution? (Please do not merge as we should clean one of the solutions before.) |
Yes, the sampleCoefficients sounds good. I have updated it accordingly. |
Currently, it is laborious to draw a random MoMoInstance random coefficient that can be used for example rendering a random model sample.
Functionality:
Draws shape, color and expression vector entries N(0,1) distributed.
This is a possible use case of the proposed functionality: