|
import segmentation_models_pytorch as smp |
|
import sklearn.metrics |
|
import torch |
|
import timm |
|
|
|
|
|
x = torch.randn(1, 13, 512, 512) |
|
y = torch.randint(0, 4, (1, 512, 512)).numpy() |
|
|
|
|
|
|
|
segmodel = smp.Unet( |
|
encoder_name="mobilenet_v2", |
|
encoder_weights=None, |
|
in_channels=13, |
|
classes=4 |
|
) |
|
segmodel.load_state_dict(torch.load("models/UNetMobV2.pt")) |
|
segmodel.eval() |
|
|
|
|
|
|
|
with torch.no_grad(): |
|
yhat = segmodel(x) |
|
cloudmask = torch.argmax(yhat, dim=1).cpu().numpy().squeeze() |
|
|
|
|
|
|
|
ti_index = sklearn.metrics.fbeta_score( |
|
y_true=y.flatten(), |
|
y_pred=cloudmask.flatten(), |
|
beta=2.0, |
|
average="macro" |
|
) |
|
|
|
|
|
|
|
hi_model = timm.create_model( |
|
model_name="resnet10t", |
|
pretrained=True, |
|
num_classes=1, |
|
in_chans=13 |
|
) |
|
hi_model.load_state_dict(torch.load("models/resnet10.pt")) |
|
hi_model.eval() |
|
|
|
|
|
|
|
with torch.no_grad(): |
|
y = hi_model(x) |
|
hi_index = torch.sigmoid(y).cpu().numpy().squeeze().item() |
|
|
|
|
|
|
|
if (ti_index < 0.3) & (hi_index > 0.5): |
|
perror = 1 |
|
else: |
|
perror = 0 |