Naresh617 commited on
Commit
d3a7c66
·
1 Parent(s): fe5770e

Delete deploy.py

Browse files
Files changed (1) hide show
  1. deploy.py +0 -76
deploy.py DELETED
@@ -1,76 +0,0 @@
1
- #!/usr/bin/env python
2
- # coding: utf-8
3
-
4
- # In[2]:
5
-
6
-
7
- get_ipython().system('pip install gradio torch torchvision')
8
-
9
-
10
- # In[3]:
11
-
12
-
13
- import gradio as gr
14
- import torch
15
- import torch.nn as nn
16
- import torch.optim as optim
17
- import torchvision
18
- import torchvision.transforms as transforms
19
-
20
- class Net(nn.Module):
21
- def __init__(self):
22
- super(Net, self).__init__()
23
- self.conv1 = nn.Conv2d(3, 6, 5)
24
- self.pool = nn.MaxPool2d(2, 2)
25
- self.conv2 = nn.Conv2d(6, 16, 5)
26
- # Modify fc1 to match the size in the saved checkpoint
27
- self.fc1 = nn.Linear(400, 120)
28
- # Modify fc2 to match the size in the saved checkpoint
29
- self.fc2 = nn.Linear(120, 84)
30
- # Modify fc3 to match the size in the saved checkpoint
31
- self.fc3 = nn.Linear(84, 10)
32
-
33
- def forward(self, x):
34
- x = self.pool(torch.relu(self.conv1(x)))
35
- x = self.pool(torch.relu(self.conv2(x)))
36
- x = x.view(x.shape[0], -1)
37
- x = torch.relu(self.fc1(x))
38
- x = torch.relu(self.fc2(x))
39
- x = self.fc3(x)
40
- return x
41
-
42
- # Load the trained model
43
- model = Net()
44
- model.load_state_dict(torch.load("cifar_net.pth"))
45
- model.eval()
46
-
47
- # Define the transformation to be applied to input images
48
- preprocess = transforms.Compose([
49
- transforms.ToTensor(),
50
- transforms.Resize((32, 32)),
51
- transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
52
- ])
53
-
54
- # Define the CIFAR-10 class names
55
- classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck')
56
-
57
- # Define a function to make predictions on input images
58
- def classify_image(image):
59
- img_tensor = preprocess(image)
60
- img_tensor = img_tensor.unsqueeze(0)
61
- output = model(img_tensor)
62
- _, predicted = torch.max(output, dim=1)
63
- return classes[predicted[0]] # Return as a list
64
-
65
- # Create Gradio interface
66
- iface = gr.Interface(fn=classify_image, inputs="image", outputs="text")
67
-
68
- # Launch the interface
69
- iface.launch()
70
-
71
-
72
- # In[ ]:
73
-
74
-
75
-
76
-