-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Installation on Colab or Windows #140
Comments
Hi, sorry I'm away from the computer for a week, I'll have a look next week! |
Hi, thanks for your immediate feedback. |
Hi, I can choose one of three Colab runtime environments: CPU, T4 GPU, TPU v2-8 On Windows display_detection=false disabled the cv2.imshow(...): poseEstimation.py |
Hi @jtoerber, apologies for the delay. Glad to see you managed to run it within Windows! You set all the visualization options to false, which is what I would have first suggested. This is good if everything runs smoothly, but in case of challenging capture, you may want to be able to show the images and plots. Does it only fail with poseEstimation (which uses cv2.imshow()), or does it also fail with plots (in calibration, synchronization, and filtering)? If it only fails with poseEstimation and you want to display detection, then check the location of your installation with try:
from google.colab.patches import cv2_imshow
COLAB = True
except ImportError:
COLAB = False
def show_img(img_name, img):
'''
Display an image in Colab or a local environment
'''
if COLAB:
cv2_imshow(img) # Use cv2_imshow in Colab
else:
cv2.imshow(img_name, img) In poseEstimation.py, you can add: from Pose2Sim.common import show_img And you can replace both occurrences of cv2.imshow with: show_img(f"Pose Estimation {os.path.basename(video_path)}", img_show)
# AND
show_img(f"Pose Estimation {os.path.basename(image_folder_path)}", img_show) Whether this works or fails, can you tell me? I would like to enable this feature in the next release |
Hi, thanks for the code snippets. First I did this according to https://stackoverflow.com/questions/53581278/test-if-notebook-is-running-on-google-colab: try:
import google.colab
IN_COLAB = True
except:
IN_COLAB = False
print(IN_COLAB)
IN_COLAB=None
print(IN_COLAB)
import sys
IN_COLAB = 'google.colab' in sys.modules
print(IN_COLAB)
if 'google.colab' in str(get_ipython()):
print('Running on CoLab')
else:
print('Not running on CoLab')
import os
if os.getenv("COLAB_RELEASE_TAG"):
print("Running in Colab")
print(os.getenv("COLAB_RELEASE_TAG"))
else:
print("NOT in Colab")
import os
if 'COLAB_GPU' in os.environ:
print("I'm running on Colab")
# CPU: set but empty, T4 GPU: 1, TPU v2-8:?
print("Hello:" + os.getenv("COLAB_GPU") + ":Hello")
import os
if os.path.exists('/colabtools'):
print("/colabtools exists")
else:
print("/colabtools does not exist") with the following output on CPU(!): On a T4 GPU I get the same except: import pkgutil
mediapipe_loader = pkgutil.find_loader('mediapipe') Regarding the imshow problem: mpl.use('qt5agg') In Colab executing %matplotlib --list gives me on a CPU-Colab-Runtime: # mpl.use('qt5agg') then did the additional function in common.py and changes in poseEstimation.py # ...
%matplotlib inline
# ... , which should help even if the display_... Parameters are set to true. Currently I am working in Demo_SinglePerson so no calibration needed, but mpl.use('qt5agg') is also executed for Calibration and leads to an "qt5agg"-error: Addition: poseEstimation took about 2:30 per Video on a CPU-Colab-Runtime. Will try the other ones as well. At least on the free Colab, every time you use it, you have to set everything up. But you are able to mount a Google-Drive, where you maybe should put your conda environment, if you have enough space. You may even share Colab-Notebooks as in this sample: |
Hi, it is a bit hard to read, could you put the code inside back-quotes and indent it?
|
Done. |
Thanks for the formatting! |
Hi, All calls except Pose2Sim.kinematics() could be executed. The last one gives: Addition: print(torch.cuda.is_available(), ort.get_available_providers()) gave on CPU, T4 GPU and TPU always False. With above mentioned environment variables you may detect COLAB and/or COLAB with CPU, GPU or TPU. Proposal: is one way of working with Colab reducing poseEstimation running times. Changes attached. I consider this as an enhancement. |
Okay, I get it, thanks for that! Would you be mind proposing a pull request so that changes are easier to track? I don't have time for it right now, but I'll try to check what's wrong with OpenSim and make kinematics() work. |
Do you think you could have made a mistake somewhere? |
Yes. Call Pose2Sim.kinematics and see what happens.Am 06.11.2024 16:55 schrieb David PAGNON ***@***.***>:
Did you manage to install opensim? I just did within Colab with the instruction from your link and it works:
!pip install -q condacolab
import condacolab
condacolab.install()
!conda install -c opensim-org opensim -y
import opensim
torch and CUDA are installed by default on Colab when running a GPU session, so you should not have to install torch and this should return True
import torch
print(torch.cuda.is_available())
I then installed onnxruntime-gpu, and the following returns ['TensorrtExecutionProvider', 'CUDAExecutionProvider', 'CPUExecutionProvider']
import onnxruntime as ort
print(ort.get_available_providers())
Do you think you could have made a mistake somewhere?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Can you share your Colab file? |
ModuleNotFoundError Traceback (most recent call last) [](https://localhost:8080/#) in () 15 # Pose2Sim.filtering() 16 # Pose2Sim.markerAugmentation() ---> 17 Pose2Sim.kinematics() 18 19 # gives: ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt' interactive framework, as 'headless' is currently running 1 frames [/usr/local/lib/python3.10/site-packages/Pose2Sim/kinematics.py](https://localhost:8080/#) in 43 from anytree import PreOrderIter 44 ---> 45 import opensim 46 47 from Pose2Sim.common import natural_sort_key, euclidean_distance, trimmed_mean ModuleNotFoundError: No module named 'opensim' --------------------------------------------------------------------------- NOTE: If your import is failing due to a missing package, you can manually install dependencies using either !pip or !apt. To view examples of installing some common dependencies, click the "Open Examples" button below. or with a little bit of color: |
So I tried it, your main issue is that condacolab apparently cannot create any virtual environement. Good news though, you don't need any. I'm skipping the part where you install the packages to your Google Drive, it is good but not mandatory. I also don't install the GPU libraries below but you should do it. This works (don't worry about the potential error message): !pip install -q condacolab
import condacolab
condacolab.install()
!conda install -c opensim-org opensim -y
pip install Pose2Sim And then there are plenty of ways you can run Pose2Sim. Here I disable all displays but of course, it is better if you make them work: from Pose2Sim import Pose2Sim
import os
import toml
sed -i "/mpl\.use('qt5agg')/d" /usr/local/lib/python3.10/site-packages/Pose2Sim/common.py # delete 'qt5agg' line
project_dir = '/usr/local/lib/python3.10/site-packages/Pose2Sim/Demo_SinglePerson'
config_dict = toml.load(os.path.join(project_dir, 'Config.toml'))
os.chdir(project_dir)
config_dict.get("project").update({"project_dir":project_dir})
config_dict.get("pose").update({"display_detection":False})
config_dict.get("synchronization").update({"display_sync_plots":False})
config_dict.get('filtering').update({'display_figures':False})
Pose2Sim.runAll(config_dict) It should work seamlessly now! Please keep me updated. |
Note to self: the script above should work fine, but it can be improved:
If @jtoerber or anyone feels like making something it it would be awesome, otherwise I'll probably do it one day or another (but I'm way too busy right now) :) |
Hi, just accidentally found "professional" Colab Notebooks here, e.g.: with: if not IS_GOOGLE_CLOUD_NOTEBOOK:
if "google.colab" in sys.modules:
from google.colab import auth as google_auth
google_auth.authenticate_user()
# If you are running this notebook locally, replace the string below with the
# path to your service account key and run this cell to authenticate your GCP
# account.
elif not os.getenv("IS_TESTING"):
%env GOOGLE_APPLICATION_CREDENTIALS '' and sometimes a restart of the Colab Session is needed after installation, which may be automated by: if not os.getenv("IS_TESTING"):
# Automatically restart kernel after installs
import IPython
app = IPython.Application.instance()
app.kernel.do_shutdown(True) |
Dear all,
Installation of conda is a little different:
https://saturncloud.io/blog/how-to-install-conda-package-to-google-colab/
!pip install -q condacolab
import condacolab
condacolab.install()
!conda --version
import condacolab
condacolab.check()
switch in Colab to , not only in the bash executing the command
%cd /usr/local/lib/python3.10/site-packages/Pose2Sim/Demo_SinglePerson
Colab has no GUI, so we have to work headless or with a virtual GUI:
There seems to be a workaround (Xvfb):
https://colab.research.google.com/drive/1flu31ulJlgiRL1dnN2ir8wGh9p7Zij2t#scrollTo=8-AxnvAVyzQQ
!pip install pyvirtualdisplay
!apt-get install -y xvfb python-opengl ffmpeg
on Ubuntu: huggingface/deep-rl-class#275
!apt-get install -y xvfb python3-opengl ffmpeg
I then had to this code before running the Demo_SinglePerson:
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1400, 900))
display.start()
from Pose2Sim import Pose2Sim
Pose2Sim.calibration()
Pose2Sim.poseEstimation()
Pose2Sim.synchronization()
Pose2Sim.personAssociation()
Pose2Sim.triangulation()
Pose2Sim.filtering()
Pose2Sim.markerAugmentation()
Pose2Sim.kinematics()
Then I get:
DisabledFunctionError: cv2.imshow() is disabled in Colab, because it causes Jupyter sessions
to crash; see jupyter/notebook#3935.
As a substitution, consider using
from google.colab.patches import cv2_imshow
Well, It seems that then all imports would have been to be replaced. Any chances to run it headless?
Installation seemed ok. After trying Demo_SinglePerson with the provided script:
from Pose2Sim import Pose2Sim
Pose2Sim.calibration()
Pose2Sim.poseEstimation()
Pose2Sim.synchronization()
Pose2Sim.personAssociation()
Pose2Sim.triangulation()
Pose2Sim.filtering()
Pose2Sim.markerAugmentation()
Pose2Sim.kinematics()
I got:
No valid CUDA installation found: using OpenVINO backend with CPU.
Inference run on every single frame.
Using HALPE_26 model (body and feet) for pose estimation.
Mode: balanced.
Traceback (most recent call last):
File "c:\Users<osuser>.conda\envs\Pose2Sim\Lib\site-packages\Pose2Sim\Demo_SinglePerson\test.py", line 3, in
Pose2Sim.poseEstimation()
File "C:\Users<osuser>.conda\envs\Pose2Sim\lib\site-packages\Pose2Sim\Pose2Sim.py", line 238, in poseEstimation
rtm_estimator(config_dict)
File "C:\Users<osuser>.conda\envs\Pose2Sim\lib\site-packages\Pose2Sim\poseEstimation.py", line 450, in rtm_estimator
pose_tracker = PoseTracker(
File "C:\Users<osuser>.conda\envs\Pose2Sim\lib\site-packages\rtmlib\tools\solution\pose_tracker.py", line 121, in init
model = solution(mode=mode,
File "C:\Users<osuser>.conda\envs\Pose2Sim\lib\site-packages\rtmlib\tools\solution\body_with_feet.py", line 104, in init
self.det_model = YOLOX(det,
File "C:\Users<osuser>.conda\envs\Pose2Sim\lib\site-packages\rtmlib\tools\object_detection\yolox.py", line 20, in init
super().init(onnx_model,
File "C:\Users<osuser>.conda\envs\Pose2Sim\lib\site-packages\rtmlib\tools\base.py", line 43, in init
onnx_model = download_checkpoint(onnx_model)
File "C:\Users<osuser>.conda\envs\Pose2Sim\lib\site-packages\rtmlib\tools\file.py", line 149, in download_checkpoint
extract_zip(cached_file, tmp_dir)
File "C:\Users<osuser>.conda\envs\Pose2Sim\lib\site-packages\rtmlib\tools\file.py", line 28, in extract_zip
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
File "C:\Users<osuser>.conda\envs\Pose2Sim\lib\zipfile.py", line 1268, in init
self._RealGetContents()
File "C:\Users<osuser>.conda\envs\Pose2Sim\lib\zipfile.py", line 1335, in _RealGetContents
raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file
Any help or suggestions welcome.
Currently I have no own Linux machine available.
Thanks in advance.
The text was updated successfully, but these errors were encountered: