How to use transform_graph to optimize Tensorflow model - python

I used to use the optimize_for_inference library in optimizing frozen Tensorflow models. However, I have read from different sources that Tensorflow no longer supports it.
I came across transform_graph, and its documentation is found here: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms#strip_unused_nodes
At first, I ran into errors and found out that I need to install Tensorflow from source (https://www.tensorflow.org/install/install_sources#install_the_pip_package) instead of using PIP.
I already re-installed Tensorflow from source, and ran this code in bash (/tensorflor/tensorflow dir):
bazel build tensorflow/tools/graph_transforms:transform_graph
bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph=tensorflow_inception_graph.pb \
--out_graph=optimized_inception_graph.pb \
--inputs='Mul' \
--outputs='softmax' \
--transforms='
strip_unused_nodes(type=float, shape="1,299,299,3")
fold_constants(ignore_errors=true)
fold_batch_norms
fold_old_batch_norms
round_weights(num_steps=256)'
And ran to again this error:
-bash: bazel-bin/tensorflow/tools/graph_transforms/transform_graph: No such file or directory
What seems to be the problem?

That is weird.
The code I write below is to install and using the transform_graph in CentOS7.
yum install epel-release
yum update
yum install patch
curl https://copr.fedorainfracloud.org/coprs/vbatts/bazel/repo/epel-7/vbatts-bazel-epel-7.repo -o /etc/yum.repos.d/vbatts-bazel-epel-7.repo
yum install bazel
curl -L -O https://github.com/tensorflow/tensorflow/archive/v1.8.0.tar.gz
cd tensorflow-1.8.0
./configure # interactive!
bazel build tensorflow/tools/graph_transforms:summarize_graph
bazel-bin/tensorflow/tools/graph_transforms/summarize_graph
After you install the Tensorflow by source code and finish the configure, the bazel codes should be working.
The error from you environment is occurred when you didn't finish the install the Tensorflow by source code, or you ran the script in wrong path.
Please check the configure step, path of the Tensorflow root.

Related

How to resolve CMake Error: Could not find a package configuration file provided by "boost_python3"

I tried to install the lanelet2 library according to the github installation guide at https://github.com/fzi-forschungszentrum-informatik/Lanelet2.
When I perform catkin build I get the following error:
Errors << lanelet2_python:cmake /home/student/catkin_ws/logs/lanelet2_python/build.cmake.000.log
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake:117 (find_package):
Could not find a package configuration file provided by "boost_python3"
(requested version 1.71.0) with any of the following names:
boost_python3Config.cmake
boost_python3-config.cmake
Add the installation prefix of "boost_python3" to CMAKE_PREFIX_PATH or set
"boost_python3_DIR" to a directory containing one of the above files. If
"boost_python3" provides a separate development package or SDK, be sure it
has been installed.
My OS is Ubuntu 20.04 with ROS noetic. The build is performed inside a venv with Python Version 3.8.10.
The command python is pointing to python3. I've also installed the following dependencies:
sudo apt-get install ros-noetic-rospack ros-noetic-catkin ros-noetic-mrt-cmake-modules
sudo apt-get install libboost-dev libeigen3-dev libgeographic-dev libpugixml-dev libpython3-dev libboost-python-dev python3-catkin-tools
Does someone have an idea how to resolve this error?
See neutrinoyu's comment at https://github.com/ethz-asl/kalibr/issues/368#issuecomment-651726289
/kalibr/Schweizer-Messer/numpy_eigen/cmake/add_python_export_library.cmake:89
change
list(APPEND BOOST_COMPONENTS python3)
to
list(APPEND BOOST_COMPONENTS python)

could able to run demo sound classification application in openvino

To run sound classication demo in openvino,
I have followed below steps:
cd /opt/intel/openvino_2021/install_dependencies
sudo -E ./install_openvino_dependencies.sh
for env setting: source /opt/intel/openvino_2021/bin/setupvars.sh
cd /opt/intel/openvino_2021/deployment_tools/model_optimizer/install_prerequisites
sudo ./install_prerequisites.sh
git clone https://github.com/openvinotoolkit/open_model_zoo.git.
Then I placed the cloned repo in the deployment_tools directory.
sudo python3 /opt/intel/openvino_2021/deployment_tools/open_model_zoo/tools/downloader/downloader.py --name aclnet
sudo python3 /opt/intel/openvino_2021/deployment_tools/open_model_zoo/tools/downloader/converter.py --name aclnet
Here I got error:
/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.4) or chardet (3.0.4) doesn't match a supported version!
warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Unable to locate Model Optimizer. Use --mo or run setupvars.sh/setupvars.bat from the OpenVINO toolkit.
Here aclent model downloaded and gives .onnx in public folder. now how to convert .onnx file to ir format(xml and bin format)?
I followed below coomand too but still I get same error
sudo python3 ./mo.py --input_model ~/public/aclnet/aclnet_des_53.onnx --output_dir ~/public/aclnet
https://docs.openvinotoolkit.org/latest/omz_demos_sound_classification_demo_python.html
Please can anyone help on this?
This error happened because the script attempts to locate Model Optimizer using the environment variables set by the OpenVINO™ toolkit's setupvars.sh script. You can override this heuristic with the --mo option:
python3 converter.py --mo my/openvino/path/model_optimizer/mo.py --name aclnet

No executable found for solver 'glpk' on pyomo

I have an optimization model written on pyomo (Python 3.7/Ubuntu 18.04) and using
from pyomo.opt import SolverFactory
opt = SolverFactory("gurobi")
results = opt.solve(model)
It works exactly as it should. However, when I try to use glpk as the solver, I get the following error:
ApplicationError: No executable found for solver 'glpk'.
Importing the package also returns an error:
ModuleNotFoundError: No module named 'glpk'
But when I do conda list on the terminal, I get this information for glpk package:
glpk 4.65 he80fd80_1002 conda-forge
How can I fix this?
It's been quite some time, but this might help future users with the same issue.
I had the same issue, while trying to run pyomo along with glpk as a solver on a debian based container image.
I was getting the following error: Could not locate the 'glpsol' executable, which is required for solver 'glpk'. ApplicationError: No executable found for solver 'glpk'.
After installing glpk-utils along with glpk, my python script executed successfully.
part of my working docker file can be found below
FROM python:3.10-slim-bullseye
WORKDIR /opt/app
RUN apt update && apt install -y gcc libglpk-dev glpk-utils
COPY requirements.txt /opt/app/requirements.txt
RUN pip install --upgrade pip && pip install -r requirements.txt
# requirements.txt contents (Pyomo==6.4.2 and glpk==0.4.6 among others)
COPY . .
# utilizing .dockerignore to leave files/folders out of the container image
CMD [ "python", "main.py" ]
On terminal, trying running which glpsol.
This ought to return a path to your glpsol executable. I am guessing you won't get a result. If that's the case you need to add the location of 'glpsol' to your PATH variable. You should be able to find it by seaching for where the 'glpk' package was installed. It should be in the 'bin' folder. Hopefully.

AttributeError: module 'cv2.cv2' has no attribute 'freetype' in OpenCV

I'm using a docker container with minimal packages installed. I installed opencv-contrib-python using pip3 install opencv-contrib-python and it installed the latest build 4.1.025 and have verified that it was running and my program was ok with it. However, now I need the freetype module but when I try:
import cv2 as cv
ft = cv.freetype.createFreeType2()
It throws the AttributeError as in the title. I tried reinstalling different versions namely: 4.0.0.21, 4.0.1.23, 4.0.1.24, 4.1.0.25 to no avail. I am using the headless version mainly(since I'm using docker and I don't need any gui functionality). Another thing I found out was not all the modules can be imported I have tried (ccalib, tracking, sfm, xobjdetect etc) and these modules throw the same error. Does this mean that some modules are not available through the pip3 installation? Thank you.
I'm pretty late to this issue, but I hope this helps someone.
I've added links to an easy to follow guide at the bottom.
Here are the essential steps, you'd need to follow:
Install CMake & Git (if you haven't already)
In a folder git vcpkg (git clone https://github.com/Microsoft/vcpkg.git)
Install freetype and harfbuzz using vcpkg commandline
bootstrap-vcpkg.bat
vcpkg install freetype:x64-windows
vcpkg install harfbuzz:x64-windows
Locate vcpkg.cmake file and note down its path
Ensure C++ build tools are installed in Visual Studio 19
Download and extract OpenCV & OpenCV contrib
Create a empty dir called "build" inside the extracted OpenCV
Modify CMakeLists.txt inside freetype module folder in opencv-contrib (Link)
Modify and run the following command:
cmake -G "Visual Studio 16 2019"
-B D:\code\downloads\opencv-4.3.0\build
-D BUILD_NEW_PYTHON_SUPPORT=ON
-D BUILD_PYTHON_SUPPORT=ON
-D BUILD_opencv_python3=yes
-D PYTHON_DEFAULT_EXECUTABLE=D:\anaconda3\python.exe
-D OPENCV_SKIP_PYTHON_LOADER=ON
-D PYTHON_LIBRARY=D:\anaconda3\libs\python36.lib
-D OPENCV_EXTRA_MODULES_PATH=D:\code\downloads\opencv_contrib-4.3.0\modules
-D OPEN_CV_FORCE_PYTHON_LIBS=yes
-D CMAKE_TOOLCHAIN_FILE=D:\code\downloads\vcpkg\scripts\buildsystems\vcpkg.cmake
Use CMake GUI to make changes referenced at this link (LINK)
Once necessary changes are made, click Configure and Generate.
Building DEBUG & RELEASE versions using Visual Studio 19
Test the installation by importing cv2.freetype from the environment you setup.
There's a comprehensive written guide over here:
https://github.com/BabaGodPikin/Build-OpenCv-for-Python-with-Extra-Modules-Windows-10
Also, I've made a video inspired by the same tutorial, which can be found here:
https://youtu.be/9YUDx3qzKwY
I would recommend watching the video and keeping this guide open on the side.
Cheers!

Installing Python-Tesseract on a Linux system

I am having trouble installing python-tesseract on my linux system. I've been using this tutorial:
http://delimitry.blogspot.be/2014/10/installing-tesseract-for-python-on.html
The error I get is:
File does not exist:['/usr/include/tesseract/capi.h', '/usr/local/include/tesseract/capi.h', '/opt/include/tesseract/capi.h', '/opt/local/include/tesseract/capi.h']
root#opencv:/home/philipp/python-tesseract#
When running python setup.py clean in /python-tesseract after following the rest of the instructions in order.
Running linux 3.2.0-4-amd64 on this system.
Whereis tesseract-ocr returns:
/usr/share/tesseract-ocr
Whereis leptonica returns:
/usr/include/leptonica
Whereis tesseract returns:
tesseract: /usr/bin/tesseract /usr/bin/X11/tesseract /usr/include/tesseract/ /usr/share/man/man1/tesseract.1.gz
I've also tried running a few other tutorials/guides to install python-tesseract that have returned other errors such as, missing libleptonica then missing libc6 but I havn't investigated these as much. Just tried to see if any other guides worked immidiately.
Also, when I run tesseract in the terminal it works, but import tesseract does not.
What am I doing wrong? How can I fix this and install python-tesseract?
I think this way could work for you:
1- download python-tesseract_0.9-0.5ubuntu3_vivid_amd64.deb from here
2- install gdebi-core
sudo apt-get install gdebi-core
3- install python-tesseract_0.9-0.5ubuntu3_vivid_amd64.deb with gdebi
sudo gdebi python-tesseract_0.9-0.5ubuntu2_i386.deb

Categories