Skip to content

Commit

Permalink
streamlined setup for solve and parameters objects
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch committed Aug 15, 2023
1 parent 470037c commit 53a8517
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
import org.janelia.render.client.newsolver.blocksolveparameters.FIBSEMAlignmentParameters.PreAlign;
import org.janelia.render.client.newsolver.setup.AffineSolverSetup;
import org.janelia.render.client.newsolver.setup.RenderSetup;
import org.janelia.render.client.solver.DistributedSolveParameters;
import org.janelia.render.client.solver.RunParameters;

import mpicbg.models.Affine2D;
import mpicbg.models.AffineModel2D;
import mpicbg.models.Model;

public class AffineDistributedSolver
{
public static void main( final String[] args ) throws IOException
{
final AffineSolverSetup setupParameters = new AffineSolverSetup();
final AffineSolverSetup cmdLineSetup = new AffineSolverSetup();

// TODO: remove testing hack ...
if (args.length == 0) {
Expand Down Expand Up @@ -53,47 +53,70 @@ public static void main( final String[] args ) throws IOException
"--maxPlateauWidthGlobal", "50",
"--maxIterationsGlobal", "10000",
};
setupParameters.parse(testArgs);
cmdLineSetup.parse(testArgs);
} else {
setupParameters.parse(args);
cmdLineSetup.parse(args);
}

final RenderSetup renderSetup = RenderSetup.setupSolve( setupParameters );
final RenderSetup renderSetup = RenderSetup.setupSolve( cmdLineSetup );

new AffineDistributedSolver().setup(
cmdLineSetup,
renderSetup,
cmdLineSetup.blockModel(),
cmdLineSetup.stitchingModel() );
}

public < M extends Model< M > & Affine2D< M >, S extends Model< S > & Affine2D< S > > void setup(
final AffineSolverSetup cmdLineSetup,
final RenderSetup renderSetup,
final M blockModel,
final S stitchingModel )
{
//
// setup Z BlockFactory
//
final int minZ = (int)Math.round( renderSetup.minZ );
final int maxZ = 5000;//(int)Math.round( runParameters.maxZ );
final int blockSize = setupParameters.blockSize;
final int minBlockSize = setupParameters.minBlockSize;
final int blockSize = cmdLineSetup.blockSize;
final int minBlockSize = cmdLineSetup.minBlockSize;

final BlockFactory< ZBlockFactory > blockFactory = new ZBlockFactory( minZ, maxZ, blockSize, minBlockSize );
/*

//
// setup FIB-SEM solve parameters
//
final PreAlign preAlign = PreAlign.NONE;
FIBSEMAlignmentParameters solveParams = new FIBSEMAlignmentParameters(
parameters.blockModel(),
(Function< Integer, Affine2D<?> > & Serializable )(z) -> parameters.stitchingModel(),
(Function< Integer, Integer > & Serializable )(z) -> parameters.minStitchingInliers,
parameters.blockOptimizerLambdasRigid,
parameters.blockOptimizerLambdasTranslation,
parameters.blockOptimizerIterations,
parameters.blockMaxPlateauWidth,
parameters.blockMaxAllowedError,
preAlign,
parameters.renderWeb.baseDataUrl,
parameters.renderWeb.owner,
parameters.renderWeb.project,
parameters.stack );
final boolean stitchFirst = cmdLineSetup.stitchFirst;

final FIBSEMAlignmentParameters< M, S > solveParams = new FIBSEMAlignmentParameters< M, S >(
blockModel,
stitchFirst ? (Function< Integer,S > & Serializable )(z) -> stitchingModel : null,
stitchFirst ? (Function< Integer, Integer > & Serializable )(z) -> cmdLineSetup.minStitchingInliers : null,
cmdLineSetup.maxAllowedErrorStitching,
cmdLineSetup. maxIterationsStitching,
cmdLineSetup.maxPlateauWidthStitching,
cmdLineSetup.blockOptimizerLambdasRigid,
cmdLineSetup.blockOptimizerLambdasTranslation,
cmdLineSetup.blockOptimizerLambdasRegularization,
cmdLineSetup.blockOptimizerIterations,
cmdLineSetup.blockMaxPlateauWidth,
cmdLineSetup.blockMaxAllowedError,
cmdLineSetup.maxNumMatches,
cmdLineSetup.maxZRangeMatches,
cmdLineSetup.preAlign,
cmdLineSetup.renderWeb.baseDataUrl,
cmdLineSetup.renderWeb.owner,
cmdLineSetup.renderWeb.project,
cmdLineSetup.stack,
cmdLineSetup.matchOwner,
cmdLineSetup.matchCollection );

//
// create all blocks
//
BlockCollection col = blockFactory.defineBlockCollection( solveParams );
*/
final BlockCollection< M, AffineModel2D, FIBSEMAlignmentParameters< M, S >, ZBlockFactory > col =
blockFactory.defineBlockCollection( solveParams );

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

import org.janelia.alignment.match.ModelType;
import org.janelia.render.client.newsolver.blocksolveparameters.FIBSEMAlignmentParameters.PreAlign;
import org.janelia.render.client.parameter.CommandLineParameters;
import org.janelia.render.client.parameter.RenderWebServiceParameters;
import org.janelia.render.client.solver.SerializableValuePair;
Expand All @@ -17,6 +19,7 @@
import mpicbg.models.Affine2D;
import mpicbg.models.AffineModel2D;
import mpicbg.models.InterpolatedAffineModel2D;
import mpicbg.models.Model;
import mpicbg.models.RigidModel2D;
import mpicbg.models.TranslationModel2D;

Expand Down Expand Up @@ -90,20 +93,8 @@ public SerializableValuePair<Integer, Integer> convert( final String value )
public Integer minBlockSize = 50;

//
// stitching align model, by default TRANSLATION with tunable regularization --- with RIGID (default: 0.00)
// stitching align model, by TRANSLATION with tunable regularization --- with RIGID (default: 0.00)
//
@Parameter(
names = "--modelTypeStitching",
description = "Type of transformation model for section stitching (default: Translation2D)"
)
public ModelType modelTypeStitching = ModelType.TRANSLATION;

@Parameter(
names = "--modelTypeStitchingRegularizer",
description = "Type of transformation model for regularization for section stitching (default: Rigid2D)"
)
public ModelType modelTypeStitchingRegularizer = ModelType.RIGID;

@Parameter(
names = "--lambdaStitching",
description = "Lambda, used if modelTypeStitchingRegularizer is not null."
Expand Down Expand Up @@ -145,6 +136,13 @@ public SerializableValuePair<Integer, Integer> convert( final String value )
// models are hardcoded: AFFINE, regularized with RIGID, regularized with Translation, regularized with RegularizingModel (Constant or Stabilizing)
// and a set of decreasing lambdas (see below)
//

@Parameter(
names = "--preAlign",
description = "Type of pre-alignment used: NONE, TRANSLATION, RIGID. Note: if you use 'stitchFirst' you must specify TRANSLATION or RIGID (default: none)"
)
public PreAlign preAlign = PreAlign.NONE;

@Parameter(
names = "--blockOptimizerLambdasRigid",
description = "Explicit optimizer lambda values for the rigid regularizer, by default optimizer loops through lambdas (1.0,0.5,0.1,0.01)",
Expand Down Expand Up @@ -260,7 +258,6 @@ public InterpolatedAffineModel2D<InterpolatedAffineModel2D< InterpolatedAffineMo
this.blockOptimizerLambdasTranslation.size() != this.blockOptimizerLambdasRigid.size())
throw new RuntimeException( "Number of entries for blockOptimizerIterations, blockMaxPlateauWidth, blockOptimizerLambdasTranslation and blockOptimizerLambdasRigid not identical." );


return new InterpolatedAffineModel2D<InterpolatedAffineModel2D< InterpolatedAffineModel2D< AffineModel2D, RigidModel2D >, TranslationModel2D >, StabilizingAffineModel2D<RigidModel2D>>(
new InterpolatedAffineModel2D< InterpolatedAffineModel2D< AffineModel2D, RigidModel2D >, TranslationModel2D >(
new InterpolatedAffineModel2D< AffineModel2D, RigidModel2D >(
Expand All @@ -272,11 +269,8 @@ public InterpolatedAffineModel2D<InterpolatedAffineModel2D< InterpolatedAffineMo
//new ConstantAffineModel2D( stitchingModel() ), 0.0 );
}

public Affine2D< ? > stitchingModel()
public InterpolatedAffineModel2D<TranslationModel2D, RigidModel2D> stitchingModel()
{
if ( this.modelTypeStitchingRegularizer == null )
return this.modelTypeStitching.getInstance();
else
return this.modelTypeStitching.getInterpolatedInstance( modelTypeStitchingRegularizer, lambdaStitching );
return new InterpolatedAffineModel2D<TranslationModel2D, RigidModel2D>( new TranslationModel2D(), new RigidModel2D(), lambdaStitching );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public AffineAlignBlockWorker(
this.matchFilter = new RandomMaxAmountFilter( blockData.solveTypeParameters().maxNumMatches() );

// used locally
this.stitchFirst = blockData.solveTypeParameters().minStitchingInliersSupplier() != null;
this.stitchFirst = blockData.solveTypeParameters().minStitchingInliersSupplier() != null && blockData.solveTypeParameters().stitchingModelSupplier() != null;
this.pairs = new ArrayList<>();
this.zToPairs = new HashMap<>();

Expand Down

0 comments on commit 53a8517

Please sign in to comment.