@@ -826,11 +826,13 @@ async def medsam_estimation(boxdata: BoxData) -> BoxDataResponse:
826
826
827
827
def prepare_medsam () -> None :
828
828
def initialize_image_embeddings (dcm_hash , img ) -> None : # type: ignore[no-untyped-def] # noqa: ANN001
829
- img_embeding_fp = embed_dp / f"{ dcm_hash } .pt"
830
- if not os . path . exists (img_embeding_fp ):
829
+ img_embeding_fp = Path ( embed_dp / f"{ dcm_hash } .pt" )
830
+ if not img_embeding_fp . exists ():
831
831
two_d = 2
832
832
img_3c = (
833
- np .repeat (img [:, :, None ], 3 , axis = - 1 ) if len (img .shape ) == two_d else img
833
+ np .repeat (img [:, :, None ], 3 , axis = - 1 )
834
+ if len (img .shape ) == two_d
835
+ else img
834
836
)
835
837
img_256 = cv2 .resize (src = img_3c , dsize = (256 , 256 )).astype (np .float32 )
836
838
img_256 = (img_256 - img_256 .min ()) / np .clip (
@@ -1525,13 +1527,24 @@ def meddisc() -> None:
1525
1527
if not csv_path .exists ():
1526
1528
generate_action_groups ()
1527
1529
vit_url = "https://api.github.com/repos/bowang-lab/MedSAM/contents/tiny_vit_sam.py?ref=b042d247f92105d4b03372b18230aa08560959e7"
1530
+ vit_hash = "7b2f2103b7bc19a09c1f1e2fe1097ead8105fed59ab62e436430032a3a0e6c49"
1528
1531
response = requests .get (vit_url , timeout = 10 )
1529
1532
content = response .json ()["content" ]
1530
1533
decoded_content = base64 .b64decode (content ).decode ("utf-8" )
1531
- spec = importlib .util .spec_from_loader ("tiny_vit_sam" , loader = None , origin = vit_url )
1532
- module = importlib .util .module_from_spec (spec ) # type: ignore[arg-type]
1533
- exec (decoded_content , module .__dict__ ) # noqa: S102
1534
- sys .modules ["tiny_vit_sam" ] = module
1534
+ hash_object = hashlib .sha256 (decoded_content .encode ())
1535
+ calculated_hash = hash_object .hexdigest ()
1536
+ if calculated_hash == vit_hash :
1537
+ spec = importlib .util .spec_from_loader (
1538
+ "tiny_vit_sam" ,
1539
+ loader = None ,
1540
+ origin = vit_url ,
1541
+ )
1542
+ module = importlib .util .module_from_spec (spec ) # type: ignore[arg-type]
1543
+ exec (decoded_content , module .__dict__ ) # noqa: S102
1544
+ sys .modules ["tiny_vit_sam" ] = module
1545
+ else :
1546
+ msg = "E: Generated hash doesn't match"
1547
+ raise ValueError (msg )
1535
1548
os .environ ["KERAS_OCR_CACHE_DIR" ] = "tmp"
1536
1549
if os .getenv ("STAGING" ):
1537
1550
run (
0 commit comments