Skip to content

Commit

Permalink
reorganize tiling so it lays inside the bioimageio package
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Sep 24, 2024
1 parent 568aa53 commit 28e020a
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.bioimage.modelrunner.bioimageio;
package io.bioimage.modelrunner.bioimageio.tiling;

public class ImageInfo {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
* #L%
*/
package io.bioimage.modelrunner.tiling;
package io.bioimage.modelrunner.bioimageio.tiling;

import java.util.stream.LongStream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
* limitations under the License.
* #L%
*/
package io.bioimage.modelrunner.tiling;
package io.bioimage.modelrunner.bioimageio.tiling;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
* Patch specification providing information about the patch size and patch grid size.
Expand Down Expand Up @@ -69,7 +68,7 @@ public class PatchSpec
* The original size of the image/tensor that is going to be tiled
* @return The create patch specification.
*/
public static PatchSpec create(String tensorName, long[] patchInputSize, int[] patchGridSize,
protected static PatchSpec create(String tensorName, long[] patchInputSize, int[] patchGridSize,
int[][] patchPaddingSize, long[] nonTiledTensorDims)
{
PatchSpec ps = new PatchSpec();
Expand All @@ -85,38 +84,26 @@ private PatchSpec()
{
}

/**
* Return the PatchSpec corresponding to the tensor called by the name defined
* @param specs
* list of patch specs
* @param name
* name of the tensor of interest
* @return the patch specs of the tensor if interest
*/
public static PatchSpec getPatchSpecFromListByName(List<PatchSpec> specs, String name) {
return specs.stream().filter(pp -> pp.getTensorName().equals(name)).findAny().orElse(null);
}

/**
* GEt the name of the tensor
* @return the name of the tensor
*/
public String getTensorName() {
protected String getTensorName() {
return tensorName;
}

/**
* The dimensions of the tensor
* @return the dimensions of the tensor that is going to be tiled
*/
public long[] getNonTiledTensorDims() {
protected long[] getNonTiledTensorDims() {
return nonTiledTensorDims;
}

/**
* @return Input patch size. The patch taken from the input sequence including the halo.
*/
public long[] getTileSize()
protected long[] getTileSize()
{
return patchInputSize;
}
Expand All @@ -125,15 +112,15 @@ public long[] getTileSize()
* @return The patch grid size. The number of patches in each axis used to cover the entire sequence. It should be computed from the output patch and input
* sequence sizes.
*/
public int[] getTileGrid()
protected int[] getTileGrid()
{
return patchGridSize;
}

/**
* @return The padding size used on each patch.
*/
public int[][] getPadding()
protected int[][] getPadding()
{
return patchPaddingSize;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.bioimage.modelrunner.bioimageio;
package io.bioimage.modelrunner.bioimageio.tiling;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -12,7 +12,7 @@
import io.bioimage.modelrunner.bioimageio.description.Axis;
import io.bioimage.modelrunner.bioimageio.description.ModelDescriptor;
import io.bioimage.modelrunner.bioimageio.description.TensorSpec;
import io.bioimage.modelrunner.tiling.TileInfo;
import io.bioimage.modelrunner.bioimageio.tiling.TileInfo;
import io.bioimage.modelrunner.utils.Constants;

public class TileCalculator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
* #L%
*/
package io.bioimage.modelrunner.tiling;
package io.bioimage.modelrunner.bioimageio.tiling;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -81,7 +81,7 @@ private TileGrid()
* @return an instance of {@link TileGrid} that contains the information about where the tiles need to be
* positioned with respect to the original image
*/
public static TileGrid create(PatchSpec tileSpecs)
protected static TileGrid create(PatchSpec tileSpecs)
{
TileGrid ps = new TileGrid();
ps.tensorName = tileSpecs.getTensorName();
Expand Down Expand Up @@ -114,23 +114,23 @@ public static TileGrid create(PatchSpec tileSpecs)
*
* @return name of the tensor that is going to be processed
*/
public String getTensorName() {
protected String getTensorName() {
return tensorName;
}

/**
*
* @return size of the tile that is going to be used to process the image
*/
public long[] getTileSize() {
protected long[] getTileSize() {
return this.tileSize;
}

/**
*
* @return size of the roi of each of the tiles that is going to be used to process the image
*/
public int[] getRoiSize() {
protected int[] getRoiSize() {
return this.roiSize;
}

Expand All @@ -140,15 +140,15 @@ public int[] getRoiSize() {
* respect to the original image of the tensor.
* The positions might be negative as the image that is going to be processed might have padding on the edges
*/
public List<long[]> getTilePostionsInImage() {
protected List<long[]> getTilePostionsInImage() {
return this.tilePostionsInImage;
}

/**
*
* @return the positions of the roi in each of the tiles that are going to be used
*/
public List<long[]> getRoiPositionsInTile() {
protected List<long[]> getRoiPositionsInTile() {
return this.roiPositionsInTile;
}

Expand All @@ -157,7 +157,7 @@ public List<long[]> getRoiPositionsInTile() {
* @return the positions of the roi of each of the tiles in the original image. Where the ROIs are
* inserted on the original image.
*/
public List<long[]> getRoiPostionsInImage() {
protected List<long[]> getRoiPostionsInImage() {
return this.roiPositionsInImage;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.bioimage.modelrunner.tiling;
package io.bioimage.modelrunner.bioimageio.tiling;

public class TileInfo {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.bioimage.modelrunner.tiling;
package io.bioimage.modelrunner.bioimageio.tiling;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/io/bioimage/modelrunner/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@
import java.net.MalformedURLException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

import io.bioimage.modelrunner.bioimageio.ImageInfo;
import io.bioimage.modelrunner.bioimageio.TileCalculator;
import io.bioimage.modelrunner.bioimageio.tiling.ImageInfo;
import io.bioimage.modelrunner.bioimageio.tiling.TileCalculator;
import io.bioimage.modelrunner.bioimageio.bioengine.BioEngineAvailableModels;
import io.bioimage.modelrunner.bioimageio.bioengine.BioengineInterface;
import io.bioimage.modelrunner.bioimageio.description.ModelDescriptor;
Expand All @@ -46,27 +43,24 @@
import io.bioimage.modelrunner.bioimageio.description.exceptions.ModelSpecsException;
import io.bioimage.modelrunner.bioimageio.description.weights.ModelWeight;
import io.bioimage.modelrunner.bioimageio.description.weights.WeightFormat;
import io.bioimage.modelrunner.bioimageio.tiling.PatchSpec;
import io.bioimage.modelrunner.bioimageio.tiling.TileGrid;
import io.bioimage.modelrunner.bioimageio.tiling.TileInfo;
import io.bioimage.modelrunner.bioimageio.tiling.TileMaker;
import io.bioimage.modelrunner.engine.DeepLearningEngineInterface;
import io.bioimage.modelrunner.engine.EngineInfo;
import io.bioimage.modelrunner.engine.EngineLoader;
import io.bioimage.modelrunner.exceptions.LoadEngineException;
import io.bioimage.modelrunner.exceptions.LoadModelException;
import io.bioimage.modelrunner.exceptions.RunModelException;
import io.bioimage.modelrunner.tensor.Tensor;
import io.bioimage.modelrunner.tiling.PatchSpec;
import io.bioimage.modelrunner.tiling.TileGrid;
import io.bioimage.modelrunner.tiling.TileInfo;
import io.bioimage.modelrunner.tiling.TileMaker;
import io.bioimage.modelrunner.utils.Constants;
import io.bioimage.modelrunner.versionmanagement.InstalledEngines;
import net.imglib2.FinalInterval;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.Img;
import net.imglib2.img.array.ArrayImgs;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.view.Views;

/**
* Class that manages a Deep Learning model to load it and run it.
Expand Down

0 comments on commit 28e020a

Please sign in to comment.