Skip to content

Commit

Permalink
Import tiny_vit_sam directly
Browse files Browse the repository at this point in the history
  • Loading branch information
uw0s committed Apr 16, 2024
1 parent 32b475d commit f38c4da
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime
import glob
import hashlib
import importlib
import json
import os
import re
Expand Down Expand Up @@ -43,8 +44,7 @@

if TYPE_CHECKING:
from numpy.typing import NDArray

from tmp.tiny_vit_sam import TinyViT
from tiny_vit_sam import TinyViT


class UserOptionsClass(BaseModel):
Expand Down Expand Up @@ -290,7 +290,7 @@ def postprocess_masks(

@lru_cache(maxsize=1)
def load_model() -> MedsamLite:
from tmp.tiny_vit_sam import TinyViT
from tiny_vit_sam import TinyViT

medsam_lite_image_encoder = TinyViT(
img_size=256,
Expand Down Expand Up @@ -1501,17 +1501,16 @@ def meddisc() -> None:
for directory in tmp_directories:
directory.mkdir(parents=True, exist_ok=True)
csv_path = Path("tmp/action-groups-dcm.csv")
vit_path = Path("tmp/tiny_vit_sam.py")
vit_url = "https://api.github.com/repos/bowang-lab/MedSAM/contents/tiny_vit_sam.py?ref=b042d247f92105d4b03372b18230aa08560959e7"
if not csv_path.exists():
generate_action_groups()
if not vit_path.exists():
response = requests.get(vit_url, timeout=10)
content = response.json()["content"]
file_content = base64.b64decode(content).decode("utf-8")
with vit_path.open("w") as f:
f.write(file_content)
sys.path.append(str(Path.cwd()))
vit_url = "https://api.github.com/repos/bowang-lab/MedSAM/contents/tiny_vit_sam.py?ref=b042d247f92105d4b03372b18230aa08560959e7"
response = requests.get(vit_url, timeout=10)
content = response.json()["content"]
decoded_content = base64.b64decode(content).decode("utf-8")
spec = importlib.util.spec_from_loader("tiny_vit_sam", loader=None, origin=vit_url)
module = importlib.util.module_from_spec(spec) # type: ignore[arg-type]
exec(decoded_content, module.__dict__) # noqa: S102
sys.modules["tiny_vit_sam"] = module
os.environ["KERAS_OCR_CACHE_DIR"] = "tmp"
if os.getenv("STAGING"):
if not Path("tmp/fullchain.pem").exists():
Expand Down

0 comments on commit f38c4da

Please sign in to comment.