Spaces:
Running
Running
admin
commited on
Commit
•
7d1df75
1
Parent(s):
46fd9ef
sync
Browse files- .gitattributes +10 -11
- .gitignore +2 -0
- README.md +2 -2
- app.py +67 -0
- requirements.txt +7 -0
.gitattributes
CHANGED
@@ -1,35 +1,34 @@
|
|
1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
4 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
|
|
6 |
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
|
|
11 |
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
13 |
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
*.pb filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
17 |
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
*.rar filter=lfs diff=lfs merge=lfs -text
|
|
|
20 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
|
|
22 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
|
|
24 |
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tfevents* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.db* filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.ark* filter=lfs diff=lfs merge=lfs -text
|
30 |
+
**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text
|
31 |
+
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
|
32 |
+
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
save.pt
|
2 |
+
rename.sh
|
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
title: HEp2
|
3 |
-
emoji:
|
4 |
colorFrom: blue
|
5 |
colorTo: pink
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
1 |
---
|
2 |
title: HEp2
|
3 |
+
emoji: 🧬🧫
|
4 |
colorFrom: blue
|
5 |
colorTo: pink
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.39.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
app.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
from PIL import Image
|
5 |
+
from torchvision.transforms import transforms
|
6 |
+
from modelscope import snapshot_download
|
7 |
+
|
8 |
+
MODEL_DIR = snapshot_download("MuGeminorum/HEp2", cache_dir="./__pycache__")
|
9 |
+
TRANSLATE = {
|
10 |
+
"Centromere": "着丝粒 Centromere",
|
11 |
+
"Golgi": "高尔基体 Golgi",
|
12 |
+
"Homogeneous": "同质 Homogeneous",
|
13 |
+
"NuMem": "记忆体 NuMem",
|
14 |
+
"Nucleolar": "核仁 Nucleolar",
|
15 |
+
"Speckled": "斑核 Speckled",
|
16 |
+
}
|
17 |
+
CLASSES = list(TRANSLATE.keys())
|
18 |
+
|
19 |
+
|
20 |
+
def embeding(img_path: str):
|
21 |
+
compose = transforms.Compose(
|
22 |
+
[
|
23 |
+
transforms.Resize(224),
|
24 |
+
transforms.CenterCrop(224),
|
25 |
+
transforms.RandomAffine(5),
|
26 |
+
transforms.ToTensor(),
|
27 |
+
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
|
28 |
+
]
|
29 |
+
)
|
30 |
+
img = Image.open(img_path).convert("RGB")
|
31 |
+
return compose(img)
|
32 |
+
|
33 |
+
|
34 |
+
def infer(target: str):
|
35 |
+
model = torch.load(f"{MODEL_DIR}/save.pt", map_location=torch.device("cpu"))
|
36 |
+
if not target:
|
37 |
+
return None, "请上传细胞图片 Please upload a cell picture!"
|
38 |
+
|
39 |
+
torch.cuda.empty_cache()
|
40 |
+
input: torch.Tensor = embeding(target)
|
41 |
+
output: torch.Tensor = model(input.unsqueeze(0))
|
42 |
+
predict = torch.max(output.data, 1)[1]
|
43 |
+
return os.path.basename(target), TRANSLATE[CLASSES[predict]]
|
44 |
+
|
45 |
+
|
46 |
+
if __name__ == "__main__":
|
47 |
+
example_imgs = []
|
48 |
+
for cls in CLASSES:
|
49 |
+
example_imgs.append(f"{MODEL_DIR}/examples/{cls}.png")
|
50 |
+
|
51 |
+
with gr.Blocks() as demo:
|
52 |
+
gr.Interface(
|
53 |
+
fn=infer,
|
54 |
+
inputs=gr.Image(
|
55 |
+
type="filepath", label="上传细胞图像 Upload a cell picture"
|
56 |
+
),
|
57 |
+
outputs=[
|
58 |
+
gr.Textbox(label="图片名 Picture name", show_copy_button=True),
|
59 |
+
gr.Textbox(label="识别结果 Recognition result", show_copy_button=True),
|
60 |
+
],
|
61 |
+
title="请上传 PNG 格式的 HEp2 细胞图片<br>It is recommended to upload HEp2 cell images in PNG format.",
|
62 |
+
examples=example_imgs,
|
63 |
+
allow_flagging="never",
|
64 |
+
cache_examples=False,
|
65 |
+
)
|
66 |
+
|
67 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
gradio
|
3 |
+
pillow
|
4 |
+
torchvision
|
5 |
+
tqdm
|
6 |
+
requests
|
7 |
+
modelscope==1.15
|