Spaces:
Sleeping
Sleeping
set seeds
Browse files- utils/segmentation.py +10 -0
utils/segmentation.py
CHANGED
|
@@ -4,6 +4,7 @@ import torch
|
|
| 4 |
import scipy.sparse as sp
|
| 5 |
import sys
|
| 6 |
import os
|
|
|
|
| 7 |
from zipfile import ZipFile
|
| 8 |
from .plotting import plot_side_by_side_comparison
|
| 9 |
|
|
@@ -12,6 +13,13 @@ from models.HybridGNet2IGSC import Hybrid
|
|
| 12 |
|
| 13 |
hybrid = None
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def scipy_to_torch_sparse(scp_matrix):
|
| 16 |
values = scp_matrix.data
|
| 17 |
indices = np.vstack((scp_matrix.row, scp_matrix.col))
|
|
@@ -215,7 +223,9 @@ def segment(input_img, noise_std=0.0):
|
|
| 215 |
img_corr = np.clip(img_corr + noise, 0.0, 1.0)
|
| 216 |
|
| 217 |
# Predict landmarks
|
|
|
|
| 218 |
means_orig, stds_orig = predict_landmarks(img_orig)
|
|
|
|
| 219 |
means_corr, stds_corr = predict_landmarks(img_corr)
|
| 220 |
|
| 221 |
# Save landmarks and masks
|
|
|
|
| 4 |
import scipy.sparse as sp
|
| 5 |
import sys
|
| 6 |
import os
|
| 7 |
+
import random
|
| 8 |
from zipfile import ZipFile
|
| 9 |
from .plotting import plot_side_by_side_comparison
|
| 10 |
|
|
|
|
| 13 |
|
| 14 |
hybrid = None
|
| 15 |
|
| 16 |
+
def seed_everything(seed=42):
|
| 17 |
+
random.seed(seed)
|
| 18 |
+
np.random.seed(seed)
|
| 19 |
+
torch.manual_seed(seed)
|
| 20 |
+
if torch.cuda.is_available():
|
| 21 |
+
torch.cuda.manual_seed_all(seed)
|
| 22 |
+
|
| 23 |
def scipy_to_torch_sparse(scp_matrix):
|
| 24 |
values = scp_matrix.data
|
| 25 |
indices = np.vstack((scp_matrix.row, scp_matrix.col))
|
|
|
|
| 223 |
img_corr = np.clip(img_corr + noise, 0.0, 1.0)
|
| 224 |
|
| 225 |
# Predict landmarks
|
| 226 |
+
seed_everything(123)
|
| 227 |
means_orig, stds_orig = predict_landmarks(img_orig)
|
| 228 |
+
seed_everything(123)
|
| 229 |
means_corr, stds_corr = predict_landmarks(img_corr)
|
| 230 |
|
| 231 |
# Save landmarks and masks
|