TMAx 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tmax-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: TMAx
3
+ Version: 0.1.0
4
+ Summary: Module for segmenting pathological images of tissue microarrays
5
+ Author-email: BOSCH Valentin <val.bosch2001@gmail.com>
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: torch
9
+ Requires-Dist: numpy
10
+ Requires-Dist: huggingface_hub
11
+ Requires-Dist: opencv-python
12
+ Requires-Dist: pillow
13
+
14
+ <img width="2242" height="1267" alt="image" src="https://github.com/user-attachments/assets/3e0d6e0b-aafa-400b-a129-63b837c2ee01" />
15
+
16
+ # TMAs
17
+ Ce projet propose un modèle de segmentation d’images histopathologiques, spécialisé dans les Tissue MicroArrays (TMA) utilisés en anatomopathologie.
18
+
19
+ L’objectif est de segmenter automatiquement des structures d’intérêt dans des lames numériques, en particulier dans le contexte des lymphomes.
20
+
21
+ # Documentation
22
+ def predict_mask(model, imagePath, outputPath, repo_id="Vaaaal/TMAs", filename="tmas_segmenter.pth"):
23
+ - model (torch.nn.Module)
24
+ - Segmentation model (UNet architecture or equivalent) : Weights will be automatically loaded from Hugging Face.
25
+ - imagePath (str) : Path to the input image to be segmented.
26
+ - outputPath (str) : Path where the generated segmentation mask will be saved.
27
+ - repo_id (str, optional) : ID of the Hugging Face repository containing the model weights.
28
+ - filename (str, optional) : Name of the weight file in the repository.
tmax-0.1.0/README.md ADDED
@@ -0,0 +1,15 @@
1
+ <img width="2242" height="1267" alt="image" src="https://github.com/user-attachments/assets/3e0d6e0b-aafa-400b-a129-63b837c2ee01" />
2
+
3
+ # TMAs
4
+ Ce projet propose un modèle de segmentation d’images histopathologiques, spécialisé dans les Tissue MicroArrays (TMA) utilisés en anatomopathologie.
5
+
6
+ L’objectif est de segmenter automatiquement des structures d’intérêt dans des lames numériques, en particulier dans le contexte des lymphomes.
7
+
8
+ # Documentation
9
+ def predict_mask(model, imagePath, outputPath, repo_id="Vaaaal/TMAs", filename="tmas_segmenter.pth"):
10
+ - model (torch.nn.Module)
11
+ - Segmentation model (UNet architecture or equivalent) : Weights will be automatically loaded from Hugging Face.
12
+ - imagePath (str) : Path to the input image to be segmented.
13
+ - outputPath (str) : Path where the generated segmentation mask will be saved.
14
+ - repo_id (str, optional) : ID of the Hugging Face repository containing the model weights.
15
+ - filename (str, optional) : Name of the weight file in the repository.
@@ -0,0 +1 @@
1
+ from .core import predict_mask
@@ -0,0 +1,84 @@
1
+ import torch
2
+ import cv2
3
+ import numpy as np
4
+ from huggingface_hub import hf_hub_download, login
5
+ from PIL import Image
6
+ import config
7
+ from model_resnet import UNetResNet
8
+
9
+
10
+ #Main variables
11
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
12
+ INPUT_IMAGE_WIDTH = 1024
13
+ INPUT_IMAGE_HEIGHT = 1024
14
+
15
+
16
+ def load_model_from_hf(repo_id, filename, device):
17
+ model = UNetResNet()
18
+
19
+ path = hf_hub_download(
20
+ repo_id=repo_id,
21
+ filename=filename,
22
+ repo_type="model"
23
+ )
24
+
25
+ state_dict = torch.load(path, map_location=device)
26
+ model.load_state_dict(state_dict, strict=False)
27
+
28
+ model.to(device)
29
+ model.eval()
30
+
31
+ return model
32
+
33
+ def predict_mask(imagePath, output_path):
34
+
35
+ model = load_model_from_hf(
36
+ repo_id="Vaaaal/TMAs",
37
+ filename="unet_tgs_salt_resnet.pth",
38
+ device=config.DEVICE
39
+ )
40
+
41
+ with torch.no_grad():
42
+
43
+ # --- Load image (robuste TIFF) ---
44
+ try:
45
+ image = np.array(Image.open(imagePath).convert("RGB"))
46
+ except Exception as e:
47
+ raise FileNotFoundError(f"Erreur chargement image: {imagePath}") from e
48
+
49
+ origH, origW = image.shape[:2]
50
+
51
+ # --- Preprocess ---
52
+ image_resized = cv2.resize(
53
+ image,
54
+ (config.INPUT_IMAGE_WIDTH, config.INPUT_IMAGE_HEIGHT)
55
+ )
56
+
57
+ image_resized = image_resized.astype("float32") / 255.0
58
+ image_resized = np.transpose(image_resized, (2, 0, 1))
59
+ image_resized = np.expand_dims(image_resized, 0)
60
+
61
+ image_tensor = torch.from_numpy(image_resized).to(config.DEVICE)
62
+
63
+ # --- Prediction ---
64
+ predMask = model(image_tensor)
65
+
66
+ # --- Post-process (important) ---
67
+ predMask = torch.sigmoid(predMask) # si binaire
68
+ predMask = predMask.squeeze().cpu().numpy()
69
+
70
+ # resize back original size
71
+ predMask = cv2.resize(predMask, (origW, origH))
72
+
73
+ # threshold (optionnel)
74
+ predMask = (predMask > 0.5).astype("uint8") * 255
75
+
76
+ Image.fromarray(predMask).save(output_path, compression=None)
77
+
78
+ return predMask
79
+
80
+
81
+ # --- IMAGE ---
82
+ img_path = r"D:\imvia\unet_tma_segmenter\TMAs\TMAs\09abe43a32f34fbb98d6ab10ff13ca16.tiff"
83
+ # --- PREDICT ---
84
+ mask = predict_mask(img_path, "predicted_mask.tiff")
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: TMAx
3
+ Version: 0.1.0
4
+ Summary: Module for segmenting pathological images of tissue microarrays
5
+ Author-email: BOSCH Valentin <val.bosch2001@gmail.com>
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: torch
9
+ Requires-Dist: numpy
10
+ Requires-Dist: huggingface_hub
11
+ Requires-Dist: opencv-python
12
+ Requires-Dist: pillow
13
+
14
+ <img width="2242" height="1267" alt="image" src="https://github.com/user-attachments/assets/3e0d6e0b-aafa-400b-a129-63b837c2ee01" />
15
+
16
+ # TMAs
17
+ Ce projet propose un modèle de segmentation d’images histopathologiques, spécialisé dans les Tissue MicroArrays (TMA) utilisés en anatomopathologie.
18
+
19
+ L’objectif est de segmenter automatiquement des structures d’intérêt dans des lames numériques, en particulier dans le contexte des lymphomes.
20
+
21
+ # Documentation
22
+ def predict_mask(model, imagePath, outputPath, repo_id="Vaaaal/TMAs", filename="tmas_segmenter.pth"):
23
+ - model (torch.nn.Module)
24
+ - Segmentation model (UNet architecture or equivalent) : Weights will be automatically loaded from Hugging Face.
25
+ - imagePath (str) : Path to the input image to be segmented.
26
+ - outputPath (str) : Path where the generated segmentation mask will be saved.
27
+ - repo_id (str, optional) : ID of the Hugging Face repository containing the model weights.
28
+ - filename (str, optional) : Name of the weight file in the repository.
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ TMAx/__init__.py
4
+ TMAx/core.py
5
+ TMAx.egg-info/PKG-INFO
6
+ TMAx.egg-info/SOURCES.txt
7
+ TMAx.egg-info/dependency_links.txt
8
+ TMAx.egg-info/requires.txt
9
+ TMAx.egg-info/top_level.txt
@@ -0,0 +1,5 @@
1
+ torch
2
+ numpy
3
+ huggingface_hub
4
+ opencv-python
5
+ pillow
@@ -0,0 +1 @@
1
+ TMAx
@@ -0,0 +1,20 @@
1
+ [project]
2
+ name = "TMAx"
3
+ version = "0.1.0"
4
+ description = "Module for segmenting pathological images of tissue microarrays"
5
+ dependencies = [
6
+ "torch",
7
+ "numpy",
8
+ "huggingface_hub",
9
+ "opencv-python",
10
+ "pillow"
11
+ ]
12
+ authors = [
13
+ { name="BOSCH Valentin", email="val.bosch2001@gmail.com" }
14
+ ]
15
+ readme = "README.md"
16
+ requires-python = ">=3.8"
17
+
18
+ [build-system]
19
+ requires = ["setuptools", "wheel"]
20
+ build-backend = "setuptools.build_meta"
tmax-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+