diff --git a/nipreps/synthstrip/model.py b/nipreps/synthstrip/model.py index 3081d2d..74eba9c 100644 --- a/nipreps/synthstrip/model.py +++ b/nipreps/synthstrip/model.py @@ -89,7 +89,7 @@ def __init__( max_pool = [max_pool] * self.nb_levels # cache downsampling / upsampling operations - MaxPooling = getattr(nn, 'MaxPool%dd' % ndims) + MaxPooling = getattr(nn, f'MaxPool{ndims}d') self.pooling = [MaxPooling(s) for s in max_pool] self.upsampling = [nn.Upsample(scale_factor=s, mode='nearest') for s in max_pool] @@ -164,7 +164,7 @@ class ConvBlock(nn.Module): def __init__(self, ndims, in_channels, out_channels, stride=1, activation='leaky'): super().__init__() - Conv = getattr(nn, 'Conv%dd' % ndims) + Conv = getattr(nn, f'Conv{ndims}d') self.conv = Conv(in_channels, out_channels, 3, stride, 1) if activation == 'leaky': self.activation = nn.LeakyReLU(0.2) diff --git a/nipreps/synthstrip/wrappers/nipype.py b/nipreps/synthstrip/wrappers/nipype.py index 2362916..6fe2d85 100644 --- a/nipreps/synthstrip/wrappers/nipype.py +++ b/nipreps/synthstrip/wrappers/nipype.py @@ -23,6 +23,7 @@ """SynthStrip interface.""" import os +from contextlib import suppress from pathlib import Path from nipype.interfaces.base import ( @@ -37,8 +38,10 @@ _fs_home = os.getenv('FREESURFER_HOME', None) _default_model_path = Path(_fs_home) / 'models' / 'synthstrip.1.pt' if _fs_home else Undefined -if _fs_home and not _default_model_path.exists(): - _default_model_path = Undefined +use_defaultmodel = False +with suppress(AttributeError): + use_defaultmodel = _default_model_path.exists() + _default_model_path = str(_default_model_path) class _SynthStripInputSpec(CommandLineInputSpec): @@ -50,8 +53,8 @@ class _SynthStripInputSpec(CommandLineInputSpec): ) use_gpu = traits.Bool(False, usedefault=True, argstr='-g', desc='Use GPU', nohash=True) model = File( - str(_default_model_path), - usedefault=True, + _default_model_path, + usedefault=use_defaultmodel, exists=True, argstr='--model %s', desc="file containing model's weights",