training SyntaxNet from parser_trainer_test.sh (ImportError: cannot import name tf_logging) - python-2.7

I am new to python and SyntaxNet and I am trying to train SyntaxNet from SyntaxNet Tutorial.
To trained the model I updated parser_trainer_test.sh based on The Tutorial. and ran it as follow:
ubuntu#ubuntu-VirtualBox:~/models/syntaxnet$ syntaxnet/parser_trainer_test.sh
It gave me this error:
syntaxnet/parser_trainer_test.sh: line 36: /home/ubuntu/models/syntaxnet/syntaxnet/parser_trainer: No such file or directory
Then I updated "$BINDIR/parser_trainer" \ in line 35 of parser_trainer_test.sh to "$BINDIR/parser_trainer.py" \ and ran it again.
And it gave me this error:
File "/home/ubuntu/models/syntaxnet/syntaxnet/parser_trainer.py", line 25,in <module>
from tensorflow.python.platform import tf_logging as logging
ImportError: cannot import name tf_logging
I went through tf_logging.py and all other python files in syntaxnet/tensorflow/python/platform
I think that's where the error is. But if you want, I can post more.
parser.trainer.py :
import os
import os.path
import time
import tensorflow as tf
from tensorflow.python.platform import tf_logging as logging # this is where error happens
from tensorflow.python.platform import gfile
tf_logging.py:
import logging
import os
import sys
import time
from logging import DEBUG
from logging import ERROR
from logging import FATAL
from logging import INFO
from logging import WARN
There is something that I am suspecious about (I am not perofessional so sorry if it seems silly). I found a file named logging.hin path tensorflow/tensorflow/core/platform which defines DEBUG,ERROR,FATAL,.. and I get confused whether the aim of the model is the logging package from python or this logging.h file. If am wrong, which is probable, please help me through this problem.

I suspect the problem is that you are trying to run the script directly, and it expects to be invoked by Bazel (so that the environment, paths, etc. are set up appropriately). Try the following command instead:
$ bazel test //syntaxnet:parser_trainer_test

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

Caffe2 Import Throwing Error in Python free() invalid size

I'm trying to import the following modules for a Caffe2 tutorial.
Tutorial here: https://github.com/caffe2/caffe2/blob/master/caffe2/python/tutorials/Loading_Pretrained_Models.ipynb
Modules here:
%matplotlib inline
from caffe2.proto import caffe2_pb2
import numpy as np
import skimage.io
import skimage.transform
from matplotlib import pyplot
import os
from caffe2.python import core, workspace, models
import urllib2
print("Required modules imported.")
But it's throwing the following at import.
"* Error in `python': free(): invalid size: 0x0000000000de4e80 *
Aborted (core dumped).
I deleted each line one by one and found the problem line being:
from caffe2.python import core, workspace, models
If I remove this, it will import without issue.
Now, if I import this via the python IDE it works.
Any help would be appreciated!
Thanks

Pylint disagrees with file import

In reference to How do I import a Python script from a sibling directory?, Pylint will error with E0401:Unable to import at line 6.
if __name__ == '__main__':
if __package__ is None:
import sys
from os import path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
from components.core import my_module
else:
from ..components.core import my_module
Is this just something that we have to accept, or is there a rigorous solution to correct this?
While the file in question is part of my unit tests and not critical to deployment, I would like to keep everything error free.
(pylint 1.6.4, Python 2.7.12)
If you are referring to importing components, then this would not work, since pylint does not understand modifications of sys.path. It would be theoretically feasible to understand them, but since it is a static analysis tool, it has its limitations with regard to what it can and what it should do. In order to help it, you might try running pylint with --init-hook="import sys; sys.path.append(path.dirname(path.dirname(path.abspath('your file'))))".

Python/pyserial cx_freeze Compilation error: no module named tools

I am trying to compile a python code with cx_freeze in Windows 7, python 2.7, but it keeps giving me trouble because of pyserial. I tried to import the pyserial tools module in many different ways but I keep getting compilation errors:
import serial
import serial.tools
from serial.tools import list_ports
#I also tried:
#import serial.tools.list_ports
#from serial import tools
#import serial.tools.list_ports
#from serial import tools
The error message varies between:
ImportError: No module named tools
and
ImportError: No module named tools.list_ports
Any ideas on how to solve this issue? Thanks.

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

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/