Spaces:
Sleeping
Sleeping
Create speclab.py
Browse files- speclab.py +23 -0
speclab.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
def speclab(img):
|
| 4 |
+
|
| 5 |
+
# initialize the model
|
| 6 |
+
model = torch.hub.load('Nano1337/SpecLab', 'srdetect', force_reload=True) # for some reasons loads the model in src rather than demo
|
| 7 |
+
model.eval()
|
| 8 |
+
|
| 9 |
+
# preprocess image to be used as input
|
| 10 |
+
transforms = A.Compose([
|
| 11 |
+
A.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5)),
|
| 12 |
+
ToTensorV2()
|
| 13 |
+
])
|
| 14 |
+
input = transforms(image=img)['image']
|
| 15 |
+
input = input.unsqueeze(0)
|
| 16 |
+
|
| 17 |
+
# model prediction
|
| 18 |
+
output = model(input)
|
| 19 |
+
|
| 20 |
+
# overlay output onto original image
|
| 21 |
+
img[output==255] = [0, 255, 0]
|
| 22 |
+
|
| 23 |
+
return img
|