KamitaniLab / bdpy

Python package for brain decoding analysis (BrainDecoderToolbox2 data format, machine learning analysis, functional MRI)
MIT License
33 stars 22 forks source link

iteration over a 0-d array #3

Closed ZaraNaSha closed 5 years ago

ZaraNaSha commented 5 years ago

Dear all when I run the End2EndDeepImageReconstruction code for test with command "$ python end2end_test.py", in bdata.py file and in "select" function i get "iteration over a 0-d array" error. i dont know how could i solve it. thanks

ShuntaroAoki commented 5 years ago

Hi, could you tell me which line in end2end_test.py caused the error?

ZaraNaSha commented 5 years ago

Hi, brain_data = fmri_data.select(fmri_data_selector) line in end2end_test.py and stack.append(np.array([n == r for n in l], dtype=bool)) line in bdata.py.

ZaraNaSha commented 5 years ago

Hi, could you tell me which line in end2end_test.py caused the error?

Hi, brain_data = fmri_data.select(fmri_data_selector) line in end2end_test.py and stack.append(np.array([n == r for n in l], dtype=bool)) line in bdata.py.

ShuntaroAoki commented 5 years ago

Thanks. It seems fmri_data_selector is invalid; the key doesn't exist in the fMRI data file. If you modified the script end2end_test.py, could you tell me the value of fmri_data_selector when it caused the error. Another possibility is corruption in fMRI data files. Could you check the file md5sum (listed below) to validate the files, or download the data files and try again?

ee503598904a4d50a7df7be0880aaadf  data/fmri/sub-01_perceptionNaturalImageTest_original_VC.h5
90ac02df511a43393bb1ab1ec45803c3  data/fmri/sub-01_perceptionNaturalImageTraining_original_VC.h5
3767c08b4b138d3114ec69cfaa8274ab  data/fmri/sub-02_perceptionNaturalImageTest_original_VC.h5
43d22acbcd84e7ec43379b020dcde392  data/fmri/sub-02_perceptionNaturalImageTraining_original_VC.h5
ffcd06aa419b1f9fbce65709a742a368  data/fmri/sub-03_perceptionNaturalImageTest_original_VC.h5
cea58d6d6b44ba51dfa3655c1edace29  data/fmri/sub-03_perceptionNaturalImageTraining_original_VC.h5
ZaraNaSha commented 5 years ago

Thanks. It seems fmri_data_selector is invalid; the key doesn't exist in the fMRI data file. If you modified the script end2end_test.py, could you tell me the value of fmri_data_selector when it caused the error. Another possibility is corruption in fMRI data files. Could you check the file md5sum (listed below) to validate the files, or download the data files and try again?

ee503598904a4d50a7df7be0880aaadf  data/fmri/sub-01_perceptionNaturalImageTest_original_VC.h5
90ac02df511a43393bb1ab1ec45803c3  data/fmri/sub-01_perceptionNaturalImageTraining_original_VC.h5
3767c08b4b138d3114ec69cfaa8274ab  data/fmri/sub-02_perceptionNaturalImageTest_original_VC.h5
43d22acbcd84e7ec43379b020dcde392  data/fmri/sub-02_perceptionNaturalImageTraining_original_VC.h5
ffcd06aa419b1f9fbce65709a742a368  data/fmri/sub-03_perceptionNaturalImageTest_original_VC.h5
cea58d6d6b44ba51dfa3655c1edace29  data/fmri/sub-03_perceptionNaturalImageTraining_original_VC.h5

thanks for your reply, I don't change the selector and use its default value in the code 'ROI_VC = 1', I check the fMRI data and they are the same as you list them. but I think the size of one of them is not correct, I will download it again and test. thanks.

ZaraNaSha commented 5 years ago

I download it again but the error is the same. ;-( image

ShuntaroAoki commented 5 years ago

Thanks. It seems there is

no problem on the data and code. I failed to replicate the error with the latest code and data files. We need some workarounds to fix the error.

Could you run the following code with pdb (as $ python -m pdb debug.py)?

debug.py:

import bdpy

test_files = ['./data/fmri/sub-01_perceptionNaturalImageTest_original_VC.h5',
              './data/fmri/sub-02_perceptionNaturalImageTest_original_VC.h5',
              './data/fmri/sub-03_perceptionNaturalImageTest_original_VC.h5']

for f in test_files:
    print(f)

    dat = bdpy.BData(f)
    a = dat.select('ROI_VC = 1')

You will see something like this:

% python -m pdb debug.py
> /home/mu/aoki/work/End2EndDeepImageReconstruction_test/debug.py(1)<module>()
-> import sys
(Pdb)

Then type c and run the script. When it gets an error it will stop like below:

(Pdb) c
./data/fmri/sub-01_perceptionNaturalImageTest_original_VC.h5
Traceback (most recent call last):
  File "/home/kujaku/libraries/python/anaconda2/lib/python2.7/pdb.py", line 1314, in main
    pdb._runscript(mainpyfile)
  File "/home/kujaku/libraries/python/anaconda2/lib/python2.7/pdb.py", line 1233, in _runscript
    self.run(statement)
  File "/home/kujaku/libraries/python/anaconda2/lib/python2.7/bdb.py", line 400, in run
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
  File "debug.py", line 1, in <module>
    import bdpy
  File "/home/kujaku/libraries/python/anaconda2/lib/python2.7/site-packages/bdpy/bdata/bdata.py", line 420, in select
    stack.append(np.array([n == r for n in l], dtype=bool))
TypeError: iteration over a 0-d array
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /home/kujaku/libraries/python/anaconda2/lib/python2.7/site-packages/bdpy/bdata/bdata.py(420)select()
-> stack.append(np.array([n == r for n in l], dtype=bool))
(Pdb)

Then, please type p condition and p expr_rpn, and let me know the outputs.

ZaraNaSha commented 5 years ago

Thanks. It seems there is

no problem on the data and code. I failed to replicate the error with the latest code and data files. We need some workarounds to fix the error.

Could you run the following code with pdb (as $ python -m pdb debug.py)?

debug.py:

import bdpy

test_files = ['./data/fmri/sub-01_perceptionNaturalImageTest_original_VC.h5',
              './data/fmri/sub-02_perceptionNaturalImageTest_original_VC.h5',
              './data/fmri/sub-03_perceptionNaturalImageTest_original_VC.h5']

for f in test_files:
    print(f)

    dat = bdpy.BData(f)
    a = dat.select('ROI_VC = 1')

You will see something like this:

% python -m pdb debug.py
> /home/mu/aoki/work/End2EndDeepImageReconstruction_test/debug.py(1)<module>()
-> import sys
(Pdb)

Then type c and run the script. When it gets an error it will stop like below:

(Pdb) c
./data/fmri/sub-01_perceptionNaturalImageTest_original_VC.h5
Traceback (most recent call last):
  File "/home/kujaku/libraries/python/anaconda2/lib/python2.7/pdb.py", line 1314, in main
    pdb._runscript(mainpyfile)
  File "/home/kujaku/libraries/python/anaconda2/lib/python2.7/pdb.py", line 1233, in _runscript
    self.run(statement)
  File "/home/kujaku/libraries/python/anaconda2/lib/python2.7/bdb.py", line 400, in run
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
  File "debug.py", line 1, in <module>
    import bdpy
  File "/home/kujaku/libraries/python/anaconda2/lib/python2.7/site-packages/bdpy/bdata/bdata.py", line 420, in select
    stack.append(np.array([n == r for n in l], dtype=bool))
TypeError: iteration over a 0-d array
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /home/kujaku/libraries/python/anaconda2/lib/python2.7/site-packages/bdpy/bdata/bdata.py(420)select()
-> stack.append(np.array([n == r for n in l], dtype=bool))
(Pdb)

Then, please type p condition and p expr_rpn, and let me know the outputs.

thanks, this is the output of all steps that you help me to run; image

ShuntaroAoki commented 5 years ago

Okay, thanks. So another inspection: could you tell me the outputs of p self.get_metadata('ROI_VC') and p self.metadata.key at the last step?

In addition, which version of Python and numpy do you use?

ZaraNaSha commented 5 years ago

Okay, thanks. So another inspection: could you tell me the outputs of p self.get_metadata('ROI_VC') and p self.metadata.key at the last step?

In addition, which version of Python and numpy do you use?

image python 3.6.8 numpy 1.16.4

ShuntaroAoki commented 5 years ago

python 3.6.8

Okay, I got it. The problem was caused by string literal type difference between Python 2 and 3. Bdpy and end2end scripts don't yet fully work with Python 3. Please try with Python 2.

ZaraNaSha commented 5 years ago

python 3.6.8

Okay, I got it. The problem was caused by string literal type difference between Python 2 and 3. Bdpy and end2end scripts don't yet fully work with Python 3. Please try with Python 2.

I think that the code is compatible with python 2.7 and newer version. thank you for your follow up.