Caffe install getting ImportError: DLL load failed: The specified module could not be found - python-2.7

I am trying to compile and run the snippets posted here, which basically is going to let me visualize the network internals(feature maps).
I have successfully compiled caffe and pycaffe using the caffe-windows branch, And I have copied the caffe folder, into T:\Anaconda\Lib\site-packages folder.
Yet still, when I try to run this snippet of code in jupyter notebook :
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
# Make sure that caffe is on the python path:
caffe_root = 'TC:/Caffe/' # this file is expected to be in {caffe_root}/examples
import sys
sys.path.insert(0, caffe_root + 'python')
import caffe
plt.rcParams['figure.figsize'] = (10, 10)
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'
import os
if not os.path.isfile(caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel'):
print("Downloading pre-trained CaffeNet model...")
!../scripts/download_model_binary.py ../models/bvlc_reference_caffenet
I get the following error :
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-e7a8ec94e861> in <module>()
8 sys.path.insert(0, caffe_root + 'python')
9
---> 10 import caffe
L:\Anaconda2\lib\site-packages\caffe\__init__.py in <module>()
----> 1 from .pycaffe import Net, SGDSolver
2 from ._caffe import set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver
3 from .proto.caffe_pb2 import TRAIN, TEST
4 from .classifier import Classifier
5 from .detector import Detector
L:\Anaconda2\lib\site-packages\caffe\pycaffe.py in <module>()
11 import numpy as np
12
---> 13 from ._caffe import Net, SGDSolver
14 import caffe.io
15
ImportError: DLL load failed: The specified module could not be found.
Whats wrong here?
Notes:
I'm using Anaconda2-2.4.1-Windows-x86_64.exe

There's most likely a more specific dependency issue you are not seeing (Protobuf / OpenCV). First try using the C++ API to load an example and make sure all the DLL's load. Then you can more confidently narrow things down to the Python side. I recommend the more recent windows caffe instructions based off the branch you're using:
https://initialneil.wordpress.com/2015/01/11/build-caffe-in-windows-with-visual-studio-2013-cuda-6-5-opencv-2-4-9/
I had to do a complete rebuild as detailed above (note that some dependencies are easier to find with NuGet). Also be on the lookout for the right protobuf binaries in various 3rdParty.zip files throughout the above blog.
If you are okay with a snapshot version of Caffe and you don't need to modify the project itself, the following binaries are much easier to install and get working:
https://initialneil.wordpress.com/2015/07/15/caffe-vs2013-opencv-in-windows-tutorial-i/

Related

Caffe Framework :Importing Error

I followed the instructions from "https://gist.github.com/nikitametha/c54e1abecff7ab53896270509da80215" and installed caffe framework.
But ,when I import caffe from some other directory ,it is showing this error
caffe framework was installed but, it still shows the import error -
No module named caffe
How to solve this issue?
Thank you...
You need to add ~/caffe/python to your $PYTHONPATH. either
~$ PYTHONPATH=$PYTHONPATH:~/caffe/python python
>>> import caffe
Or you can do it inside python
>>> import sys
>>> sys.path.insert(0, '~/caffe/python')
>>> import caffe
Alternatively, you can modify your ~/.bashrc file and fix PYTHONPATH environmet variable there

Import error in iPython after installing umfpack

After installing the umfpack package (which I needed) I can no longer import any packages in an iPython Notebook. Any import command e.g
import numpy as np
results in a stream of errors the last of which is
/Users/murray/anaconda/lib/python2.7/site-packages/numpy/core/__init__.py in <module>()
12 os.environ[envkey] = '1'
13 env_added.append(envkey)
---> 14 from . import multiarray
15 for envkey in env_added:
16 del os.environ[envkey]
ImportError: dlopen(/Users/murray/anaconda/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): Library not loaded: #rpath/libopenblas-r0.2.18.dylib
Referenced from: /Users/murray/anaconda/lib/python2.7/site-packages/numpy/core/multiarray.so
Reason: image not found
I'm really out of my depth herem so if you can help, assume I am a total novice.
Someone fixed it for me by reinstalling everything.

can't import package pandas, statsmodels and matplotlib on Jupyter for anaconda

I failed to import package pandas statsmodels and matplotlib in Jupyter in Anaconda 2,
import pandas
import statsmodels
import matplotlib as mpl
for example the error information for import pandas like this
--------------------------------------------------------------------------- ImportError Traceback (most recent call
last) in ()
----> 1 import pandas
/Applications/anaconda/lib/python2.7/site-packages/pandas/init.py
in ()
29 "pandas from the source directory, you may need to run "
30 "'python setup.py build_ext --inplace' to build the C "
---> 31 "extensions first.".format(module))
32
33 from datetime import datetime
ImportError: C extension: hashtable not built. If you want to import
pandas from the source directory, you may need to run 'python setup.py
build_ext --inplace' to build the C extensions first.
but I can import numpy, scipy,sklearn correctly
import scipy as sp
import numpy as np
import sklearn as sk
In addition, if I use Spyder or ipython on Anaconda, it works for all the 6 packages mentioned above. I used the Mac OS 10.10.5, Python 2.7.12 Anaconda 2 (x86_64). The question is similar to the question mentioned in the following link, but the answer seems not work for my problem (I have deleted the python 2.7 installed on the Mac by default).
Import pandas on jupyter ipython notebook fails
uninstall and reinstall pandas and try again. Also if there are useless files in your directory delete them.

Error in keras - name 'Dense' is not defined

I'm new to Deep Neural Network libraries in python. I've installed Theano & keras in my windows system by following these steps(I already had anaconda):
Install TDM GCC x64.
Run the below code from command prompt
conda update conda
conda update --all
conda install mingw libpython
pip install git+git://github.com/Theano/Theano.git
pip install git+git://github.com/fchollet/keras.git
When I'm running the following code in Ipython,
import numpy as np
import keras.models
from keras.models import Sequential
model = Sequential()
model.add(Dense(32, input_shape=(784,)))
model.add(Activation('relu'))
it is showing the following error:
NameError
Traceback (most recent call last)
----> 1 model.add(Dense(32, input_shape=(784,)))
NameError: name 'Dense' is not defined
Here is the error message screenshot.
How come sequential was imported successfully and 'Dense' was not defined?
You need from keras.layers import Activation, Dense.
I had a similar problem in tensorflow 2.0 and solved it by using
from tensorflow.keras.layers import Dense
For TensorFlow 2.6 you should do this:
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

Python package import issues

I am building a package that I want to be able to install with pip. The package name is 'pololu-motors' and is on PyPi now at version 0.1.2, but it seems to not import correctly.
Update: The problem has been solved, the problem was me not the code, however I have updated the package to version 0.2.1 and made it more difficult to clobber the namespace, so hopefully nobody else will have the issue I had.
If I cd into my virtual environment to the base of the motors module and import the package with ipython it works fine, but if I try to import the package from a test project, I've setup, it says it cannot file any of the classes that are on motors.
Here is my motors/__init__.py
from .qik2s9v1 import Qik2s9v1
Just outside of the motors module in site-packages:
In [1]: from motors import Qik2s9v1
In [2]:
There are no errors and the Qik2s9v1 class is found properly, however, in the test project I get this:
In [1]: from motors import Qik2s9v1
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-79017388c348> in <module>()
----> 1 from motors import Qik2s9v1
ImportError: cannot import name Qik2s9v1
I can import motors with no errors, but the class Qik2s9v1 is nowhere to be found.
In [2]: import motors
In [3]: motors.Qik2s9v1
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-fee4c340a836> in <module>()
----> 1 motors.Qik2s9v1
AttributeError: 'module' object has no attribute 'Qik2s9v1'
Any ideas what's going on here?
#Evert had the correct answer to this issue. As it turns out I had a directory named motors in the same location I was trying to import my package name motors with ipython. If I changed directory to any other place in my test package it would have worked just fine.
This is a stupid mistake that I shouldn't have made, but a lesson well learned.