I have installed caffe from source. I have used the Cmake for installation. I have updated the respective paths as well.
My caffe root directory is: /home/ashj/caffe
I have updated the PYTHON path as:
export PYTHONPATH=<caffe-home>/python:$PYTHONPATH
which is by using
**export PYTHONPATH=/home/ashj/caffe/python:$PYTHONPATH**
I could load import the module caffe. However I am not able to access any methods or any layers inside the caffe like set_mode_gpu(), set_mode_cpu() or layers or params. I am getting errors like:
When I used
import caffe
caffe.set_mode_gpu()
I am getting following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'caffe' has no attribute 'set_mode_gpu'
PS: I have also tried using caffe.__caffe.set_mode_gpu() as mentioned in this link. but it is not working for me.
My system specs: Ubuntu 18.04
TIA
Though may be late, but I encountered this same problem and found a way work around:
sys.path.insert(0, '/path/to/caffe/python')
import caffe
caffe.set_mode_gpu()
namely, add the caffe/pathon path to you sys.path before import caffe.
Wrote a post here for detailed analysis, hope helpful.
This problem may be the results of package caffe's path.
For me, if I do the following from the Ubuntu Terminal, everything goes fine:
but if I do from the Pycharm IDE, errors occur:
note that I tested the package caffe's path in both ways, and got different results:
- in the Ubuntu terminal, namely the way which goes fine, I got
'/home/CVAR-B/softwares/caffe/caffe/python/caffe/__init__.pyc'
which is the expected result;
- in the Pycharm IDE way, namely the way error occurs, I got
'/usr/local/lib/python2.7/dist-packages/caffe/__init__.pyc'
which is not the expected result.
In view of this discovery, I did this one more thing to handle the error:
sys.path.insert(0, '/path/to/caffe/python')
import caffe
caffe.set_mode_gpu()
namely, add the caffe/pathon path to you sys.path before import caffe.
and the result shows this can be a workaround:
(source: ax2x.com)
See the caffe.__file__'s result, now returns the expected path.
Try these steps and then set your python PATH:
You might've already done steps 1 and 3.
make all
make pycaffe
make distribute
mkdir ~/python
mv distribute/python/caffe ~/python
Set your PYTHONPATH after this — this should be some dir like caffe/python/caffe
Related
Looking to convert "FastSeg-large" public model from the OpenModelZoo to use with the "image segmentation" demo. I was able to use the download.py utility to get the original model files downloaded. Now i'm running the following command:
python3 converter.py --name fastseg-large
I'm getting the following error:
Module fastseg_large in C:\Users\david\Desktop\Neural Zoo\open_model_zoo\models\public\fastseg-large;C:\Users\david\Desktop\Neural Zoo\open_model_zoo\tools\downloader\public\fastseg-large/model doesn't exist. Check import path and name
cannot import name 'container_abcs' from 'torch._six' (C:\Users\david\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\torch\_six.py)
Looks like i'm getting 2 different errors with the first having trouble finding the path to the original torch model files. I confirmed my path down to the "/model" directory exists. In that directory is another subdirectory "fastseg\model" where the torch model files exist.
The second error i'm not sure about - i double checked that i installed Torch from pip.
Any suggestions?
I’ve validated that running converter.py for FastSeg-large public model is working fine in OpenVINO™ 2021.4.752.
Make sure you run the install_prerequisites_onnx.bat batch file to configure the Model Optimizer for ONNX:
cd “C:\Program Files (x86)\Intel\openvino_2021.4.752\deployment_tools\model_optimizer\install_prerequisites”
then
install_prerequisites_onnx.bat
Doing some more web searches i see the error can be due to a newer version of Torch. So i uninstalled Torch and reinstalled version 1.8. That actually failed and i went back to the "pip install torch" without specifying the version. Then i saw torchvision was also mentioned so i "pip install torchvision".
Somewhere along the way i must have cleaned up something related to my torch libraries. Either way that got this to work.
I am trying to use the nets from the official mnist directory of tensorflows model repository. On my windows system I receive this error:
C:\Users\ry\Desktop\NNTesting\models\official\mnist>mnist_test.py
Traceback (most recent call last):
File "C:\Users\ry\Desktop\NNTesting\models\official\mnist\mnist_test.py",line 24, in <module>
from official.mnist import mnist
ModuleNotFoundError: No module named 'official'
I have followed their official directions and set my python path using
set PYTHONPATH="PYTHONPATH:"%cd%"
and can confirm that
PYTHONPATH="$PYTHONPATH:C:\Users\ry\Desktop\NNTesting\models"
and I have also installed the dependencies successfully. Does anyone have experience using these models on a windows system and can help me with this pathing issue? I'm not sure what I have done incorrectly here.
Thanks
pip install tf-models-official
For Google Colab I needed to add the the model dir also to the Systems path:
!git clone https://github.com/tensorflow/models.git
import os
os.environ['PYTHONPATH'] += ":/content/models"
import sys
sys.path.append("/content/models")
if anyone has this problem make sure that the python path variable doesn't have quotations in it. For some reason, the readme has quotations around it.
Here is the correct way to set it
PYTHONPATH=path\to\models
I had exactly the same question as you did, and the following solution solved this problem.
There is an error in the tensorflow/models/official README.md
https://github.com/tensorflow/models/tree/master/official
Wrong
export PYTHONPATH="$PYTHONPATH:/path/to/models"
Correct
export PYTHONPATH=$PYTHONPATH:/path/to/models
The Official Models are made available as a Python module. To run the models and associated scripts, add the top-level /models folder to the Python path with the command: export PYTHONPATH="$PYTHONPATH:/path/to/models"
FROM README
I had the same problem. Did you use windows 10? Make sure you run the command prompt as "administrator". I used it in VS code at first, no warning, and didn't work. But it worked when I run a separate prompt window as "administrator".
set PYTHONPATH=path\to\models
then run the model.
I was setting up to run the NMT model and ran into the same problem.
It took me bit to figure out exactly which folder should be added to PYTHONPATH.
I tried several folders inside my example's directory with no luck.
I finally understood what that import was trying to tell me...
"from official.transformer.utils import tokenizer"
means
"add the parent of directory 'official' to PYTHONPATH".
For me, this was just the top-level 'models-master' directory that I obtained from GitHub. Once I added /path/to/models-master, I was past this obstacle.
Go to models folder and do
export PYTHONPATH=$PYTHONPATH:$PWD
add the model directory to PYTHONPATH.
import os
os.environ['PYTHONPATH'] += ':/content/models/research/:/content/models/research/slim/'
jupyter. Clone from official git and manually appended the path to sys.
!git clone https://github.com/tensorflow/models.git
import sys
sys.path.append("C:/Windows/System32/models")
sys.path
Still learning certain things about Python... I am having issues recognizing my Python script in my scripts dir. First, I checked to see that my path is set correctly:
import sys
for pythonPath in sys.path:
print pythonPath
And C:/Users/..../Documents/maya/2014-x64/scripts is listed, which is where I am placing swap.py
In Maya's script editor I am typing the following:
import swap
reload(swap)
swap.printSomething()
I get:
Error: AttributeError: file line 3: 'module' object has no attribute 'printSomething' #
If I take the same code and throw it into a package...
C:/Users/..../Documents/maya/2014-x64/scripts/swapPackage/swap.py
And then call this, it works...
import swapPackage.swap as swap
reload(swap)
swap.printSomething()
Why? I am totally confused. Mel scripts even run fine from this location as well. I just can't get a simple python script to import and run.
Also something I noticed. Even though I can get this script to run in a package, the package name must be totally different than the module name. I can't have a package named this:
C:/Users/..../Documents/maya/2014-x64/scripts/swap/swap.py
but I can have one where the package name is different:
C:/Users/..../Documents/maya/2014-x64/scripts/swapPackage/swap.py
Ok folks, I was able to solve this by executing a print of my file, only to find out that it was sourcing a totally different version someone copied elsewhere. ARGH. This solves both issues, and makes sense why changing the package name from the module worked.
import swap
reload(swap)
print swap.__file__
I am trying to use OpenCV 3.0 with Anaconda Python3.4. I compiled the opencv sources from Github together with the accompanying opencv_contrib repository and installed them inside a local directory.
Now, starting python I am able to import the cv2 module and do stuff like loading and displaying images. However it seems that the submodule xfeatures2d doesn't exist.
>>> import cv2
>>> cv2.xfeatures2d
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'xfeatures2d'
Interestingly I get no error if I try to import cv2.xfeatures2d (although I still can't use it then)
The shared library file exists in ~/MyOpenCV3Install/lib/libopencv_xfeatures2d.so.3.0.0. My first guess was that it is not being loaded for some reason, so I tried to force it using the LD_PRELOAD environment variable prior to launching python. However still no luck so far.
For me it doesn't work using the python3.4 environment. However, when using a python2.7 environment everything works just fine. After importing the cv2 module I can call functions like cv2.xfeatures2d.SURF_create() without errors.
Does anybody have an idea why the xfeatures2d submodule is not available when using python3.4? Is it possible that the python bindings created for opencv_contrib are not compatible with python3 yet?
EDIT:
I used the following options for the cmake configuration step:
BUILD_opencv_python3=ON
PYTHON3_EXECUTABLE=/home/mi/anaconda/envs/env3.4/bin/python3.4
PYTHON3_INCLUDE_DIR=/home/mi/anaconda/envs/env3.4/include/python3.4.m
PYTHON3_LIBRARY=/home/mi/anaconda/envs/env3.4/lib/libpython3.4m.so
PYTHON3_NUMPY_INCLUDE_DIR=/home/mi/anaconda/envs/env3.4/lib/python3.4/site-packages/numpy/core/include
PYTHON3_PACKAGES_PATH=/home/mi/anaconda/envs/env3.4/lib/python3.4/site-packages
I am having trouble getting PyDev on Eclipse to recognize installed modules (gensim), which work fine in IDLE. I am using Windows Vista, 32-bit. Python 2.7.
I have found this question asked: here, here, here, and here.
The recommended solution is to go to preferences > pydev > interpreter - python, and remove and re-add (w/ Auto Config) the python interpreter. I have done this, and have restarted Eclipse. In PYTHONPATH, C:\Python27\lib\site-packages\gensim-0.8.0-py2.7.egg, appears, but I still run into the import error. My code is:
from gensim import corpora, models, similarities
And this yields:
Traceback (most recent call last):
File "C:\Users\Jpan\Documents\workspace\FirstProject\src\gensim.py", line 1, in <module>
from gensim import corpora, models, similarities
File "C:\Users\Jpan\Documents\workspace\FirstProject\src\gensim.py", line 1, in <module>
from gensim import corpora, models, similarities
ImportError: cannot import name corpora
Another recommended solution is to manually add the folder by clicking "New Folder" in the bottom part of the interpreter - python screen and navigating to the location where gensim installed. I have also done this, and added C:\Python27\lib\site-packages\gensim-0.8.0-py2.7.egg\gensim, which has all the necessary \__init__.py files. But, I still get the ImportError.
Any suggestions for what else I could try?
This is independent of Eclipse/PyDev. You'll get the same error running the code in any other way. Your module imports gensim. The first entry on the PYTHONPATH is the current directory, and your module is called gensim.py, so your module attempts to import iteself. Because imports are cached, you don't get into infinite recursion but get a reference to a module containing... nothing, especially not the things you expected from the "real" gensim module.
The error message should mention this possibility, it's incredibly common. The solution is to rename your file.