imlamont commited on
Commit
bedc1b2
·
verified ·
1 Parent(s): e0b85f3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +68 -9
README.md CHANGED
@@ -1,9 +1,68 @@
1
- ---
2
- tags:
3
- - model_hub_mixin
4
- - pytorch_model_hub_mixin
5
- ---
6
-
7
- This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
8
- - Library: [More Information Needed]
9
- - Docs: [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ latitude_mean: 39.951631102585964\
2
+ latitude_std: 0.0006960598068888123\
3
+ longitude_mean: -75.1914340210287\
4
+ longitude_std: 0.0006455062924978866
5
+
6
+ ```
7
+ from huggingface_hub import hf_hub_download
8
+ import torch
9
+
10
+ import torch.nn as nn
11
+ import torch.nn.functional as F
12
+ from huggingface_hub import PyTorchModelHubMixin
13
+ import torchvision.models as models
14
+
15
+ class SimpleCNN(nn.Module, PyTorchModelHubMixin):
16
+ def __init__(self):
17
+ super().__init__()
18
+
19
+ # Convolutional layers
20
+ self.conv3to32 = nn.Conv2d(in_channels=3, out_channels=15, kernel_size=9, stride=1, padding=4)
21
+
22
+ self.conv32to32kernel5 = nn.Conv2d(in_channels=15, out_channels=15, kernel_size=5, stride=1, padding=2)
23
+
24
+ self.conv32to64 = nn.Conv2d(in_channels=15, out_channels=30, kernel_size=3, stride=1, padding=1)
25
+
26
+ self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2)
27
+ self.dropout = nn.Dropout(0.5)
28
+
29
+ self.linear_input_dims = 30*56*56
30
+ self.fc_1 = nn.Linear(self.linear_input_dims, 100)
31
+ self.fc_2 = nn.Linear(100, 2)
32
+
33
+ def forward(self, x):
34
+ x = F.relu(self.conv3to32(x))
35
+ x = F.relu(self.conv32to32kernel5(x))
36
+
37
+
38
+ x = self.pool2(x)
39
+ x = F.relu(self.conv32to64(x))
40
+
41
+ x = self.pool2(x)
42
+ x = self.dropout(x)
43
+
44
+ x = x.view(-1, self.linear_input_dims)
45
+ x = F.relu(self.fc_1(x))
46
+ x = self.fc_2(x)
47
+ return x
48
+
49
+ def save_model(self, save_path):
50
+ """Save model locally using the Hugging Face format."""
51
+ self.save_pretrained(save_path)
52
+
53
+ def push_model(self, repo_name):
54
+ """Push the model to the Hugging Face Hub."""
55
+ self.push_to_hub(repo_name)
56
+
57
+
58
+ # Specify the repository and the filename of the model you want to load
59
+ repo_id = "IanAndJohn/Model_Ian" # Replace with your repo name
60
+ filename = model_save_path
61
+
62
+ model_path = hf_hub_download(repo_id=repo_id, filename=filename)
63
+
64
+ # Load the model using torch
65
+ model = SimpleCNN()
66
+ model.load_state_dict(torch.load(model_path))
67
+ model.eval() # Set the model to evaluation mode
68
+ ```