问题
I'm following CS231n and met a problem when doing assignment2: ConvolutionalNetworks: global name 'col2im_6d_cython' is not defined
.
I think the problem was due to a failure in importing functions from im2col_cython.pyx
, which used cython.
I've installed Xcode 7.3.1, as shown below, but the problem was still not solved.
I'm running the ipynb files in Jupyter from Anaconda. There is a related discussion on reddit, but unfortunately the solution here was for Windows, not Mac OS X.
Thank you for your time.
回答1:
I wanted to add my input as a comment but didn't have enough reputation points to do so.
The issue was resolved for me when I closed the jupyter notebook and opened it again. I compiled the cython extension after I got the import error and probably have to relaunch it when the .so file is available.
回答2:
I solved this with 2 easy steps:
In the terminal, run
python setup.py build_ext --inplace
in the cs231n directory.Then reopen the notebook (if necessary, shutdown the notebook, the open it again);
Ps.: I tried this through the notebook using !python ./cs231n/setup.py build_ext --inplace
as well. It does not work! You have to that outside the notebook, using the terminal.
回答3:
I had this problem recently. I googled it a lot and also tried un-/-reinstall Anaconda. However it does work further. So I used "which python" to figure out which python's been using. And it turns out that the python included in Anakonda directory is used as default. I then tried the python2.7 in my macOS, which is located in /usr/bin/python2.7. Although I got a couple of warnings, but now it works likes charm. Perhaps it's kind of version problem. Solved in macOS Sierra 10.12.4.

I compared the two compiling results, as it shows that the include files are totally different. The one in Anaconda includes all header files in python3.6. Instead we need here corresponding header files in python2.7(I suppose). As the red circles point out.
enter image description here
回答4:
Supported by python 3 onwards. Go to setup_googlecloud.sh and change the line virtualenv .env to virtualenv -p python3 .env and run the setup again as explained in assignment1 setup.. Works well after that..
回答5:
It occurred to me as well.
My problem:
I saw that the extention file that is created is named "im2col_cython.cp37-win_amd64.pyd" and the import is looking for im2col_cython alone, so I changed the file name to "im2col_cython.pyd" and ran the setup script again. Now when I ran the code in the notebook it found the module but it said that the dll was compiled with a different python version. I use Anaconda envs and it turns out that since I ran the setup script from the cmd, it used a different python version than the one of the environment. I deleted the created files from the cs231n directory (im2col_cython.cp37-win_amd64.pyd and im2col_cython.c) and ran the setup script again, this time from the env Anaconda Prompt and it worked.
Solution:
- remove already created files (the .c and .pyd files)
- run the setup script from the environment prompt (not plain cmd)
- change the .pyd file name into im2col_cython.pyd
Enjoy!
来源:https://stackoverflow.com/questions/38993332/global-name-col2im-6d-cython-is-not-defined-cs231n