Skip to content

Instantly share code, notes, and snippets.

@deepwilson
Created October 9, 2024 11:04
Show Gist options
  • Save deepwilson/b9521196d5ef78a8e8ccc0c77c544898 to your computer and use it in GitHub Desktop.
Save deepwilson/b9521196d5ef78a8e8ccc0c77c544898 to your computer and use it in GitHub Desktop.
import os
import subprocess
import shutil
def run_command(command, description):
print(f"[INFO] {description}...")
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, error = process.communicate()
if process.returncode != 0:
print(f"[ERROR] Failed to execute: {command}")
print(f"[ERROR] Error message: {error.decode('utf-8')}")
else:
print(f"[SUCCESS] {description}")
return output.decode('utf-8')
# Step 1: Remove the existing directory if it exists before cloning
if os.path.exists("mtcnn-landmark-detector"):
print("[INFO] Removing existing 'mtcnn-landmark-detector' directory...")
shutil.rmtree("mtcnn-landmark-detector")
print("[SUCCESS] Removed existing 'mtcnn-landmark-detector' directory")
# Step 2: Clone the repository
run_command("git clone https://github.com/adumrewal/mtcnn-landmark-detector.git", "Cloning the repository")
# Step 3: Remove the existing directory if it exists
if os.path.exists("mtcnn_landmark_detector"):
print("[INFO] Removing existing 'mtcnn_landmark_detector' directory...")
shutil.rmtree("mtcnn_landmark_detector")
print("[SUCCESS] Removed existing 'mtcnn_landmark_detector' directory")
# Step 4: Rename the directory
print("[INFO] Renaming 'mtcnn-landmark-detector' to 'mtcnn_landmark_detector'...")
os.rename("mtcnn-landmark-detector", "mtcnn_landmark_detector")
print("[SUCCESS] Renamed directory")
# Step 5: Change directory to 'mtcnn_landmark_detector'
os.chdir("mtcnn_landmark_detector")
# Step 6: Move files from 'model' directory to root if 'model' directory exists
if os.path.exists("model"):
print("[INFO] Moving files from 'model' directory to root...")
for item in os.listdir("model"):
shutil.move(os.path.join("model", item), ".")
os.rmdir("model")
print("[SUCCESS] Moved files and removed 'model' directory")
# Step 7: Create __init__.py if it doesn't exist
if not os.path.exists("__init__.py"):
print("[INFO] Creating '__init__.py'...")
open("__init__.py", "a").close()
print("[SUCCESS] Created '__init__.py'")
# Step 8: Update imports in 'landmark_model.py'
print("[INFO] Updating imports in 'landmark_model.py'...")
with open("landmark_model.py", "r") as f:
content = f.read()
content = content.replace("import detector as detector_network", "from . import detector as detector_network")
with open("landmark_model.py", "w") as f:
f.write(content)
print("[SUCCESS] Updated imports in 'landmark_model.py'")
# Step 9: Create 'setup.py'
print("[INFO] Creating 'setup.py'...")
setup_py_content = """
from setuptools import setup, find_packages
setup(
name="mtcnn_landmark_detector",
version="0.1.0",
packages=find_packages(),
install_requires=[
"numpy",
"opencv-python",
"tensorflow"
],
author="Aditya Dumrewal",
description="MTCNN-based facial landmark detector",
long_description=open('README.md').read(),
long_description_content_type="text/markdown",
url="https://github.com/adumrewal/mtcnn-landmark-detector",
)
"""
with open("setup.py", "w") as f:
f.write(setup_py_content)
print("[SUCCESS] Created 'setup.py'")
# Step 10: Install the package and dependencies
run_command("pip install -e .", "Installing the MTCNN Landmark Detector package")
run_command("pip install git+https://github.com/hukkelas/DSFD-Pytorch-Inference.git", "Installing DSFD-Pytorch-Inference package")
run_command("pip install opencv-python-headless", "Installing opencv-python-headless")
run_command("pip install mtcnn", "Installing MTCNN package")
print("[INFO] MTCNN Landmark Detector package has been set up and installed.")
print("[INFO] You can now import it using: from mtcnn_landmark_detector.landmark_model import FaceLandmarkModel")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment