KhaldiAbderrhmane
commited on
Upload Resnet50FER
Browse files- config.json +6 -1
- model.py +22 -0
- model.safetensors +3 -0
config.json
CHANGED
@@ -1,7 +1,12 @@
|
|
1 |
{
|
|
|
|
|
|
|
2 |
"auto_map": {
|
3 |
-
"AutoConfig": "config.Resnet50Config"
|
|
|
4 |
},
|
5 |
"num_classes": 6,
|
|
|
6 |
"transformers_version": "4.37.2"
|
7 |
}
|
|
|
1 |
{
|
2 |
+
"architectures": [
|
3 |
+
"Resnet50FER"
|
4 |
+
],
|
5 |
"auto_map": {
|
6 |
+
"AutoConfig": "config.Resnet50Config",
|
7 |
+
"AutoModelForImageClassification": "model.Resnet50FER"
|
8 |
},
|
9 |
"num_classes": 6,
|
10 |
+
"torch_dtype": "float32",
|
11 |
"transformers_version": "4.37.2"
|
12 |
}
|
model.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn as nn
|
3 |
+
import torchvision.models as models
|
4 |
+
from .config import Resnet50Config
|
5 |
+
from transformers import PreTrainedModel
|
6 |
+
|
7 |
+
class Resnet50FER(PreTrainedModel):
|
8 |
+
config = Resnet50Config
|
9 |
+
def __init__(self, config):
|
10 |
+
super().__init__(config)
|
11 |
+
# Load the ResNet50 model without the final fully connected layer
|
12 |
+
self.resnet = models.resnet50(pretrained=False)
|
13 |
+
|
14 |
+
num_ftrs = self.resnet.fc.in_features
|
15 |
+
# Replace the fully connected layer with a new one for your specific classification task
|
16 |
+
self.resnet.fc = nn.Linear(num_ftrs, config.num_classes)
|
17 |
+
|
18 |
+
def forward(self, x):
|
19 |
+
# Forward pass through the ResNet50 model
|
20 |
+
x = self.resnet(x)
|
21 |
+
x = self.resnet.fc(x)
|
22 |
+
return x
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0eee7468c7e125b5499bb7d42c79b8261da5cd6aa07e9dd571e761f6edba8bbc
|
3 |
+
size 94324992
|