Получаете ошибку ограничивающей рамки для Nilearn CanICA? - PullRequest
0 голосов
/ 06 августа 2020

Я работаю с изображениями фМРТ и использую модуль CanICA от Nilearn для завершения извлечения признаков. Мой набор данных состоит из 670 изображений. Однако, когда я пытаюсь запустить программу, я получаю следующую ошибку:

BoundingBoxError: The field of view given by the target affine does not contain any of the data

Я попытался открыть свои файлы с помощью программы просмотра файлов NifTI, и это сработало. Поэтому я не уверен, почему возникает эта ошибка. Какие-нибудь советы? Вот код, который я использую:

import os
import pandas as pd
import re
 
 
# initialize array to empty
dataset = []
 
# traverse directory tree and return files in each director
# dp: folder path,
# dn: sub folders, 
# files: files in directory(directory is same as folder)
 
cnt=0
for dp, dn, files in os.walk('/content/drive/My Drive/ABIDE/REST'):
  #/content/drive/My Drive/abide_files/CMU_a_0050642_rest.nii.gz
    cnt=cnt+1
    for f in files:
        if (f.endswith("_rest.nii")): # if file has extension rest.nii.gz, add it to array
            dataset.append(os.path.join(dp, f))

print (dataset) 
print("Num Files", len(dataset))

!pip install nilearn
import nilearn
from nilearn.decomposition import CanICA
 
canica = CanICA(n_components=20,
                memory="nilearn_cache", memory_level=2,
                verbose=10,
                mask_strategy='template',
                random_state=0)
icadataset = []
for f in dataset:
  canica.fit(f)
  canica_components_img = canica.components_img_
  dir=os.path.dirname(f)
  fn=os.path.basename(f)
  fs1 = fn.replace("_rest.nii", "_ica.nii")  
  newfn=dir+"/"+fs1
  print (newfn)
  f1 = canica_components_img.to_filename(newfn)
  #icadataset.append(f1)

И вот отзыв:

BoundingBoxError                          Traceback (most recent call last)
<ipython-input-9-ffaede9e41ae> in <module>()
     10 icadataset = []
     11 for f in dataset:
---> 12   canica.fit(f)
     13   canica_components_img = canica.components_img_
     14   dir=os.path.dirname(f)

11 frames
/usr/local/lib/python3.6/dist-packages/nilearn/decomposition/base.py in fit(self, imgs, y, confounds)
    394         # if masker_ has been provided a mask_img
    395         if self.masker_.mask_img is None:
--> 396             self.masker_.fit(imgs)
    397         else:
    398             self.masker_.fit()

/usr/local/lib/python3.6/dist-packages/nilearn/input_data/multi_nifti_masker.py in fit(self, imgs, y)
    206                     memory=self.memory,
    207                     verbose=max(0, self.verbose - 1),
--> 208                     **mask_args)
    209         else:
    210             if imgs is not None:

/usr/local/lib/python3.6/dist-packages/joblib/memory.py in __call__(self, *args, **kwargs)
    563 
    564     def __call__(self, *args, **kwargs):
--> 565         return self._cached_call(args, kwargs)[0]
    566 
    567     def __getstate__(self):

/usr/local/lib/python3.6/dist-packages/joblib/memory.py in _cached_call(self, args, kwargs, shelving)
    529 
    530         if must_call:
--> 531             out, metadata = self.call(*args, **kwargs)
    532             if self.mmap_mode is not None:
    533                 # Memmap the output at the first call to be consistent with

/usr/local/lib/python3.6/dist-packages/joblib/memory.py in call(self, *args, **kwargs)
    725         if self._verbose > 0:
    726             print(format_call(self.func, args, kwargs))
--> 727         output = self.func(*args, **kwargs)
    728         self.store_backend.dump_item(
    729             [func_id, args_id], output, verbose=self._verbose)

/usr/local/lib/python3.6/dist-packages/nilearn/masking.py in compute_multi_gray_matter_mask(target_imgs, threshold, connected, opening, memory, verbose, n_jobs, **kwargs)
    657     mask = compute_gray_matter_mask(target_imgs[0], threshold=threshold,
    658                                     connected=connected, opening=opening,
--> 659                                     memory=memory, verbose=verbose)
    660     return mask
    661 

/usr/local/lib/python3.6/dist-packages/nilearn/masking.py in compute_gray_matter_mask(target_img, threshold, connected, opening, memory, verbose)
    575 
    576     from .image.resampling import resample_to_img
--> 577     resampled_template = cache(resample_to_img, memory)(template, target_img)
    578 
    579     mask = get_data(resampled_template) >= threshold

/usr/local/lib/python3.6/dist-packages/joblib/memory.py in __call__(self, *args, **kwargs)
    563 
    564     def __call__(self, *args, **kwargs):
--> 565         return self._cached_call(args, kwargs)[0]
    566 
    567     def __getstate__(self):

/usr/local/lib/python3.6/dist-packages/joblib/memory.py in _cached_call(self, args, kwargs, shelving)
    529 
    530         if must_call:
--> 531             out, metadata = self.call(*args, **kwargs)
    532             if self.mmap_mode is not None:
    533                 # Memmap the output at the first call to be consistent with

/usr/local/lib/python3.6/dist-packages/joblib/memory.py in call(self, *args, **kwargs)
    725         if self._verbose > 0:
    726             print(format_call(self.func, args, kwargs))
--> 727         output = self.func(*args, **kwargs)
    728         self.store_backend.dump_item(
    729             [func_id, args_id], output, verbose=self._verbose)

/usr/local/lib/python3.6/dist-packages/nilearn/image/resampling.py in resample_to_img(source_img, target_img, interpolation, copy, order, clip, fill_value, force_resample)
    662                         interpolation=interpolation, copy=copy, order=order,
    663                         clip=clip, fill_value=fill_value,
--> 664                         force_resample=force_resample)
    665 
    666 

/usr/local/lib/python3.6/dist-packages/nilearn/image/resampling.py in resample_img(img, target_affine, target_shape, interpolation, copy, order, clip, fill_value, force_resample)
    483     # of the target affine
    484     if xmax < 0 or ymax < 0 or zmax < 0:
--> 485         raise BoundingBoxError("The field of view given "
    486                                "by the target affine does "
    487                                "not contain any of the data")

BoundingBoxError: The field of view given by the target affine does not contain any of the data

Дополнительная информация: Tensorflow 2.2.0

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...