File size: 757 Bytes
8cc2137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import torch
import torch.nn.functional as F

MOLD_HIGH_CONF = 0.80
MOLD_LOW_CONF  = 0.50
BIO_CONF       = 0.60

def final_decision(model, img_tensor, mold_idx=4):
    with torch.no_grad():
        out = model(img_tensor.unsqueeze(0))
        class_probs = F.softmax(out["class"], dim=1)[0]
        bio_probs = F.softmax(out["bio"], dim=1)[0]

    mold_p = class_probs[mold_idx].item()
    bio_p  = bio_probs[1].item()

    if mold_p >= MOLD_HIGH_CONF:
        decision = "Mold"
    elif mold_p >= MOLD_LOW_CONF and bio_p >= BIO_CONF:
        decision = "Possible Mold"
    else:
        decision = "Not Mold"

    return {
        "decision": decision,
        "mold_probability": round(mold_p, 3),
        "biological_probability": round(bio_p, 3)
    }