Skip to content

Commit

Permalink
Merge pull request #1 from artyaltanzaya/main
Browse files Browse the repository at this point in the history
No module named "Detectron2" Bug Fix
  • Loading branch information
capjamesg committed Jun 14, 2023
2 parents e17987f + cab3cea commit 095bba7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
31 changes: 0 additions & 31 deletions autodistill_detic/detic_model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os
from dataclasses import dataclass

import numpy as np
import supervision as sv
import torch
import subprocess
from autodistill.detection import CaptionOntology, DetectionBaseModel

import argparse
Expand Down Expand Up @@ -68,41 +66,12 @@ def load_detic_model(ontology):
HOME = os.path.expanduser("~")
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")

installation_commands = [
"mkdir ~/.cache/autodistill/",
"cd ~/.cache/autodistill/",
"git clone [email protected]:facebookresearch/detectron2.git",
"cd detectron2",
"pip install -e .",
"pip install -r requirements.txt",
"cd ..",
"git clone https://github.com/facebookresearch/Detic.git --recurse-submodules",
"cd Detic",
"pip install -r requirements.txt",
"mkdir models",
"wget https://dl.fbaipublicfiles.com/detic/Detic_LCOCOI21k_CLIP_SwinB_896b32_4x_ft4x_max-size.pth -O models/Detic_LCOCOI21k_CLIP_SwinB_896b32_4x_ft4x_max-size.pth"
]

def install_detic():
for command in installation_commands:
# keep track of pathi
if command.startswith("cd"):
# re[place ~ with home]
command = command.replace("~", HOME)
os.chdir(command.split(" ")[1])

subprocess.run(command, shell=True)


@dataclass
class DETIC(DetectionBaseModel):
ontology: CaptionOntology

def __init__(self, ontology: CaptionOntology):
self.ontology = ontology
if not os.path.exists(HOME + "/.cache/autodistill/detectron2"):
install_detic()

original_dir = os.getcwd()

sys.path.insert(0, HOME + "/.cache/autodistill/Detic/third_party/CenterNet2/")
Expand Down
28 changes: 25 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import setuptools
from setuptools import find_packages
from setuptools.command.install import install
import re
import subprocess

with open("./autodistill_detic/__init__.py", 'r') as f:
content = f.read()
# from https://www.py4u.net/discuss/139845
version = re.search(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]', content).group(1)

with open("README.md", "r") as fh:
long_description = fh.read()

class AutodistillDetic(install):
def run(self):
install.run(self)
installation_commands = """
mkdir -p ~/.cache/autodistill/ &&
cd ~/.cache/autodistill/ &&
pip install 'git+https://github.com/facebookresearch/detectron2.git' &&
git clone https://github.com/facebookresearch/Detic.git --recurse-submodules &&
cd Detic &&
pip install -r requirements.txt &&
mkdir models &&
wget https://dl.fbaipublicfiles.com/detic/Detic_LCOCOI21k_CLIP_SwinB_896b32_4x_ft4x_max-size.pth -O models/Detic_LCOCOI21k_CLIP_SwinB_896b32_4x_ft4x_max-size.pth
"""

subprocess.run(installation_commands, shell=True, executable="/bin/bash")


setuptools.setup(
name="autodistill_detic",
version=version,
Expand All @@ -19,11 +37,15 @@
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/autodistill/autodistill-detic",
nstall_requires=[
install_requires=[
"torch",
"supervision",
"numpy",
"autodistill",
],
cmdclass={
'install': AutodistillDetic,
},
packages=find_packages(exclude=("tests",)),
extras_require={
"dev": ["flake8", "black==22.3.0", "isort", "twine", "pytest", "wheel"],
Expand Down

0 comments on commit 095bba7

Please sign in to comment.