Mehmet Batuhan Duman commited on
Commit
521227f
1 Parent(s): de18bbd

Changes and added model3

Browse files
Files changed (2) hide show
  1. app.py +53 -4
  2. model3.pth +3 -0
app.py CHANGED
@@ -64,24 +64,73 @@ class Net2(nn.Module):
64
  x = F.relu(self.fc2(x))
65
  x = F.softmax(self.fc3(x), dim=1)
66
  return x
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
 
 
68
 
69
  model2 = None
70
  model2_path = "model4.pth"
71
 
72
- if os.path.exists(model2_path):
73
- state_dict = torch.load(model2_path, map_location=torch.device('cpu'))
74
  new_state_dict = {}
75
  for key, value in state_dict.items():
76
  new_key = key.replace("module.", "")
77
  new_state_dict[new_key] = value
78
 
79
- model = Net2()
80
  model.load_state_dict(new_state_dict)
81
  model.eval()
82
 
83
  else:
84
- print("Model file not found at", model2_path)
85
 
86
 
87
  def process_image(input_image):
 
64
  x = F.relu(self.fc2(x))
65
  x = F.softmax(self.fc3(x), dim=1)
66
  return x
67
+ class Net(nn.Module):
68
+ def __init__(self):
69
+ super(Net, self).__init__()
70
+ self.conv1 = nn.Conv2d(3, 32, 3, padding=1)
71
+ self.pool1 = nn.MaxPool2d(2, 2)
72
+ self.dropout1 = nn.Dropout(0.25)
73
+
74
+ self.conv2 = nn.Conv2d(32, 32, 3, padding=1)
75
+ self.pool2 = nn.MaxPool2d(2, 2)
76
+ self.dropout2 = nn.Dropout(0.25)
77
+
78
+ self.conv3 = nn.Conv2d(32, 32, 3, padding=1)
79
+ self.pool3 = nn.MaxPool2d(2, 2)
80
+ self.dropout3 = nn.Dropout(0.25)
81
+
82
+ self.conv4 = nn.Conv2d(32, 32, 3, padding=1)
83
+ self.pool4 = nn.MaxPool2d(2, 2)
84
+ self.dropout4 = nn.Dropout(0.25)
85
+
86
+ self.flatten = nn.Flatten()
87
+
88
+ self.fc1 = nn.Linear(32 * 5 * 5, 200)
89
+ self.fc2 = nn.Linear(200, 150)
90
+ self.fc3 = nn.Linear(150, 2)
91
+
92
+ def forward(self, x):
93
+ x = F.relu(self.conv1(x))
94
+ x = self.pool1(x)
95
+ x = self.dropout1(x)
96
+
97
+ x = F.relu(self.conv2(x))
98
+ x = self.pool2(x)
99
+ x = self.dropout2(x)
100
+
101
+ x = F.relu(self.conv3(x))
102
+ x = self.pool3(x)
103
+ x = self.dropout3(x)
104
+
105
+ x = F.relu(self.conv4(x))
106
+ x = self.pool4(x)
107
+ x = self.dropout4(x)
108
+
109
+ x = self.flatten(x)
110
+ x = F.relu(self.fc1(x))
111
+ x = F.relu(self.fc2(x))
112
+ x = torch.sigmoid(self.fc3(x))
113
+ return x
114
 
115
+ model = None
116
+ model_path = "model3.pth"
117
 
118
  model2 = None
119
  model2_path = "model4.pth"
120
 
121
+ if os.path.exists(model_path):
122
+ state_dict = torch.load(model_path, map_location=torch.device('cpu'))
123
  new_state_dict = {}
124
  for key, value in state_dict.items():
125
  new_key = key.replace("module.", "")
126
  new_state_dict[new_key] = value
127
 
128
+ model = Net()
129
  model.load_state_dict(new_state_dict)
130
  model.eval()
131
 
132
  else:
133
+ print("Model file not found at", model_path)
134
 
135
 
136
  def process_image(input_image):
model3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71441727a850152f5a1470607decc8800e09b14e8e2ae15efb77d6723decee25
3
+ size 882027