Spaces:
Sleeping
Sleeping
RHenigan
commited on
Commit
•
c2ac5a3
1
Parent(s):
c46d2ed
simplify imports
Browse files- app.py +0 -22
- requirements.txt +0 -5
app.py
CHANGED
@@ -1,23 +1,9 @@
|
|
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 numpy as np
|
9 |
-
import pandas as pd
|
10 |
-
from scipy.ndimage.morphology import binary_dilation
|
11 |
import segmentation_models_pytorch as smp
|
12 |
-
from sklearn.impute import SimpleImputer
|
13 |
-
from sklearn.model_selection import train_test_split
|
14 |
import torch
|
15 |
-
import torch.nn as nn
|
16 |
-
from torch.optim import Adam
|
17 |
-
from torch.optim.lr_scheduler import ReduceLROnPlateau
|
18 |
-
from torch.utils.data import Dataset, DataLoader
|
19 |
from torchvision import transforms as T
|
20 |
-
from tqdm import tqdm
|
21 |
from tensorflow.keras.models import load_model
|
22 |
|
23 |
model = smp.MAnet(
|
@@ -27,18 +13,10 @@ model = smp.MAnet(
|
|
27 |
classes=1,
|
28 |
activation='sigmoid',)
|
29 |
|
30 |
-
transform = A.Compose([
|
31 |
-
A.ChannelDropout(p=0.3),
|
32 |
-
A.RandomBrightnessContrast(p=0.3),
|
33 |
-
A.ColorJitter(p=0.3),
|
34 |
-
])
|
35 |
-
|
36 |
model.load_state_dict(torch.load("weights.pt", map_location=torch.device('cpu')))
|
37 |
model.eval()
|
38 |
|
39 |
def segment(image):
|
40 |
-
image = transform(image=image)
|
41 |
-
image = image.get("image")
|
42 |
image = T.functional.to_tensor(image)
|
43 |
prediction = model(image[None, ...])
|
44 |
prediction = np.squeeze(prediction.detach().numpy())
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
from PIL import Image
|
|
|
3 |
import numpy as np
|
|
|
|
|
4 |
import segmentation_models_pytorch as smp
|
|
|
|
|
5 |
import torch
|
|
|
|
|
|
|
|
|
6 |
from torchvision import transforms as T
|
|
|
7 |
from tensorflow.keras.models import load_model
|
8 |
|
9 |
model = smp.MAnet(
|
|
|
13 |
classes=1,
|
14 |
activation='sigmoid',)
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
model.load_state_dict(torch.load("weights.pt", map_location=torch.device('cpu')))
|
17 |
model.eval()
|
18 |
|
19 |
def segment(image):
|
|
|
|
|
20 |
image = T.functional.to_tensor(image)
|
21 |
prediction = model(image[None, ...])
|
22 |
prediction = np.squeeze(prediction.detach().numpy())
|
requirements.txt
CHANGED
@@ -1,11 +1,6 @@
|
|
1 |
Pillow
|
2 |
-
albumentations
|
3 |
numpy
|
4 |
-
pandas
|
5 |
-
scipy
|
6 |
segmentation_models_pytorch
|
7 |
-
sklearn
|
8 |
torch
|
9 |
torchvision
|
10 |
-
tqdm
|
11 |
tensorflow
|
|
|
1 |
Pillow
|
|
|
2 |
numpy
|
|
|
|
|
3 |
segmentation_models_pytorch
|
|
|
4 |
torch
|
5 |
torchvision
|
|
|
6 |
tensorflow
|