Closed kencan7749 closed 1 month ago
It works just by modifying these lines https://github.com/KamitaniLab/bdpy/blob/b6179eab45f9142f568dab565ab02f82993f876a/bdpy/ml/learning.py#L555-L577 to these:
elif self.model_format == 'bdmodel':
if os.path.isfile(self.model_path):
raise ValueError('BDmodel should be specified as a directory, not a file')
# W: shape = (n_voxels, shape_features)
if os.path.isdir(os.path.join(self.model_path, 'W')):
model_path = self.model_path.replace('[', '[[]')
W_files = sorted(glob.glob(os.path.join(model_path, 'W', '*.mat')))
elif os.path.isfile(os.path.join(self.model_path, 'W.mat')):
W_files = [os.path.join(self.model_path, 'W.mat')]
else:
raise RuntimeError('W not found.')
# b: shape = (1, shape_features)
if os.path.isdir(os.path.join(self.model_path, 'b')):
model_path = self.model_path.replace('[', '[[]')
b_files = sorted(glob.glob(os.path.join(model_path, 'b', '*.mat')))
elif os.path.isfile(os.path.join(self.model_path, 'b.mat')):
b_files = [os.path.join(self.model_path, 'b.mat')]
else:
raise RuntimeError('b not found.')
model_files = [(w, b) for w, b in zip(W_files, b_files)]
else
The differences are https://github.com/KamitaniLab/bdpy/blob/b6179eab45f9142f568dab565ab02f82993f876a/bdpy/ml/learning.py#L561 and
https://github.com/KamitaniLab/bdpy/blob/b6179eab45f9142f568dab565ab02f82993f876a/bdpy/ml/learning.py#L569, allowing special character by replacing "[" into "[[]".
BTW, we can consider replacing glob.escape
instead.
When I predicted the feature such as
features[34]
from brain activity, I encountered an error.I identified the cause as the directory containing special characters ("[", "]"). I want to deal it with the same way as
Features
class in bdpy. I'd like to ask you to add this line https://github.com/KamitaniLab/bdpy/blob/b6179eab45f9142f568dab565ab02f82993f876a/bdpy/dataform/features.py#L281 here around https://github.com/KamitaniLab/bdpy/blob/b6179eab45f9142f568dab565ab02f82993f876a/bdpy/ml/learning.py#L552.