Spaces:
Running
Running
RHenigan
commited on
Commit
•
44a9d05
1
Parent(s):
09bc333
Make gradio app
Browse files- app.py +49 -0
- model.h5 +3 -0
- requirements.txt +16 -0
- weights.pt +3 -0
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from glob import glob
|
3 |
+
import os
|
4 |
+
import time
|
5 |
+
|
6 |
+
from PIL import Image
|
7 |
+
import albumentations as A
|
8 |
+
import cv2
|
9 |
+
import numpy as np
|
10 |
+
import matplotlib.patches as mpatches
|
11 |
+
import matplotlib.pyplot as plt
|
12 |
+
import pandas as pd
|
13 |
+
from scipy.ndimage.morphology import binary_dilation
|
14 |
+
import segmentation_models_pytorch as smp
|
15 |
+
from sklearn.impute import SimpleImputer
|
16 |
+
from sklearn.model_selection import train_test_split
|
17 |
+
import torch
|
18 |
+
import torch.nn as nn
|
19 |
+
from torch.optim import Adam
|
20 |
+
from torch.optim.lr_scheduler import ReduceLROnPlateau
|
21 |
+
from torch.utils.data import Dataset, DataLoader
|
22 |
+
from torchvision import transforms as T
|
23 |
+
from tqdm import tqdm
|
24 |
+
from tensorflow.keras.models import load_model
|
25 |
+
|
26 |
+
model = smp.MAnet(
|
27 |
+
encoder_name="efficientnet-b7",
|
28 |
+
encoder_weights="imagenet",
|
29 |
+
in_channels=3,
|
30 |
+
classes=1,
|
31 |
+
activation='sigmoid',)
|
32 |
+
|
33 |
+
transform = A.Compose([
|
34 |
+
A.ChannelDropout(p=0.3),
|
35 |
+
A.RandomBrightnessContrast(p=0.3),
|
36 |
+
A.ColorJitter(p=0.3),
|
37 |
+
])
|
38 |
+
|
39 |
+
model.load_state_dict(torch.load("weights.pt", map_location=torch.device('cpu')))
|
40 |
+
model.eval()
|
41 |
+
|
42 |
+
def segment(image):
|
43 |
+
image = transform(image=image)
|
44 |
+
image = image.get("image")
|
45 |
+
image = T.functional.to_tensor(image)
|
46 |
+
prediction = model(image[None, ...])
|
47 |
+
prediction = np.squeeze(prediction.detach().numpy())
|
48 |
+
return Image.fromarray(prediction)
|
49 |
+
iface = gr.Interface(fn=segment, inputs="image", outputs="image").launch()
|
model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b2f7896ed91f6d20c6df42ddc5c846ca022837f65a7d0d4df713a8dea9a68261
|
3 |
+
size 313745109
|
requirements.txt
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
glob
|
2 |
+
os
|
3 |
+
time
|
4 |
+
PIL
|
5 |
+
albumentations
|
6 |
+
cv2
|
7 |
+
numpy
|
8 |
+
matplotlib
|
9 |
+
pandas
|
10 |
+
scipy
|
11 |
+
segmentation_models_pytorch
|
12 |
+
sklearn
|
13 |
+
torch
|
14 |
+
torchvision
|
15 |
+
tqdm
|
16 |
+
tensorflow
|
weights.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b2f7896ed91f6d20c6df42ddc5c846ca022837f65a7d0d4df713a8dea9a68261
|
3 |
+
size 313745109
|