Moditha24 commited on
Commit
c197dad
·
verified ·
1 Parent(s): 676a789

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -24
app.py CHANGED
@@ -1,30 +1,26 @@
1
- import torch
2
- import torch.nn as nn
3
  from config import MLP
4
- import gradio as gr
 
 
5
 
6
- # Load the mode
7
- model = MLP()
8
- model.load_state_dict(torch.load("pytorch_model.pth", map_location=torch.device("cpu")))
9
- model.eval()
10
 
11
- # Define a prediction function
12
- def predict(inputs):
13
- with torch.no_grad():
14
- inputs = torch.tensor(inputs).float().unsqueeze(0) # Add batch dimension
15
- output = model(inputs)
16
- if isinstance(output, torch.Tensor):
17
- return output.squeeze().tolist()
18
- return output # fallback
19
 
20
- # Create the Gradio interface
21
- demo = gr.Interface(
22
- fn=predict,
23
- inputs=gr.Textbox(label="Enter comma-separated input values (e.g., 1.2, 3.4, 5.6)"),
24
- outputs=gr.Textbox(label="Model Output"),
25
- title="PyTorch MLP Classifier"
26
- )
 
 
 
 
27
 
28
- # Launch
29
  if __name__ == "__main__":
30
- demo.launch()
 
 
 
1
  from config import MLP
2
+ from mmcv import Config
3
+ from mmdet.models import build_detector
4
+ import torch
5
 
6
+ def main():
7
+ # Print model type from config
8
+ print(f"Model type: {MLP['type']}")
 
9
 
10
+ # Build the model from the config dict
11
+ model = build_detector(MLP, train_cfg=MLP.get('train_cfg'), test_cfg=MLP.get('test_cfg'))
 
 
 
 
 
 
12
 
13
+ # Set model to evaluation mode
14
+ model.eval()
15
+
16
+ # Print model architecture summary
17
+ print(model)
18
+
19
+ # Optional: dummy input test (batch of 1 image with 3 channels, 800x1333)
20
+ dummy_input = torch.randn(1, 3, 800, 1333)
21
+ with torch.no_grad():
22
+ result = model.forward_dummy(dummy_input)
23
+ print("Forward pass output:", result)
24
 
 
25
  if __name__ == "__main__":
26
+ main()