Running Google's DeepDream on Windows with CUDA: ImportError DLL load failed [duplicate] - cuda

I have build .dll of _caffe.cpp on Windows (Release, x64).
I changed extension .dll to .pyd and trying to import it in python:
import caffe
File "\caffe-master\python\caffe\__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver
File "\caffe-master\python\caffe\pycaffe.py", line 13, in <module>
from ._caffe import Net, SGDSolver
ImportError: DLL load failed: The specified module could not be found.
What does it mean, some module of dependencies missing which was included in project in Visual Studio, where I build this dll?

You need to add Python Caffe to PYTHONPATH. For example:
export PYTHONPATH=$PYTHONPATH:/home/username/caffe/python

For windows :
Adding /caffe/Build/x64/Release/pycaffe to system path(path) works for me, and I think the best way to do it is :
New a system variable : PYTHON_PKG = /caffe/Build/x64/Release/pycaffe;
Include PYTHON_PKG in path : path = %PYTHON_PKG%; %OtherDirs%
After I did this, I get PKG missing google.internal, then I did pip install google.internal in CMD. It works.

Once you have a compiled and built caffe, try
echo 'export PYTHONPATH=/path/to/caff-dir/python'
Also, you may need to run following:
pip install -r requirement.txt

Related

ModuleNotFoundError: No module named 'torchvision.models.feature_extraction'

I want to extract features in ResNet101, however, I have trouble importing torchvision.models.feature_extraction.
Here is my code:
from torchvision import models
from torchvision.models.feature_extractor import create_feature_extractor
res101 = models.resnet101(pretrained=True)
extractor = create_feature_extractor(
res101,
return_nodes=[
"conv1",
"maxpool",
"layer1",
"layer2",
"layer3",
"layer4",
]
)
features = extractor(inputs)
And here is the error
from torchvision.models.feature_extractor import create_feature_extractor
Traceback (most recent call last):
Input In [11] in <cell line: 1>
from torchvision.models.feature_extractor import create_feature_extractor
ModuleNotFoundError: No module named 'torchvision.models.feature_extractor'
You might be trying to use something like:
from torchvision.models.feature_extraction import create_feature_extractor
See the extraction vs extractor
Check this module
Same problem. I installed PyTorch using conda and it works fine in Jupyter notebooks. But it does not work in terminal.
Turns out the pip listed torchvision version was 0.82.
Solved by updating torchvision using pip.
Maybe some packages installed the old version for me. Hope my experience helps you.

ModuleNotFoundError: No module named 'fastai.vision'

I am trying to use ImageDataBunch from fastai, and it worked fine, but recently when I ran my code, it showed this error ModuleNotFoundError: No module named 'fastai.vision'
Then, I upgraded my fastai version pip install fastai --upgrade. This error got cleared but landed in NameError: name 'ImageDataBunch' is not defined
Here's my code:
import warnings
import numpy as np
from fastai.vision import *
warnings.filterwarnings("ignore", category=UserWarning, module="torch.nn.functional")
np.random.seed(42)
data = ImageDataBunch.from_folder(path, train='.', valid_pct=0.2,
ds_tfms=get_transforms(), size=224, num_workers=4, no_check=True).normalize(imagenet_stats)
How can I fix this?
I actually ran into this same issue when I started using Colab, but haven't been able to reproduce it. Here was the thread describing what I and another developer did to troubleshoot: https://forums.fast.ai/t/no-module-named-fastai-data-in-google-colab/78164/4
I would recommend trying to factory reset your runtime ( "Runtime" -> "Factory Reset Runtime")
Then you can check which version of fastai you have (you have to restart the runtime to use the new version if you've already imported it)
import fastai
fastai.__version__
I'm able to run fastai.vision import * on fastai version 1.0.61 and 2.0.13
In Google Colab:
Upgrade fastai on colab:
! [ -e /content ] && pip install -Uqq fastai
Import necessary libraries:
from fastai.vision.all import *
from fastai.text.all import *
from fastai.collab import *
from fastai.tabular.all import *
Get the images and annotations:
path = untar_data(URLs.PETS)
path_anno = path/'annotations'
path_img = path/'images'
print( path_img.ls() ) # print all images
fnames = get_image_files(path_img) # -->> 7390 images
print(fnames[:5]) # print first 5 images
The solution that worked for me is to copy to (connect) my google drive & then run the cells. Source
You might have installed the older version of fastai. You need to upgrade to fastaiv2. You can upgrade fastai by using pip as shown below.
!pip install fastai --upgrade
Also check your fastai version using
import fastai
print(fastai.__version__)

pygame py2app Library not loaded: #loader_path/.dylibs/libSDL-1.2.0.dylib

I wouldn't call myself a programmer and am unfamiliar with Mac and Linux, so any links or pointers to additional background would help greatly. I've started with the most basic pygame I could google, (from https://realpython.com/pygame-a-primer/). The test.py and test.app runs on my VM but not on anyone else's real Macs.
test.py file
import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
pygame.display.flip()
setup.py file
from setuptools import setup
APP = ['test.py']
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
command to create the test.app
$ python3 setup.py py2app
The test.app runs fine on the VM, but whenever the test.app runs on a real Mac (tested 2, one ran on Catalina ver???) this error message appears:
Traceback (most recent call last):
File "/Applications/test.app/Contents/Resources/__boot__.py", line 101, in <module>
_run()
File "/Applications/test.app/Contents/Resources/__boot__.py", line 84, in _run
exec(compile(source, path, "exec"), globals(), globals())
File "/Applications/test.app/Contents/Resources/test.py", line 1, in <module>
import pygame
File "pygame/__init__.pyc", line 120, in <module>
File "pygame/base.pyc", line 14, in <module>
File "pygame/base.pyc", line 10, in __load
File "imp.pyc", line 343, in load_dynamic
ImportError: dlopen(/Applications/test.app/Contents/Resources/lib/python3.7/lib-dynload/pygame/base.so, 2): Library not loaded: #loader_path/.dylibs/libSDL-1.2.0.dylib
Referenced from: /Applications/test.app/Contents/Resources/lib/python3.7/lib-dynload/pygame/base.so
Reason: image not found
2020-05-02 11:27:50.309 test[931:15836] test Error
----------------------------
Working environment: VirtualBox 6.1, macOS Sierra (Version 10.12) with the following:
$ pip list
Package Version
----------- ----------
altgraph 0.17
certifi 2020.4.5.1
macholib 1.14
modulegraph 0.18
pip 20.1
py2app 0.21
pygame 1.9.6
setuptools 39.0.1
wheel 0.34.2
$ brew list --versions
freetype 2.10.1
gdbm 1.18.1
jpeg 9d
libmikmod 3.3.11.1
libogg 1.3.4
libpng 1.6.37
libtiff 4.1.0
libvorbis 1.3.6
openssl#1.1 1.1.1g
pkg-config 0.29.2_3
python 3.7.7
readline 8.0.4
sdl 1.2.15_1
sdl2 2.0.12_1
sdl_image 1.2.12_7
sdl_mixer 1.2.12_3
sdl_ttf 2.0.11_1
sqlite 3.31.1
webp 1.1.0
xz 5.2.5
Any ideas or pointers would be greatly appreciated. The actual program is an OhHell card game which supports Windows clients (via pyinstaller), but I'm also trying to support a Mac client to play with my friends on a Mac. Similar to the test.py and test.app (ohhell.py and ohhell.app) runs on the VM Mac but same issue/error occurs with real macs. I've just included the simplest code snippet that I was able to google that reproduced the exact error message.
-john
Workaround Solution: Linking to a dynamic library on a Mac with full path and What path does #loader_path resolve to?. Using the '$ install_name_tool -change "#loader_path/.dylibs/libSDL-1.2.0.dylib" "/Applications/test.app/Contents/Frameworks/libSDL-1.2.0.dylib" base.so' resolved the Library not loaded: loader_path/.dylibs/libSDL-1.2.0.dylib errors. I assume this hard codes the path, but with my friends it's fine to tell them to make sure it resides in the /Applications folder.
However a secondary problem came up, 'pygame.error: File is not a Windows BMP file'. I used py2app, so the pygame delete and reinstall threads didn't seem like a feasible solution (pygame unnecesary w/py2app), so switching the images to uncompressed bitmap (256 colors) worked.
For those curious, I did try Pyinstaller for Mac but that presented a whole new set of problems.

Python 3: parse html with XPath error

I am new to python 3. I am paring the html data with XPath. I use the pycharm to compile my code, my code is shown as following. please help me fix the issue (please don't use the beautiful soup).I know a lot code about parse html with python 2 xpath, if you have some materials link about parse html with python 3 xpath, please tell me. I have installed the lxml and requests library in the pycharm. Further, the terminal default is python 2.7.Thanks in advance!
from lxml import html
import requests
page = requests.get('http://econpy.pythonanywhere.com/ex/001.html')
tree = html.fromstring(page.content)
#This will create a list of buyers:
buyers = tree.xpath('//div[#title="buyer-name"]/text()')
#This will create a list of prices
prices = tree.xpath('//span[#class="item-price"]/text()')
print('Buyers: ', buyers)
print('Prices: ', prices)
The errors:
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
/Users/tianke0711/PycharmProjects/database/Pax_html/xpath_test.py
Traceback (most recent call last):
File
"/Users/tianke0711/PycharmProjects/database/Pax_html/xpath_test.py",
line 1, in <module>
from lxml import html
File
"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-
packages/lxml/html/__init__.py", line 54, in <module>
from .. import etree
ImportError:
ddlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/lxml/etree.cpython-35m-darwin.so, 2): Library not loaded: libxml2.2.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/lxml/etree.cpython-35m-darwin.so
Reason: Incompatible library version: etree.cpython-35m-darwin.so requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0
Based on the error information,the libxml2.2( Library not loaded: libxml2.2.dylib) is the old version. Since the python3 need new version of libxml. Use the following command to install the new libxml, and then it works for me.
brew install libxml2
brew install libxslt
brew link libxml2 --force
brew link libxslt --force
Actually, I don't know the reason in detail. If some guys know this, please tell me! Thanks!

Load new module in Kamailio

I would like to ask, how can I load new module in Kamailio 4.1.2?
Actually, I have an issue, when I tried to compile my kamaiio.cfg
I've got error:
root#kamailio:/usr/local/# kamailio -c kamailio.cfg
loading modules under /usr/local/lib64/kamailio/modules/
0(25392) ERROR: <core> [sr_module.c:587]: load_module(): ERROR: load_module: could not find module <websocket> in </usr/local/lib64/kamailio/modules/>
0(25392) : <core> [cfg.y:3408]: yyerror_at(): parse error in config file /usr/local/etc/kamailio/kamailio.cfg, line 323, column 12-25: failed to load module
0(25392) ERROR: <core> [cfg.y:3272]: yyparse(): cfg. parser: failed to find command ws_handle_handshake
0(25392) : <core> [cfg.y:3411]: yyerror_at(): parse error in config file /usr/local/etc/kamailio/kamailio.cfg, line 1083, column 27: unknown command, missing loadmodule?
ERROR: bad config file (2 errors)
when I look physically to the /usr/local/lib64/kamailio/modules/ there is some modules, but websocket.so is missing.
So, how can I get and load module in Kamailio?
Thank you for help!
You haven't installed the module websocket. Edit modules.lst file in the source code directory and add websocket to include_modules variable. If you don't have modules.lst, just do:
make cfg
Alternative is to do:
make cfg include_modules="websocket"
By default, the build system for kamailio compiles and install only the modules that have the same dependencies as the core of the application. For websocket you need to install libunistring and openssl (libssl) devel packages.
Steps to load new module to Kamailio server. (Try if above answer is not working for you)
Check the modules is exist in the default module directly /usr/local/lib64/kamailio/modules.
If found, add loadmodule "module_name.so" in load module section in kamailio.cfg file.
If the module is not found in default module directory, you can check for the source code of that module in the default module source code directory /usr/local/src/kamailio-4.4/kamailio/modules.
If source code found, enter to the module directory. Then create modules' shared object file(.so) by following commands.
./configure
make
make test
make install
Then you will get a shared object file(.so). Copy that file into the default module directory. and load this module from the kamailio.cfg file as mentioned in step 1.
If module source code does not exist in the default source code directory, You need to download the source code from the web. And follow step 3 and 4.