facebookarchive / caffe2

Caffe2 is a lightweight, modular, and scalable deep learning framework.
https://caffe2.ai
Apache License 2.0
8.42k stars 1.94k forks source link

ImportError: cannot import name 'core' #1909

Open dbxmcf opened 6 years ago

dbxmcf commented 6 years ago

Dear Developers:

Following the steps in the link:

https://caffe2.ai/docs/getting-started.html?platform=ubuntu&configuration=compile

It seems I have succesfully built caffe2, however I am having problem running it, below are my list of commands and outputs:

[fchen14@qb003 build]$ module li Currently Loaded Modulefiles: 1) /home/fchen14/mymodules/python36 3) gcc/4.9.0 5) cmake/3.4.1/INTEL-14.0.2 2) cuda/8.0 4) intel/14.0.2 [fchen14@qb003 build]$ cmake -DCMAKE_C_COMPILER=which gcc -DCMAKE_CXX_COMPILER=which g++ .. && make -j 20 -- The CXX compiler identification is GNU 4.9.0 -- The C compiler identification is GNU 4.9.0 -- Check for working CXX compiler: /usr/local/compilers/gcc/4.9.0/bin/g++ -- Check for working CXX compiler: /usr/local/compilers/gcc/4.9.0/bin/g++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done ... lots of output ... [fchen14@qb003 caffe2]$ git clone --recursive https://github.com/caffe2/caffe2.git && cd caffe2 Cloning into 'caffe2'... remote: Counting objects: 87243, done. remote: Compressing objects: 100% (2/2), done. remote: Total 87243 (delta 0), reused 0 (delta 0), pack-reused 87241 Receiving objects: 100% (87243/87243), 214.81 MiB | 41.80 MiB/s, done. ... lots of output Cloning into 'third_party/zstd'... remote: Counting objects: 27405, done. remote: Compressing objects: 100% (85/85), done. remote: Total 27405 (delta 104), reused 104 (delta 70), pack-reused 27250 Receiving objects: 100% (27405/27405), 12.66 MiB | 8.43 MiB/s, done. Resolving deltas: 100% (20202/20202), done. Checking connectivity... done. Submodule path 'third_party/zstd': checked out 'aec56a52fbab207fc639a1937d1e708a282edca8' [fchen14@qb003 caffe2]$ mkdir build && cd build [fchen14@qb003 build]$ which python /work/fchen14/acd3/bin/python [fchen14@qb003 build]$ python --version Python 3.6.2 :: Anaconda custom (64-bit) [fchen14@qb003 build]$ cmake -DCMAKE_C_COMPILER=which gcc -DCMAKE_CXX_COMPILER=which g++ .. && make -j 20 -- The CXX compiler identification is GNU 4.9.0 -- The C compiler identification is GNU 4.9.0 -- Check for working CXX compiler: /usr/local/compilers/gcc/4.9.0/bin/g++ -- Check for working CXX compiler: /usr/local/compilers/gcc/4.9.0/bin/g++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Check for working C compiler: /usr/local/compilers/gcc/4.9.0/bin/gcc -- Check for working C compiler: /usr/local/compilers/gcc/4.9.0/bin/gcc -- works ... lots of output ... [ 99%] Building CXX object modules/detectron/CMakeFiles/caffe2_detectron_ops_gpu.dir/select_smooth_l1_loss_op.cc.o [ 99%] Building CXX object modules/detectron/CMakeFiles/caffe2_detectron_ops_gpu.dir/affine_channel_op.cc.o [100%] Building CXX object modules/detectron/CMakeFiles/caffe2_detectron_ops_gpu.dir/sigmoid_focal_loss_op.cc.o [100%] Building CXX object modules/detectron/CMakeFiles/caffe2_detectron_ops_gpu.dir/sample_as_op.cc.o [100%] Linking CXX shared library ../../lib/libcaffe2_detectron_ops_gpu.so [100%] Built target caffe2_detectron_ops_gpu [fchen14@qb003 build]

The above seems to be the indication of a succesful build, then try to test the installation in build directory

[fchen14@qb003 build]$ python Python 3.6.2 |Anaconda custom (64-bit)| (default, Sep 30 2017, 18:42:57) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.

from caffe2.python import core Traceback (most recent call last): File "", line 1, in ImportError: cannot import name 'core'

However I can import * from caffe2.python [fchen14@qb003 build]$ python Python 3.6.2 |Anaconda custom (64-bit)| (default, Sep 30 2017, 18:42:57) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.

from caffe2.python import *

Could you tell the solution to this? Thanks a lot!

feldim2425 commented 6 years ago

I had the same issue. It seems like it moves the python libraries to the wrong location in my case it moved the libraries to '/usr/lib/python3/dist-packages' where python didn't find it. So I simply copied '/usr/lib/python3/dist-packages/caffe2' to '/usr/lib/python3.6/dist-packages'. But I don't know where this files are for anaconda.

pjh5 commented 6 years ago

Have you tried setting your PYTHONPATH to /usr/local ? Caffe2 installs into /usr/local by default. If it is not in /usr/local you can find it with find / -name libcaffe2* 2>/dev/null

When was the last time you pulled Caffe2 from Github? There was a PR only two days ago that affected this logic https://github.com/caffe2/caffe2/pull/1677 .

dbxmcf commented 6 years ago

Hi, I did not try to install in /usr/local, it is a cluster environment, user do not have permission and I was trying to import it from caffe2/build directory,

Below is the log I checked out:

[fchen14@qb003 caffe2]$ git log commit 965cdbaa719f5f720e8fb7e5eee8b4e19ca061ea Author: Qinqing Zheng zqq@fb.com Date: Mon Feb 5 23:06:03 2018 -0800

pjh5 commented 6 years ago

Where did you install caffe2 then? Can you run find / -name libcaffe2* 2>/dev/null? What is your PYTHONPATH?

kenkyusha commented 6 years ago

output of find / -name libcaffe2* 2>/dev/null :

/usr/local/lib/libcaffe2.so
/usr/local/lib/libcaffe2_detectron_ops_gpu.so
/usr/local/lib/libcaffe2_module_test_dynamic.so
/usr/local/lib/libcaffe2_gpu.so
/home/nvidia/caffe2/build/lib/libcaffe2.so
/home/nvidia/caffe2/build/lib/libcaffe2_detectron_ops_gpu.so
/home/nvidia/caffe2/build/lib/libcaffe2_module_test_dynamic.so
/home/nvidia/caffe2/build/lib/libcaffe2_gpu.so

additional information: installed on Jetson TX2 with build_tegra script

pjh5 commented 6 years ago

@dbxmcf I noticed that your default python is an Anaconda version. This python executable will search for libraries inside the current environment, e.g. in /users/myuser/anaconda/envs/my_caffe2_env/lib . To install Caffe2 in an Anaconda environment, it's best to pass CMAKE_PREFIX_PATH and CMAKE_INSTALL_PATH as the root dir of the conda environment (in this example /users/myuser/anaconda/envs/my_caffe2_env). Please see https://caffe2.ai/docs/getting-started.html?platform=mac&configuration=compile#custom-anaconda-install (which also works on linux).

@kenkyusha what is the error that you are having? It looks like you have installed Caffe2 into /usr/local with a leftover built folder under /home/nvidia/caffe2 . Can you set LD_LIBRARY_PATH to /usr/local ?

kenkyusha commented 6 years ago

@pjh5 thanks for fast reply upon closer look it appears that running the relu test actually works fine and everything imports also neat when i am in $HOME and not while inside $HOME/caffe2 python caffe2/python/operator_test/relu_op_test.py however I am not convinced or sure whether it is using the GPU on my Jetson TX2 any hints regarding that?

pjh5 commented 6 years ago

@kenkyusha what is your output when you run from caffe2.python import core ? What is your cmake summary output?

kenkyusha commented 6 years ago

@pjh5 I think it is some kind of path error, I set the LD_LIBRARY_PATH to usr/local as you requested and tried from caffe2.python import core and funny thing it only fails to load the core when i aim in caffe2 root directory. Also the relu_op_test.py works from everywhere else but the caffe2 root dir

cmake output (not sure if it is correct or not) $HOME/caffe2/cmake/Summary.cmake

PS! for installing caffe2 i used the ./scripts/build_tegra_x1.sh . Maybe it is depricated and I should rm -rf the build and "rebuild" from scratch?=

pjh5 commented 6 years ago

@kenkyusha within build_tegra.sh there is a line that calls "cmake". This command will run caffe2/cmake/Summary.cmake and print out the value of all those variables as they were found by cmake on your machine. Please find this output and post that here.

Before building Caffe2 again you should always delete the build folder (by default it's caffe2/build).

Python will act differently depending on where you run it from because it will look for imports in the current directory that you started python from. We advise that you do not run Caffe2 in python from the Caffe2 root directory or from the Caffe2 build directory.

Can you also run which python and also find "$(which python)" -name *caffe2* 2>/dev/null ?