added params to app
Browse files
app.py
CHANGED
@@ -1,13 +1,32 @@
|
|
1 |
import torch
|
|
|
2 |
import torchvision.transforms as transforms
|
3 |
from torchvision import models
|
4 |
from PIL import Image
|
5 |
import gradio as gr
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# Force CPU usage
|
8 |
device = torch.device('cpu')
|
9 |
|
10 |
-
# Load your trained ResNet-50 model
|
11 |
model = models.resnet50(pretrained=False) # Load the ResNet-50 architecture
|
12 |
model.load_state_dict(torch.load("model.pth", map_location=device)) # Load the trained weights (.pth)
|
13 |
model.to(device) # Move model to CPU (even if you have a GPU)
|
|
|
1 |
import torch
|
2 |
+
import torch.nn as nn
|
3 |
import torchvision.transforms as transforms
|
4 |
from torchvision import models
|
5 |
from PIL import Image
|
6 |
import gradio as gr
|
7 |
|
8 |
+
# Define custom class 'Params' if used
|
9 |
+
class Params:
|
10 |
+
def __init__(self):
|
11 |
+
self.batch_size = 128 # You can adjust this based on your GPU memory
|
12 |
+
self.name = "resnet_50_sgd" # Rename to reflect ResNet-50
|
13 |
+
self.workers = 4 # Number of DataLoader workers
|
14 |
+
self.lr = 0.1 # Learning rate for SGD optimizer
|
15 |
+
self.momentum = 0.9 # Momentum for SGD
|
16 |
+
self.weight_decay = 1e-4 # Weight decay for regularization
|
17 |
+
self.lr_step_size = 30 # Step size for learning rate decay
|
18 |
+
self.lr_gamma = 0.1 # Gamma factor for learning rate decay
|
19 |
+
|
20 |
+
def __repr__(self):
|
21 |
+
return str(self.__dict__)
|
22 |
+
|
23 |
+
def __eq__(self, other):
|
24 |
+
return self.__dict__ == other.__dict__
|
25 |
+
|
26 |
# Force CPU usage
|
27 |
device = torch.device('cpu')
|
28 |
|
29 |
+
# Load your trained ResNet-50 model (or any custom architecture)
|
30 |
model = models.resnet50(pretrained=False) # Load the ResNet-50 architecture
|
31 |
model.load_state_dict(torch.load("model.pth", map_location=device)) # Load the trained weights (.pth)
|
32 |
model.to(device) # Move model to CPU (even if you have a GPU)
|