undefined symbol: _ZTIN10tensorflow8OpKernelE in building a library - tensorflow

Trying to build roi-pooling and so file is able to be produced.
The issue is when run the sample program.
File "roi_pooling_test.py", line 3, in <module>
from roi_pooling_ops import roi_pooling
File "/home/Data/Softwares/pixel_link/roi-pooling/roi_pooling/roi_pooling_ops.py", line 8, in <module>
roi_pooling_module = tf.load_op_library(lib_path)
File "/home/Data/Softwares/venv_p2_7_buildfromsource/local/lib/python2.7/site-packages/tensorflow/python/framework/load_library.py", line 61, in load_op_library
lib_handle = py_tf.TF_LoadLibrary(library_filename)
tensorflow.python.framework.errors_impl.NotFoundError: /home/Data/Softwares/pixel_link/roi-pooling/roi_pooling/roi_pooling.so: undefined symbol: _ZTIN10tensorflow8OpKernelE
Makefile:15: recipe for target 'test' failed
There is one discusion. But no correct answer was approved by OP.
Made sure tensorflow was built from source with gcc/g++-4.8 and roi-pooling was also built with same gcc/g++ version.
My tensorflow is 1.14, gcc/g++-4.8.
How to solve the issue?

Added the following flag to makefile and all are ok now.
-L/home//lib/python2.7/site-packages/tensorflow -ltensorflow_framework

Related

Python libraries being incompatible with each other

I am trying to reproduce a piece of code source for Image Segmentation which involves the use of the
keras
and
segmentation-models
libraries.
I was able to run it in another PC running Python 3.9 and tensorflow==2.10.0, keras==2.10.0, segmentation-models==1.0.0. However, when I am trying to reproduce it on my PC with tensorflow==2.11.0, keras==2.11.0, and segmentation-models==1.0.1, I get this error:
File "/home/dev/anaconda3/lib/python3.9/site-packages/efficientnet/__init__.py", line 71, in init_keras_custom_objects
keras.utils.generic_utils.get_custom_objects().update(custom_objects)
AttributeError: module 'keras.utils.generic_utils' has no attribute 'get_custom_objects'
Library versions seem to be consistent with what is mentioned in requirements of source.
I tried downgrading keras, tensorflow, and segmentation-models versions to the older ones (which I reckoned had worked on the earlier PC), but that again shows up further compatibility issues. On further digging, I found a link which seemed to give the right requirements. I created a new conda environment with Python==3.7.0, and have again downgraded the versions into those suggested in link. I still am getting newer issues:
(sm) dev#Turbo:/media/dev/WinD/Curious Dev B/PROJECT STAGE - II$ python3 debug.py
Using TensorFlow backend.
Segmentation Models: using `keras` framework.
Traceback (most recent call last):
File "debug.py", line 150, in <module>
model = sm.Unet(BACKBONE, classes=n_classes, activation=activation)
File "/home/dev/anaconda3/envs/sm/lib/python3.7/site-packages/segmentation_models/__init__.py", line 34, in wrapper
return func(*args, **kwargs)
File "/home/dev/anaconda3/envs/sm/lib/python3.7/site-packages/segmentation_models/models/unet.py", line 226, in Unet
**kwargs,
File "/home/dev/anaconda3/envs/sm/lib/python3.7/site-packages/segmentation_models/backbones/backbones_factory.py", line 103, in get_backbone
model = model_fn(*args, **kwargs)
File "/home/dev/anaconda3/envs/sm/lib/python3.7/site-packages/classification_models/models_factory.py", line 78, in wrapper
return func(*args, **new_kwargs)
File "/home/dev/anaconda3/envs/sm/lib/python3.7/site-packages/efficientnet/model.py", line 538, in EfficientNetB3
**kwargs)
File "/home/dev/anaconda3/envs/sm/lib/python3.7/site-packages/efficientnet/model.py", line 368, in EfficientNet
img_input = layers.Input(shape=input_shape)
File "/home/dev/anaconda3/envs/sm/lib/python3.7/site-packages/keras/engine/topology.py", line 1439, in Input
input_tensor=tensor)
File "/home/dev/anaconda3/envs/sm/lib/python3.7/site-packages/keras/legacy/interfaces.py", line 87, in wrapper
return func(*args, **kwargs)
File "/home/dev/anaconda3/envs/sm/lib/python3.7/site-packages/keras/engine/topology.py", line 1301, in __init__
name = prefix + '_' + str(K.get_uid(prefix))
File "/home/dev/anaconda3/envs/sm/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 63, in get_uid
graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
I am unsure as to what went wrong here, the code worked six months ago. Now I am unable to run the same code, probably due to version changes of libraries. But at least it should have worked with the older versions that I myself used earlier, or at least with what link says.

How to solve **TypeError : expected str, bytes or os.PathLike object, not WindowsPath** when importing matplotlib to python

I am trying use matplotlib within Autodesk Revit software from the PyRevit Project
In this project, Pyrevit brings an embedded CPython interpreter (3.8.5) to Revit.
Until now, I've managed to import some packages (e.g. numpy, pandas), but unfortunately import matplotlib has been a big challenge.
When I try to import matplotlib, I got the following error:
CPython Traceback:
TypeError : expected str, bytes or os.PathLike object, not WindowsPath
File "C:\Users\carlo\pyproj\bimenv\Lib\site-packages\matplotlib\__init__.py", line 886, in <module>
rcParamsDefault = _rc_params_in_file(
File "C:\Users\carlo\pyproj\bimenv\Lib\site-packages\matplotlib\__init__.py", line 789, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
File "contextlib.py", line 113, in __enter__
File "C:\Users\carlo\pyproj\bimenv\Lib\site-packages\matplotlib\__init__.py", line 765, in _open_file_or_url
fname = os.path.expanduser(fname)
File "ntpath.py", line 293, in expanduser
...\matplotlib_init_.py
File ntpath.py
Doing the same, import matplotlib, from the Python 3.8.5 in the command line it works without any problem.
enter image description here
Thank you in advance for any suggestion from your side to solve this issue.

onnxruntime: Given model could not be parsed while creating inference session. Error message: Protobuf parsing failed

According to the example code mentioned below the library. I have followed the example code but it didn't work.
[Library] https://github.com/notAI-tech/NudeNet/
Code
from nudenet import NudeClassifier
import onnxruntime
classifier = NudeClassifier()
classifier.classify('/home/coremax/Downloads/DETECTOR_AUTO_GENERATED_DATA/IMAGES/3FEF7B75-3823-4153-8490-87483AAC6ABC'
'.jpg')
I have also followed the previous solution on StackOverflow but it didn't work
Error on running Super Resolution Model from ONNX
Traceback (most recent call last):
File "/snap/pycharm-community/276/plugins/python-ce/helpers/pydev/pydevd.py", line 1491, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/snap/pycharm-community/276/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/coremax/Documents/NudeNet/main.py", line 3, in <module>
classifier = NudeClassifier()
File "/home/coremax/Documents/NudeNet/nudenet/classifier.py", line 37, in __init__
self.nsfw_model = onnxruntime.InferenceSession(model_path)
File "/home/coremax/anaconda3/envs/AdultNET/lib/python3.6/site-packages/onnxruntime/capi/session.py", line 158, in __init__
self._load_model(providers or [])
File "/home/coremax/anaconda3/envs/AdultNET/lib/python3.6/site-packages/onnxruntime/capi/session.py", line 166, in _load_model
True)
RuntimeError: /onnxruntime_src/onnxruntime/core/session/inference_session.cc:238 onnxruntime::InferenceSession::InferenceSession(const onnxruntime::SessionOptions&, const onnxruntime::Environment&, const string&) status.IsOK() was false. Given model could not be parsed while creating inference session. Error message: Protobuf parsing failed.
I know it is too late but hope this helps someone build a very useful software.
why it fails
the error is that for NudeClassifier to work it has to download the onnx model from this link
but github now requires you to be logged in to download any file so the constructor for the NudeClassifier fails as it tries to download this model
Solution
create a folder in your user's home folder with the name .NudeNet/
download the model from this link
save the model in the folder you created in step one
you should now have the model at the following path ~/.NudeNet/classifier_model.onnx
now you're ready to go good luck!

SentencePiece in Google Colab

I want to use sentencepiece, from https://github.com/google/sentencepiece in a Google Colab project where I am training an OpenNMT model. I'm a little confused with how to set up the sentencepiece binaries in Google Colab. Do I need to build with cmake?
When I try and install using pip install sentencepiece and try to include sentencepiece in my "transforms" in my script, I get this following error
After running this script (matched from the OpenNMT translation tutorial)
!onmt_build_vocab -config en-sp.yaml -n_sample -1
I get:
Traceback (most recent call last):
File "/usr/local/bin/onmt_build_vocab", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/dist-packages/onmt/bin/build_vocab.py", line 63, in main
build_vocab_main(opts)
File "/usr/local/lib/python3.7/dist-packages/onmt/bin/build_vocab.py", line 32, in build_vocab_main
transforms = make_transforms(opts, transforms_cls, fields)
File "/usr/local/lib/python3.7/dist-packages/onmt/transforms/transform.py", line 176, in make_transforms
transform_obj.warm_up(vocabs)
File "/usr/local/lib/python3.7/dist-packages/onmt/transforms/tokenize.py", line 110, in warm_up
load_src_model.Load(self.src_subword_model)
File "/usr/local/lib/python3.7/dist-packages/sentencepiece/__init__.py", line 367, in Load
return self.LoadFromFile(model_file)
File "/usr/local/lib/python3.7/dist-packages/sentencepiece/__init__.py", line 171, in LoadFromFile
return _sentencepiece.SentencePieceProcessor_LoadFromFile(self, arg)
TypeError: not a string
Below is how my script is written. I'm not sure what the not a string is coming from.
## Where the samples will be written
save_data: en-sp/run/example
## Where the vocab(s) will be written
src_vocab: en-sp/run/example.vocab.src
tgt_vocab: en-sp/run/example.vocab.tgt
## Where the model will be saved
save_model: drive/MyDrive/Europarl/model/model
# Prevent overwriting existing files in the folder
overwrite: False
# Corpus opts:
data:
europarl:
path_src: train_europarl-v7.es-en.es
path_tgt: train_europarl-v7.es-en.en
transforms: [sentencepiece, filtertoolong]
weight: 1
valid:
path_src: dev_europarl-v7.es-en.es
path_tgt: dev_europarl-v7.es-en.en
transforms: [sentencepiece]
skip_empty_level: silent
world_size: 1
gpu_ranks: [0]
...
EDIT: So I went ahead and Googled the issue more and found a google colab project that built sentencepiece using cmake here https://colab.research.google.com/github/mymusise/gpt2-quickly/blob/main/examples/gpt2_quickly.ipynb#scrollTo=dDAup5dxDXZW. However, even after building using cmake, I'm still getting this issue.
To fix this issue, I had to filter and tokenize my dataset and then train with sentencepiece. I used the scripts from this helpful source: https://github.com/ymoslem/MT-Preparation to do everything and now my model is training!

Is there another library I have missed before running chatterbot?

I've tried to create a chatbot program using the chatterbot library. It produced some errors which beat all attempts to resolve. Finally, I went to the chatterbot documentation online and copy/pasted the first example chatterbot code and run it in my editor. This produced the same errors. So I want to know if there is some library I have missed perhaps, what that library is and the version of the library to install?
I've run the example code from https://chatterbot.readthedocs.io/en/stable/examples.html Simple Example (as found below). It has produced the same errors.
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
# Create a new chat bot named Charlie
chatbot = ChatBot('Charlie')
trainer = ListTrainer(chatbot)
trainer.train([
"Hi, can I help you?",
"Sure, I'd like to book a flight to Iceland.",
"Your flight has been booked."
])
# Get a response to the input text 'I would like to book a flight.'
response = chatbot.get_response('I would like to book a flight.')
print(response)
I expect to have a prompt at the terminal that allows input and produces a response. I got a list of error instead.
Traceback (most recent call last):
File "/Users/ikwame.amofa/PycharmProjects/trychat/main.py", line 3, in <module>
from chatterbot import ChatBot
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/__init__.py", line 4, in <module>
from .chatterbot import ChatBot
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/chatterbot.py", line 2, in <module>
from chatterbot.storage import StorageAdapter
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/storage/__init__.py", line 1, in <module>
from chatterbot.storage.storage_adapter import StorageAdapter
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/storage/storage_adapter.py", line 3, in <module>
from chatterbot.tagging import PosHypernymTagger
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/tagging.py", line 4, in <module>
from chatterbot.tokenizers import get_sentence_tokenizer
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/tokenizers.py", line 4, in <module>
from chatterbot.corpus import load_corpus, list_corpus_files
File "/Users/ikwame.amofa/PycharmProjects/trychat/venv/lib/python3.7/site-packages/chatterbot/corpus.py", line 5, in <module>
from chatterbot_corpus.corpus import DATA_DIRECTORY
ModuleNotFoundError: No module named 'chatterbot_corpus'
First of all, put your error message in a code tag,
Secondly, you forgot to install the library. Install it using:
pip install chatterbot-coprus