Robzy commited on
Commit
cce6a45
·
1 Parent(s): 5cd43ef

added model

Browse files
Files changed (1) hide show
  1. model.py +29 -0
model.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ from huggingface_hub import PyTorchModelHubMixin
4
+
5
+
6
+ class MyModel(
7
+ nn.Module,
8
+ PyTorchModelHubMixin,
9
+ # optionally, you can add metadata which gets pushed to the model card
10
+ repo_url="https://huggingface.co/Robzy/random-genre",
11
+ pipeline_tag="text-to-image",
12
+ license="mit",
13
+ ):
14
+ def __init__(self, num_channels: int, hidden_size: int, num_classes: int):
15
+ super().__init__()
16
+ self.param = nn.Parameter(torch.rand(num_channels, hidden_size))
17
+ self.linear = nn.Linear(hidden_size, num_classes)
18
+
19
+ def forward(self, x):
20
+ return self.linear(x + self.param)
21
+
22
+ # create model
23
+ config = {"num_channels": 3, "hidden_size": 32, "num_classes": 10}
24
+ model = MyModel(**config)
25
+
26
+ # Save the model locally
27
+ model_save_path = "trial-model"
28
+ model.save_pretrained(model_save_path)
29
+ model.push_to_hub("Robzy/random-genre")