Skip to content

Commit 98cfa0b

Browse files
committed
Change litemedsam installation procedure
1 parent ae8c109 commit 98cfa0b

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

README

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@ cd $HOME/github.com/valab-certh/meddisc
1313
cd python/ && make clean check all && cd ..
1414

1515
# Staging
16-
printf 'USERNAME=user\n' >> python/.env
17-
printf 'PASSWORD=pass\n' >> python/.env
1816
cd python/ && make STAGING=1
1917

python/Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
FROM python:3.12-slim
2-
RUN apt-get update && apt-get install git libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender1 libfontconfig1 libice6 -y
2+
RUN apt-get update && apt-get install libgl1-mesa-glx libglib2.0-0 -y
33
WORKDIR /usr/src/app
44
COPY pyproject.toml .
5-
RUN python3 -m pip install --upgrade pip && python3 -m pip install .[dev]
6-
RUN git clone -b LiteMedSAM https://github.com/bowang-lab/MedSAM/ /usr/src/MedSAM && cd /usr/src/MedSAM/ && python3 -m pip install -e .
5+
RUN python3 -m pip install --upgrade pip && python3 -m pip install .[dev]

python/main.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import pandas as pd
2626
import pydicom
2727
import pytest
28+
import requests
2829
import torch
2930
from fastapi import Body, FastAPI, Request, UploadFile, status
3031
from fastapi.responses import HTMLResponse
@@ -35,14 +36,15 @@
3536
from pydantic import BaseModel
3637
from pydicom.errors import InvalidDicomError
3738
from segment_anything.modeling import MaskDecoder, PromptEncoder, TwoWayTransformer
38-
from tiny_vit_sam import TinyViT
3939
from torch import nn
4040
from torch.nn import functional
4141
from uvicorn import run
4242

4343
if TYPE_CHECKING:
4444
from numpy.typing import NDArray
4545

46+
from tmp.tiny_vit_sam import TinyViT
47+
4648

4749
class UserOptionsClass(BaseModel):
4850
skip_deidentification: bool
@@ -275,6 +277,8 @@ def postprocess_masks(
275277

276278
@lru_cache(maxsize=1)
277279
def load_model() -> MedsamLite:
280+
from tmp.tiny_vit_sam import TinyViT
281+
278282
medsam_lite_image_encoder = TinyViT(
279283
img_size=256,
280284
in_chans=3,
@@ -1482,8 +1486,16 @@ def meddisc() -> None:
14821486
for directory in tmp_directories:
14831487
directory.mkdir(parents=True, exist_ok=True)
14841488
csv_path = Path("tmp/action-groups-dcm.csv")
1489+
vit_path = Path("tmp/tiny_vit_sam.py")
1490+
vit_url = "https://api.github.com/repos/bowang-lab/MedSAM/contents/tiny_vit_sam.py?ref=LiteMedSAM"
14851491
if not csv_path.exists():
14861492
generate_action_groups()
1493+
if not vit_path.exists():
1494+
response = requests.get(vit_url, timeout=10)
1495+
content = response.json()["content"]
1496+
file_content = base64.b64decode(content).decode("utf-8")
1497+
with vit_path.open("w") as f:
1498+
f.write(file_content)
14871499
if os.getenv("STAGING"):
14881500
if not Path("tmp/fullchain.pem").exists():
14891501
subprocess.run(

python/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ dependencies = [
44
"fastapi==0.110.0",
55
"fire==0.6.0",
66
"keras-ocr==0.9.3",
7+
"litemedsam@https://api.github.com/repos/bowang-lab/MedSAM/tarball/LiteMedSAM",
78
"lxml==5.2.0",
89
"pydicom==2.4.4",
910
"pylibjpeg-libjpeg==2.1.0",
1011
"pylibjpeg==2.0.0",
1112
"pytest==8.1.1",
12-
"python-dotenv==1.0.1",
1313
"python-multipart==0.0.9",
14-
"segment-anything@git+https://github.com/facebookresearch/segment-anything.git@6fdee8f2727f4506cfbbe553e23b895e27956588",
14+
"segment-anything@https://api.github.com/repos/facebookresearch/segment-anything/tarball/main",
1515
"tensorflow==2.16.1",
1616
"torch@https://download.pytorch.org/whl/cpu/torch-2.2.1%2Bcpu-cp312-cp312-linux_x86_64.whl",
1717
"torchvision@https://download.pytorch.org/whl/cpu/torchvision-0.17.1%2Bcpu-cp312-cp312-linux_x86_64.whl",

0 commit comments

Comments
 (0)