diff --git a/torchbenchmark/models/doctr_det_predictor/install.py b/torchbenchmark/models/doctr_det_predictor/install.py index 16597b18d5..53e2d9758b 100644 --- a/torchbenchmark/models/doctr_det_predictor/install.py +++ b/torchbenchmark/models/doctr_det_predictor/install.py @@ -1,23 +1,25 @@ import subprocess import warnings +import json from utils.python_utils import pip_install_requirements def pip_install_requirements_doctr(): + required_pkgs = ["expecttest", "libglib", "pango"] try: - subprocess.check_call( - [ - "conda", - "install", - "-y", - "expecttest", - "libglib", - "pango", - "-c", - "conda-forge", - ] - ) + installed_pkgs = [x["name"] for x in json.loads(subprocess.check_output(["conda", "list", "--json"], text=True))] + if not all(pkg in installed_pkgs for pkg in required_pkgs): + subprocess.check_call( + [ + "conda", + "install", + "-y", + *required_pkgs, + "-c", + "conda-forge", + ] + ) except: warnings.warn( "The doctr_det_predictor model requires conda binary libaries to be installed. Missing conda packages might break this model." diff --git a/torchbenchmark/models/doctr_reco_predictor/install.py b/torchbenchmark/models/doctr_reco_predictor/install.py index a3d0df3e48..40a0547cd6 100644 --- a/torchbenchmark/models/doctr_reco_predictor/install.py +++ b/torchbenchmark/models/doctr_reco_predictor/install.py @@ -1,23 +1,25 @@ import subprocess import warnings +import json from utils.python_utils import pip_install_requirements def pip_install_requirements_doctr(): + required_pkgs = ["expecttest", "libglib", "pango"] try: - subprocess.check_call( - [ - "conda", - "install", - "-y", - "expecttest", - "libglib", - "pango", - "-c", - "conda-forge", - ] - ) + installed_pkgs = [x["name"] for x in json.loads(subprocess.check_output(["conda", "list", "--json"], text=True))] + if not all(pkg in installed_pkgs for pkg in required_pkgs): + subprocess.check_call( + [ + "conda", + "install", + "-y", + *required_pkgs, + "-c", + "conda-forge", + ] + ) except: warnings.warn( "The doctr_reco_predictor model requires conda binary libaries to be installed. Missing conda packages might break this model."