Skip to content

FIX: The commandline is set --model <undefined> #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nipreps/synthstrip/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions nipreps/synthstrip/wrappers/nipype.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""SynthStrip interface."""

import os
from contextlib import suppress
from pathlib import Path

from nipype.interfaces.base import (
Expand All @@ -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):
Expand All @@ -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",
Expand Down