Spaces:
Build error
Build error
Added openpose installation
#1
by
Jdizon - opened
pages/Pose_And_Motion_Based_SVM_Model.py
CHANGED
|
@@ -1,16 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import cv2
|
| 2 |
-
import pyopenpose as op
|
| 3 |
import numpy as np
|
| 4 |
import joblib
|
| 5 |
import tempfile
|
| 6 |
import streamlit as st
|
| 7 |
import subprocess
|
|
|
|
| 8 |
from os.path import basename, splitext, exists
|
| 9 |
from sklearn.preprocessing import StandardScaler
|
| 10 |
|
|
|
|
| 11 |
# Streamlit app header
|
| 12 |
st.title("Pose-Based One-Class SVM Model")
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
#==========================IMPORTING MODELS==========================
|
| 15 |
pose_scaler = joblib.load('pages/pose_scaler.pkl') # Standard scaler for pose data
|
| 16 |
ocsvm_pose = joblib.load('pages/ocsvm_pose_model-4.pkl') # Pre-trained One-Class SVM for pose
|
|
|
|
| 1 |
+
#pip install pyopenpose
|
| 2 |
+
|
| 3 |
+
#===================IMPORT LIBRARIES==================================
|
| 4 |
import cv2
|
| 5 |
+
#import pyopenpose as op
|
| 6 |
import numpy as np
|
| 7 |
import joblib
|
| 8 |
import tempfile
|
| 9 |
import streamlit as st
|
| 10 |
import subprocess
|
| 11 |
+
import os
|
| 12 |
from os.path import basename, splitext, exists
|
| 13 |
from sklearn.preprocessing import StandardScaler
|
| 14 |
|
| 15 |
+
|
| 16 |
# Streamlit app header
|
| 17 |
st.title("Pose-Based One-Class SVM Model")
|
| 18 |
|
| 19 |
+
#==========================INSTALLATIONS=====================================
|
| 20 |
+
# Install OpenPose
|
| 21 |
+
def install_openpose():
|
| 22 |
+
git_repo_url = 'https://github.com/CMU-Perceptual-Computing-Lab/openpose.git'
|
| 23 |
+
project_name = splitext(basename(git_repo_url))[0]
|
| 24 |
+
|
| 25 |
+
# Remove any existing openpose folder
|
| 26 |
+
if os.path.exists("openpose"):
|
| 27 |
+
subprocess.run(["rm", "-rf", "openpose"])
|
| 28 |
+
|
| 29 |
+
# Install CMake 3.17 for CUDA10
|
| 30 |
+
if not exists(project_name):
|
| 31 |
+
st.write("Installing CMake and OpenPose dependencies...")
|
| 32 |
+
|
| 33 |
+
subprocess.run(["wget", "-q", "https://cmake.org/files/v3.17/cmake-3.17.2-Linux-x86_64.tar.gz"])
|
| 34 |
+
subprocess.run(["tar", "xfz", "cmake-3.17.2-Linux-x86_64.tar.gz", "--strip-components=1", "-C", "/usr/local"])
|
| 35 |
+
|
| 36 |
+
# Clone OpenPose repository
|
| 37 |
+
subprocess.run(["git", "clone", "--depth", "1", git_repo_url])
|
| 38 |
+
|
| 39 |
+
# Update the CMakeLists.txt for compatibility
|
| 40 |
+
subprocess.run([
|
| 41 |
+
"sed", "-i",
|
| 42 |
+
r"s/execute_process(COMMAND git checkout --recursive master WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}\/3rdparty\/caffe)/execute_process(COMMAND git checkout f019d0dfe86f49d1140961f8c7dec22130c83154 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}\/3rdparty\/caffe)/g",
|
| 43 |
+
"openpose/CMakeLists.txt"
|
| 44 |
+
])
|
| 45 |
+
|
| 46 |
+
subprocess.run(["cd", "openpose", "&&", "git", "submodule", "update", "--init", "--recursive", "--remote"])
|
| 47 |
+
|
| 48 |
+
# Install system dependencies
|
| 49 |
+
dependencies = [
|
| 50 |
+
"libatlas-base-dev", "libprotobuf-dev", "libleveldb-dev", "libsnappy-dev",
|
| 51 |
+
"libhdf5-serial-dev", "protobuf-compiler", "libgflags-dev",
|
| 52 |
+
"libgoogle-glog-dev", "liblmdb-dev", "opencl-headers", "ocl-icd-opencl-dev",
|
| 53 |
+
"libviennacl-dev"
|
| 54 |
+
]
|
| 55 |
+
subprocess.run(["apt-get", "-qq", "install", "-y"] + dependencies)
|
| 56 |
+
|
| 57 |
+
# Build OpenPose
|
| 58 |
+
os.makedirs("openpose/build", exist_ok=True)
|
| 59 |
+
subprocess.run(["cmake", ".."], cwd="openpose/build")
|
| 60 |
+
subprocess.run(["make", "-j", str(os.cpu_count())], cwd="openpose/build")
|
| 61 |
+
|
| 62 |
+
st.write("OpenPose installation complete.")
|
| 63 |
+
|
| 64 |
+
# Call the installation function
|
| 65 |
+
install_openpose()
|
| 66 |
+
|
| 67 |
+
# Copy the models.zip file to the correct directory and unzip
|
| 68 |
+
def copy_and_unzip_models():
|
| 69 |
+
if os.path.exists("/content/drive/MyDrive/models.zip"):
|
| 70 |
+
subprocess.run(["cp", "/content/drive/MyDrive/models.zip", "/content/"])
|
| 71 |
+
subprocess.run(["unzip", "-o", "models.zip", "-d", "openpose"])
|
| 72 |
+
|
| 73 |
+
st.write("Models copied and unzipped successfully.")
|
| 74 |
+
else:
|
| 75 |
+
st.write("Model file not found. Ensure it’s located in /content/drive/MyDrive/models.zip")
|
| 76 |
+
|
| 77 |
+
# Call the function to copy and unzip models
|
| 78 |
+
copy_and_unzip_models()
|
| 79 |
+
|
| 80 |
+
|
| 81 |
#==========================IMPORTING MODELS==========================
|
| 82 |
pose_scaler = joblib.load('pages/pose_scaler.pkl') # Standard scaler for pose data
|
| 83 |
ocsvm_pose = joblib.load('pages/ocsvm_pose_model-4.pkl') # Pre-trained One-Class SVM for pose
|