NHPatterson / wsireg

multimodal whole slide image registration in a graph structure
MIT License
76 stars 7 forks source link

error on napari plugin #56

Closed alcrevenna closed 2 years ago

alcrevenna commented 2 years ago

Thanks for the great tool!

Description

Hi I just downloaded and installed napari, wsireg and the wsinapari plugin. I had successfully ran things in linux, now I'm on my mac get an error that cannot write registered images. I load three tiffs (each with 5 channels), single plane no 3D.

What I Did

I loaded my images on napari plugin, defined registrations (rigid->affine->nl) and added the registration graphs. Ticked box "write transformed images" Clicked run graph, got the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File /opt/anaconda3/envs/nap_wreg/lib/python3.9/site-packages/superqt/utils/_qthreading.py:616, in create_worker..reraise(e=TypeError("main() got an unexpected keyword argument 'write_images'"))
    615 def reraise(e):
--> 616     raise e
        e = TypeError("main() got an unexpected keyword argument 'write_images'")

File /opt/anaconda3/envs/nap_wreg/lib/python3.9/site-packages/superqt/utils/_qthreading.py:176, in WorkerBase.run(self=)
    174     warnings.filterwarnings("always")
    175     warnings.showwarning = lambda *w: self.warned.emit(w)
--> 176     result = self.work()
        self = 
    177 if isinstance(result, Exception):
    178     if isinstance(result, RuntimeError):
    179         # The Worker object has likely been deleted.
    180         # A deleted wrapped C/C++ object may result in a runtime
    181         # error that will cause segfault if we try to do much other
    182         # than simply notify the user.

File /opt/anaconda3/envs/nap_wreg/lib/python3.9/site-packages/superqt/utils/_qthreading.py:356, in FunctionWorker.work(self=)
    355 def work(self) -> _R:
--> 356     return self._func(*self._args, **self._kwargs)
        self._func = 
        self = 
        self._args = (, , {'write_images': True, 'to_original_size': False, 'transform_non_reg': True, 'remove_merged': True})
        self._kwargs = {}

File /opt/anaconda3/envs/nap_wreg/lib/python3.9/site-packages/napari_wsireg/_widget.py:1585, in WsiReg2DMain._run_registration(self=, reg_graph=, reg_opts={'remove_merged': True, 'to_original_size': False, 'transform_non_reg': True, 'write_images': True})
   1581 @thread_worker
   1582 def _run_registration(
   1583     self, reg_graph: WsiReg2D, reg_opts: dict
   1584 ) -> Tuple[List[str], WsiReg2D]:
-> 1585     output_data = wsireg2d_main(reg_graph, **reg_opts)
        wsireg2d_main = 
        reg_graph = 
        reg_opts = {'write_images': True, 'to_original_size': False, 'transform_non_reg': True, 'remove_merged': True}
   1586     return output_data, reg_graph

TypeError: main() got an unexpected keyword argument 'write_images'
NHPatterson commented 2 years ago

Ah yes, sorry I have a little lag between a breaking change in wsireg and napari-wsireg. I will update in the next 30 minutes and hopefully it will be up and running for you.

NHPatterson commented 2 years ago

There's a hold up with some dependencies that should resolve soon. You should be able to fix this by doing the following in your conda environment:

pip uninstall wsireg
pip install wsireg==0.3.5
alcrevenna commented 2 years ago

Hi, I did that (wsireg=0.3.5) and got started the run, then got this error:

Resolution: 9
WARNING: The parameter "ShowExactMetricValue", requested at entry number 9, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "CheckNumberOfSamples", requested at entry number 9, does not exist at all.
  The default value "true" is used instead.
WARNING: The parameter "UseMultiThreadingForMetrics", requested at entry number 9, does not exist at all.
  The default value "true" is used instead.
Setting the fixed masks took: 0 ms.
Setting the moving masks took: 0 ms.
WARNING: The parameter "NumberOfFixedHistogramBins", requested at entry number 9, does not exist at all.
  The default value "32" is used instead.
WARNING: The parameter "NumberOfMovingHistogramBins", requested at entry number 9, does not exist at all.
  The default value "32" is used instead.
WARNING: The parameter "FixedLimitRangeRatio", requested at entry number 9, does not exist at all.
  The default value "0.01" is used instead.
WARNING: The parameter "MovingLimitRangeRatio", requested at entry number 9, does not exist at all.
  The default value "0.01" is used instead.
WARNING: The parameter "FixedKernelBSplineOrder", requested at entry number 9, does not exist at all.
  The default value "0" is used instead.
WARNING: The parameter "MovingKernelBSplineOrder", requested at entry number 9, does not exist at all.
  The default value "3" is used instead.
WARNING: The parameter "UseFastAndLowMemoryVersion", requested at entry number 9, does not exist at all.
  The default value "true" is used instead.
WARNING: The parameter "UseJacobianPreconditioning", requested at entry number 9, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "FiniteDifferenceDerivative", requested at entry number 9, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "SP_A", requested at entry number 9, does not exist at all.
  The default value "20" is used instead.

WARNING: You have set MaximumNumberOfSamplingAttempts to 10.
  This functionality is known to cause problems (stack overflow) for large values.
  If elastix stops or segfaults for no obvious reason, reduce this value.
  You may select the RandomSparseMask image sampler to fix mask-related problems.

WARNING: The parameter "SigmoidInitialTime", requested at entry number 9, does not exist at all.
  The default value "0" is used instead.
WARNING: The parameter "MaxBandCovSize", requested at entry number 9, does not exist at all.
  The default value "192" is used instead.
WARNING: The parameter "NumberOfBandStructureSamples", requested at entry number 9, does not exist at all.
  The default value "10" is used instead.
WARNING: The parameter "UseAdaptiveStepSizes", requested at entry number 9, does not exist at all.
  The default value "true" is used instead.
WARNING: The parameter "AutomaticParameterEstimation", requested at entry number 9, does not exist at all.
  The default value "true" is used instead.
WARNING: The parameter "UseConstantStep", requested at entry number 9, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "MaximumStepLengthRatio", requested at entry number 9, does not exist at all.
  The default value "1" is used instead.
WARNING: The parameter "NumberOfGradientMeasurements", requested at entry number 9, does not exist at all.
  The default value "0" is used instead.
WARNING: The parameter "NumberOfJacobianMeasurements", requested at entry number 9, does not exist at all.
  The default value "4048" is used instead.
WARNING: The parameter "NumberOfSamplesForExactGradient", requested at entry number 9, does not exist at all.
  The default value "100000" is used instead.
WARNING: The parameter "SigmoidScaleFactor", requested at entry number 9, does not exist at all.
  The default value "0.1" is used instead.
Elastix initialization of all components (for this resolution) took: 30 ms.
  Computing the fixed image extrema took 210 ms.
  Computing the moving image extrema took 218 ms.
Initialization of AdvancedMattesMutualInformation metric took: 430 ms.
Starting automatic parameter estimation for AdaptiveStochasticGradientDescent ...
WARNING: The parameter "ASGDParameterEstimationMethod", requested at entry number 0, does not exist at all.
  The default value "Original" is used instead.
  Computing JacobianTerms ...
  Computing the Jacobian terms took 0.033879s
  NumberOfGradientMeasurements to estimate sigma_i: 2
  Sampling gradients ...
  Sampling the gradients took 0.103196s
Automatic parameter estimation took 0.14s
1:ItNr  2:Metric    3a:Time 3b:StepSize 4:||Gradient||  Time[ms]
0   -1.054607   0.000000    6737.480043 0.002241    584.0
1   -1.069401   0.000000    6737.480043 0.002056    23.6
2   -1.072613   1.000000    6431.230950 0.002061    21.0
...
197 -1.062716   149.258622  831.012719  0.001676    23.5
198 -1.069678   150.248150  826.210855  0.001785    22.3
199 -1.072099   151.248129  821.414325  0.001858    23.4
Time spent in resolution 9 (ITK initialization and iterating): 5.067 s.
Stopping condition: Maximum number of iterations has been reached.
Settings of AdaptiveStochasticGradientDescent in resolution 9:
( SP_a 141487.080894 )
( SP_A 20.000000 )
( SP_alpha 1.000000 )
( SigmoidMax 1.000000 )
( SigmoidMin -0.624656 )
( SigmoidScale 0.000000 )

Creating the TransformParameterFile took 0.00s

Registration result checksum: 262648637

Final metric value  = -1.072099
Settings of AdaptiveStochasticGradientDescent for all resolutions:
( SP_a 1373150.522647 643567.922778 334771.892795 170529.071258 202153.174975 120075.423254 192508.293225 660887.891827 89393.735687 141487.080894 )
( SP_A 20.000000 20.000000 20.000000 20.000000 20.000000 20.000000 20.000000 20.000000 20.000000 20.000000 )
( SP_alpha 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 )
( SigmoidMax 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 )
( SigmoidMin -0.010432 -0.010172 -0.010322 -0.010255 -0.010735 -0.010983 -0.020567 -0.104469 -0.175892 -0.624656 )
( SigmoidScale 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 )

Time spent on saving the results, applying the final transform etc.: 9 ms.
Segmentation fault: 11
NHPatterson commented 2 years ago

Ah.. unfortunately this is likely an out of memory error that is happening during registration. wsireg defaults to using the entire XY plane for registration and this can consume a lot of memory for two images. Can you go to spatial preprocessing and set "downsample" to 2 or 4 (see below)? This will downsample the images for registration only, outputs will still be at high resolution. Any change in registration quality is marginal.

Where to set downsampling (may appear different in Windows):

image

You can set this for all your images and it will definitely decrease memory consumption.

alcrevenna commented 2 years ago

Thank you! That works like a charm now.