Skip to content

Commit

Permalink
add possibility of setting eps transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Nov 20, 2024
1 parent 0d75458 commit fc96c36
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,29 @@ public class BinarizeTransformation extends AbstractTensorPixelTransformation

private static String name = "binarize";
private Double threshold;
private Double eps = Math.pow(10, -6);


public BinarizeTransformation()
{
super( name );
super.setDoubleUnitaryOperator(v -> ( v >= threshold ) ? 1d : 0d);
}

public void setEps(Object eps) {
if (eps instanceof Integer) {
this.eps = Double.valueOf((int) eps);
} else if (eps instanceof Double) {
this.eps = (double) eps;
} else if (eps instanceof String) {
this.eps = Double.valueOf((String) eps);
} else {
throw new IllegalArgumentException("'eps' parameter has to be either and instance of "
+ Float.class + " or " + Double.class
+ ". The provided argument is an instance of: " + eps.getClass());
}
}

public void setThreshold(Object threshold) {
if (threshold instanceof Integer) {
this.threshold = Double.valueOf((int) threshold);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,28 @@ public class ClipTransformation extends AbstractTensorPixelTransformation
private static String name = "clip";
private Double min;
private Double max;
private double eps = Math.pow(10, -6);

public ClipTransformation()
{
super(name);
super.setDoubleUnitaryOperator(v -> v >= max ? max.doubleValue() : (v < min ? min.doubleValue() : v));
}

public void setEps(Object eps) {
if (eps instanceof Integer) {
this.eps = Double.valueOf((int) eps);
} else if (eps instanceof Double) {
this.eps = (double) eps;
} else if (eps instanceof String) {
this.eps = Double.valueOf((String) eps);
} else {
throw new IllegalArgumentException("'eps' parameter has to be either and instance of "
+ Float.class + " or " + Double.class
+ ". The provided argument is an instance of: " + eps.getClass());
}
}

public void setMin(Object min) {
if (min instanceof Integer) {
this.min = Double.valueOf((int) min);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,27 @@ public class ScaleLinearTransformation extends AbstractTensorTransformation
private double[] gainArr;
private double[] offsetArr;
private String axes;
private double eps = Math.pow(10, -6);

public ScaleLinearTransformation()
{
super( name );
}

public void setEps(Object eps) {
if (eps instanceof Integer) {
this.eps = Double.valueOf((int) eps);
} else if (eps instanceof Double) {
this.eps = (double) eps;
} else if (eps instanceof String) {
this.eps = Double.valueOf((String) eps);
} else {
throw new IllegalArgumentException("'eps' parameter has to be either and instance of "
+ Float.class + " or " + Double.class
+ ". The provided argument is an instance of: " + eps.getClass());
}
}

public void setGain(Object gain) {
if (gain instanceof Integer) {
this.gainDouble = Double.valueOf((int) gain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,27 @@ public class ScaleRangeTransformation extends AbstractTensorTransformation
private String axes;
private Mode mode = Mode.PER_SAMPLE;
private String tensorName;
private float eps = (float) Math.pow(10, -6);
private double eps = Math.pow(10, -6);

public ScaleRangeTransformation()
{
super( name );
}

public void setEps(Object eps) {
if (eps instanceof Integer) {
this.eps = Double.valueOf((int) eps);
} else if (eps instanceof Double) {
this.eps = (double) eps;
} else if (eps instanceof String) {
this.eps = Double.valueOf((String) eps);
} else {
throw new IllegalArgumentException("'eps' parameter has to be either and instance of "
+ Float.class + " or " + Double.class
+ ". The provided argument is an instance of: " + eps.getClass());
}
}

public void setMinPercentile(Object minPercentile) {
if (minPercentile instanceof Integer) {
this.minPercentile = Double.valueOf((int) minPercentile) / 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ZeroMeanUnitVarianceTransformation extends AbstractTensorTransforma
private double[] stdArr;
private Mode mode = Mode.PER_SAMPLE;
private String axes;
private float eps = (float) Math.pow(10, -6);
private double eps = Math.pow(10, -6);

private static String FIXED_MODE_ERR = "If the mode is 'fixed', the parameters 'mean' and"
+ " 'std need to be specified";
Expand All @@ -58,6 +58,20 @@ public ZeroMeanUnitVarianceTransformation()
super( name );
}

public void setEps(Object eps) {
if (eps instanceof Integer) {
this.eps = Double.valueOf((int) eps);
} else if (eps instanceof Double) {
this.eps = (double) eps;
} else if (eps instanceof String) {
this.eps = Double.valueOf((String) eps);
} else {
throw new IllegalArgumentException("'eps' parameter has to be either and instance of "
+ Float.class + " or " + Double.class
+ ". The provided argument is an instance of: " + eps.getClass());
}
}

public void setMean(Object mean) {
if (mean instanceof Integer) {
this.meanDouble = Double.valueOf((int) mean);
Expand Down

0 comments on commit fc96c36

Please sign in to comment.