homogenus
homogenus copied to clipboard
Problems in installing and running [SOLUTION]
Greetings and thank you for this awesome project!
I got the following problem when I installed the dependencies:
error: numpy 1.16.3 is installed but numpy>=1.17 is required by {'matplotlib'}
error: numpy 1.16.3 is installed but numpy>=1.17.3 is required by {'PyWavelets'}
I resolved the problem by changing the dependencies in requirements.txt
:
numpy==1.17.3
Then I got this wall of text error when I tried to run inference:
$ python3 homogenus/tf/homogenus_infer.py -h
Traceback (most recent call last):
File "homogenus/tf/homogenus_infer.py", line 21, in <module>
import tensorflow as tf
File "/home/.../source/homogenus/.venv/lib/python3.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/.../source/homogenus/.venv/lib/python3.7/site-packages/tensorflow/python/__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/home/.../source/homogenus/.venv/lib/python3.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 15, in <module>
from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
File "/home/.../source/homogenus/.venv/lib/python3.7/site-packages/tensorflow/core/framework/node_def_pb2.py", line 15, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "/home/.../source/homogenus/.venv/lib/python3.7/site-packages/tensorflow/core/framework/attr_value_pb2.py", line 15, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "/home/.../source/homogenus/.venv/lib/python3.7/site-packages/tensorflow/core/framework/tensor_pb2.py", line 15, in <module>
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File "/home/.../source/homogenus/.venv/lib/python3.7/site-packages/tensorflow/core/framework/resource_handle_pb2.py", line 41, in <module>
serialized_options=None, file=DESCRIPTOR),
File "/home/.../source/homogenus/.venv/lib/python3.7/site-packages/google/protobuf/descriptor.py", line 560, in __new__
_message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
1. Downgrade the protobuf package to 3.20.x or lower.
2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
Then I headed to the link to check what's going on. It looks like this has something to do with tensorflow and protocol buffers. My tf version:
1.13.1
It's not 1.15.2
because I tried this PR.
My protobuf
version:
4.21.2
I have a few options:
- upgrade tensorflow to
2.x
- downgrade
protobuf
to3.20.x
or lower.
You can see the PRs for changing requirements in this repo. I didn't test them yet. This is what worked for me:
$ pip install protobuf==3.20
Collecting protobuf==3.20
Using cached protobuf-3.20.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.0 MB)
ERROR: homogenus .5 has requirement numpy==1.17.3, but you'll have numpy 1.16.3 which is incompatible.
Installing collected packages: protobuf
Attempting uninstall: protobuf
Found existing installation: protobuf 4.21.2
Uninstalling protobuf-4.21.2:
Successfully uninstalled protobuf-4.21.2
Successfully installed protobuf-3.20.0
Even though I got the warning it worked for me in the end. Test to validate this:
$ python3 homogenus/tf/homogenus_infer.py -h
usage: homogenus_infer.py [-h] [-tm TRAINED_MODEL_DIR] -ii IMAGES_INDIR -oi
OPENPOSE_INDIR [-io IMAGES_OUTDIR]
[-oo OPENPOSE_OUTDIR]
optional arguments:
-h, --help show this help message and exit
-tm TRAINED_MODEL_DIR, --trained_model_dir TRAINED_MODEL_DIR
The path to the directory holding homogenus trained
models in TF.
-ii IMAGES_INDIR, --images_indir IMAGES_INDIR
Directory of the input images.
-oi OPENPOSE_INDIR, --openpose_indir OPENPOSE_INDIR
Directory of openpose keypoints, e.g. json files.
-io IMAGES_OUTDIR, --images_outdir IMAGES_OUTDIR
Directory to put predicted gender overlays. If not
given, wont produce any overlays.
-oo OPENPOSE_OUTDIR, --openpose_outdir OPENPOSE_OUTDIR
Directory to put the openpose gendered keypoints. If
not given, it will augment the original openpose json
files.
Just for convenience, here's my setup.
- Ubuntu 20.04
- Python 3.7
I used venv, but you can do similar with conda if that rocks your boat.
python3.7 -m venv .venv
source .venv/bin/activate
$ pip freeze
absl-py==1.1.0
astor==0.8.1
cycler==0.11.0
fonttools==4.34.4
gast==0.2.2
google-pasta==0.2.0
grpcio==1.47.0
h5py==3.7.0
homogenus===.5
imageio==2.5.0
importlib-metadata==4.12.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.2
kiwisolver==1.4.3
Markdown==3.3.7
matplotlib==3.5.2
mock==4.0.3
networkx==2.6.3
numpy==1.16.3
opt-einsum==3.3.0
packaging==21.3
Pillow==9.2.0
protobuf==3.20.0
pyparsing==3.0.9
python-dateutil==2.8.2
PyWavelets==1.3.0
scikit-image==0.15.0
scikit-learn==0.20.3
scipy==1.2.1
six==1.16.0
tensorboard==1.13.1
tensorflow==1.13.1
tensorflow-estimator==1.13.0
termcolor==1.1.0
typing_extensions==4.3.0
Werkzeug==2.1.2
wrapt==1.14.1
zipp==3.8.1
You could do the same with different tensorflow versions: just downgrade protobuf
and hope for the best. I hope this helps someone else and saves them the 30 minutes I used for this :)
Then I cared to actually test the solution. Here's what happened:
$ python3 homogenus/tf/homogenus_infer.py -tm homogenus/trained_models/tf -ii samples -oi samples/openpose_keypoints/ -io out/img -oo out/pose
2022-07-14 10:28:40.039372: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA
2022-07-14 10:28:40.064846: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2496000000 Hz
2022-07-14 10:28:40.066003: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x5635f469d900 executing computations on platform Host. Devices:
2022-07-14 10:28:40.066020: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0): <undefined>, <undefined>
Restoring checkpoint homogenus/trained_models/tf/TR02_E02_It_002010.ckpt..
WARNING:tensorflow:From /home/.../source/homogenus/.venv/lib/python3.7/site-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file APIs to check for files with this prefix.
Traceback (most recent call last):
File "homogenus/tf/homogenus_infer.py", line 175, in <module>
images_outdir=ps.images_outdir, openpose_outdir=ps.openpose_outdir)
File "homogenus/tf/homogenus_infer.py", line 72, in predict_genders
from homogenus.tools.image_tools import put_text_in_image, fontColors, read_prep_image, save_images
ModuleNotFoundError: No module named 'homogenus'
Ok I was able to fix all my problems. Here's how:
My nstallation was probably OK after the edits below. I, however, created the edits here: https://github.com/nghorbani/homogenus/pull/15
I had to change the requirements.txt
, then install the package by
python3 setup.py install
Then create a new script called test.py
(or whatever) and import everything correctly. I assume that the problems in upstream come from:
- Missing requirement for opencv (install it:
pip install opencv-python
) - imports not working (maybe
homogenus
was not installed correctly on my system?) - Some requirements being old/inaccurate/changed as software packages tend to change over time
The command I used for finally running a successful test (in homogenus
root):
$ python3 test.py -tm homogenus/trained_models/tf -ii ./samples/images/ -oi ./samples/openpose_keypoints/ -io out/img -oo out/pose
@Hyrtsi can you help me with this? I'm trying to install this for dependecy to smplx and env is tensorflow 2.14 cuda 11.8 but I don't know how to make it work for this latest development.