Skip to content

Commit

Permalink
refactor variable and change models order
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Oct 4, 2024
1 parent b56dc92 commit ff0352b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions src/main/java/ai/nets/samj/communication/model/SAM2Tiny.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*/
public class SAM2Tiny implements SAMModel {

private Sam2 efficientSamJ;
private Sam2 samj;
private final SamEnvManagerAbstract manager;
private SAMJLogger log;
private Boolean installed = false;
Expand Down Expand Up @@ -115,10 +115,10 @@ public void setImage(final RandomAccessibleInterval<?> image, final SAMJLogger u
if (idx > 0) this.log.info( text.substring(0,idx) );
else this.log.info( text );
};
if (this.efficientSamJ == null)
efficientSamJ = Sam2.initializeSam("tiny", manager, filteringLogger, false);
if (this.samj == null)
samj = Sam2.initializeSam("tiny", manager, filteringLogger, false);
try {
this.efficientSamJ.setImage(Cast.unchecked(image));;
this.samj.setImage(Cast.unchecked(image));;
} catch (IOException | InterruptedException | RuntimeException e) {
log.error(FULL_NAME + " experienced an error: " + e.getMessage());
throw e;
Expand All @@ -144,8 +144,8 @@ public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
List<int[]> negList = listOfNegPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
if (negList.size() == 0) return efficientSamJ.processPoints(list, !onlyBiggest);
else return efficientSamJ.processPoints(list, negList, !onlyBiggest);
if (negList.size() == 0) return samj.processPoints(list, !onlyBiggest);
else return samj.processPoints(list, negList, !onlyBiggest);
} catch (IOException | RuntimeException | InterruptedException e) {
log.error(FULL_NAME+", providing empty result because of some trouble: "+e.getMessage());
throw e;
Expand All @@ -163,8 +163,8 @@ public List<Polygon> fetch2dSegmentation(List<Localizable> listOfPoints2D, List<
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
List<int[]> negList = listOfNegPoints2D.stream()
.map(i -> new int[] {(int) i.positionAsDoubleArray()[0], (int) i.positionAsDoubleArray()[1]}).collect(Collectors.toList());
if (negList.size() == 0) return efficientSamJ.processPoints(list, zoomedRectangle, !onlyBiggest);
else return efficientSamJ.processPoints(list, negList, zoomedRectangle, !onlyBiggest);
if (negList.size() == 0) return samj.processPoints(list, zoomedRectangle, !onlyBiggest);
else return samj.processPoints(list, negList, zoomedRectangle, !onlyBiggest);
} catch (IOException | RuntimeException | InterruptedException e) {
log.error(FULL_NAME+", providing empty result because of some trouble: "+e.getMessage());
throw e;
Expand All @@ -185,7 +185,7 @@ public List<Polygon> fetch2dSegmentation(Interval boundingBox2D)
(int)boundingBox2D.max(0),
(int)boundingBox2D.max(1)
};
return efficientSamJ.processBox(bbox, !onlyBiggest);
return samj.processBox(bbox, !onlyBiggest);
} catch (IOException | InterruptedException | RuntimeException e) {
log.error(FULL_NAME+", providing empty result because of some trouble: "+e.getMessage());
throw e;
Expand All @@ -199,7 +199,7 @@ public List<Polygon> fetch2dSegmentation(Interval boundingBox2D)
public <T extends RealType<T> & NativeType<T>> List<Polygon> fetch2dSegmentationFromMask(RandomAccessibleInterval<T> rai)
throws IOException, InterruptedException, RuntimeException {
try {
return efficientSamJ.processMask(rai, !onlyBiggest);
return samj.processMask(rai, !onlyBiggest);
} catch (IOException | InterruptedException | RuntimeException e) {
log.error(FULL_NAME+", providing empty result because of some trouble: "+e.getMessage());
throw e;
Expand All @@ -221,9 +221,9 @@ public void notifyUiHasBeenClosed() {
* {@inheritDoc}
*/
public void closeProcess() {
if (efficientSamJ != null)
efficientSamJ.close();
efficientSamJ = null;
if (samj != null)
samj.close();
samj = null;
}

@Override
Expand All @@ -242,7 +242,7 @@ public void setReturnOnlyBiggest(boolean onlyBiggest) {
@Override
public String persistEncoding() throws IOException, InterruptedException {
try {
return efficientSamJ.persistEncoding();
return samj.persistEncoding();
} catch (IOException | InterruptedException | RuntimeException e) {
log.error(FULL_NAME+", unable to persist the encoding: "+e.getMessage());
throw e;
Expand All @@ -252,7 +252,7 @@ public String persistEncoding() throws IOException, InterruptedException {
@Override
public void selectEncoding(String encodingName) throws IOException, InterruptedException {
try {
efficientSamJ.selectEncoding(encodingName);
samj.selectEncoding(encodingName);
} catch (IOException | InterruptedException | RuntimeException e) {
log.error(FULL_NAME+", unable to persist the encoding named '" + encodingName + "': "+e.getMessage());
throw e;
Expand All @@ -262,7 +262,7 @@ public void selectEncoding(String encodingName) throws IOException, InterruptedE
@Override
public void deleteEncoding(String encodingName) throws IOException, InterruptedException {
try {
efficientSamJ.deleteEncoding(encodingName);
samj.deleteEncoding(encodingName);
} catch (IOException | InterruptedException | RuntimeException e) {
log.error(FULL_NAME+", unable to delete the encoding named '" + encodingName + "': "+e.getMessage());
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public class SAMModels extends ArrayList<SAMModel> {
*/
public SAMModels() throws IOException, RuntimeException, InterruptedException {
super();
add(new EfficientSAM());
add(new SAM2Tiny());
add(new SAM2Small());
add(new EfficientSAM());
add(new SAM2Large());
add(new EfficientViTSAML2());
add(new EfficientViTSAMXL0());
Expand Down

0 comments on commit ff0352b

Please sign in to comment.