Abrar20 commited on
Commit
dac6d41
·
verified ·
1 Parent(s): 427ff62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -9,17 +9,18 @@ from PIL import Image
9
  class CycloneIntensityModel(nn.Module):
10
  def __init__(self):
11
  super().__init__()
12
- self.backbone = timm.create_model('resnet18', pretrained=True)
13
- in_features = self.backbone.fc.in_features
14
- self.backbone.fc = nn.Linear(in_features, 1)
 
15
 
16
  def forward(self, x):
17
- return self.backbone(x)
18
 
19
  # Instantiate & load
20
  model = CycloneIntensityModel()
21
- model_path = "cyclone_intensity.pth"
22
- model.load_state_dict(torch.load(model_path, map_location='cpu'))
23
  model.eval()
24
 
25
  # ------------------------ Transforms & Classifier ------------------------
@@ -38,7 +39,7 @@ def classify_cyclone(intensity: float) -> str:
38
  elif 130 <= intensity <= 156:
39
  return "Category 4 – Catastrophic damage expected."
40
  else:
41
- return "Category 5 – Catastrophic damage expected."
42
 
43
  # ------------------------ Prediction fn ------------------------
44
  def predict_intensity(img: Image.Image):
 
9
  class CycloneIntensityModel(nn.Module):
10
  def __init__(self):
11
  super().__init__()
12
+ # use the same attribute name (“model”) that your checkpoint used
13
+ self.model = timm.create_model('resnet18', pretrained=True)
14
+ in_features = self.model.fc.in_features
15
+ self.model.fc = nn.Linear(in_features, 1)
16
 
17
  def forward(self, x):
18
+ return self.model(x)
19
 
20
  # Instantiate & load
21
  model = CycloneIntensityModel()
22
+ state = torch.load("cyclone_intensity.pth", map_location='cpu')
23
+ model.load_state_dict(state) # now keys “model.conv1.weight” → self.model.conv1.weight
24
  model.eval()
25
 
26
  # ------------------------ Transforms & Classifier ------------------------
 
39
  elif 130 <= intensity <= 156:
40
  return "Category 4 – Catastrophic damage expected."
41
  else:
42
+ return "Category 5 – Max-severity damage expected."
43
 
44
  # ------------------------ Prediction fn ------------------------
45
  def predict_intensity(img: Image.Image):