|
17 | 17 | import java.util.List; |
18 | 18 | import java.util.Map; |
19 | 19 |
|
| 20 | +import javax.management.RuntimeErrorException; |
20 | 21 | import javax.swing.JDialog; |
21 | 22 | import javax.swing.JProgressBar; |
22 | 23 | import javax.swing.WindowConstants; |
@@ -69,7 +70,7 @@ public class CellposeAppose extends DynamicCommand implements Initializable |
69 | 70 | "neurips_cellpose_transformer"}, description="Choose CP model to run") |
70 | 71 | private String cp_model = "cyto3"; // cellpose model |
71 | 72 |
|
72 | | - @Parameter(label = "Custom model", description = "Custom model path, overrides the Cellpose model", style="file", required = false) |
| 73 | + @Parameter(label = "Custom model", description = "Custom model path, overrides the Cellpose model", style="file", required = false, validater = "validateCustomModel") |
73 | 74 | private File custom_model = null; |
74 | 75 |
|
75 | 76 | @Parameter( label = "Diameter", min="0", description="Average diameter of a cell/nuclei (in pixels)" ) |
@@ -324,7 +325,9 @@ public < T extends RealType< T > & NativeType< T > > void process( final ImagePl |
324 | 325 | final Map< String, Object > inputs = new HashMap<>(); |
325 | 326 | inputs.put( "image", NDArrays.asNDArray( img ) ); |
326 | 327 | inputs.put( "use_3D", use3d ); |
327 | | - inputs.put( "model", cp_model ); |
| 328 | + // return null if custom model |
| 329 | + inputs.put( "model", ( custom_model == null ) ? cp_model : null ); |
| 330 | + inputs.put( "custom_model", ( custom_model == null ) ? null : custom_model.toString() ); |
328 | 331 | inputs.put( "diameter", cell_diameter ); |
329 | 332 | inputs.put( "cell_channel", parseChannelChoice( cyto_channel ) ); |
330 | 333 | inputs.put( "nuclei_channel", parseChannelChoice( nuclei_channel )); |
@@ -583,5 +586,14 @@ public static Integer parseChannelChoice(String str) { |
583 | 586 | return Integer.parseInt(str); |
584 | 587 | } |
585 | 588 |
|
| 589 | + public void validateCustomModel() { |
| 590 | + if ( custom_model != null) { |
| 591 | + if ( ! custom_model.exists() ) { |
| 592 | + IJ.error("The path " + custom_model.toString() + " does not exist !"); |
| 593 | + throw new RuntimeException("The path " + custom_model.toString() + " does not exist !"); |
| 594 | + } |
| 595 | + } |
| 596 | + } |
| 597 | + |
586 | 598 |
|
587 | 599 | } |
0 commit comments