Spaces:
Configuration error
Configuration error
Upload 3 files
Browse files- Gadgets_model_save.pth +3 -0
- model.py +25 -0
- requirements.txt +3 -0
Gadgets_model_save.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:90f169785198008285834c200c8258b84acfc1ad6244386f2d99e518663a3c7d
|
| 3 |
+
size 95395709
|
model.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torchvision
|
| 3 |
+
|
| 4 |
+
from torch import nn
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def create_gadgets_model(num_classes:int=3,
|
| 8 |
+
seed:int=42):
|
| 9 |
+
# Create EffNetB2 pretrained weights, transforms and model
|
| 10 |
+
weights = torchvision.models.ResNet50_Weights.DEFAULT
|
| 11 |
+
transforms = weights.transforms()
|
| 12 |
+
model = torchvision.models.resnet50(weights=weights)
|
| 13 |
+
|
| 14 |
+
# Freeze all layers in base model
|
| 15 |
+
for param in model.parameters():
|
| 16 |
+
param.requires_grad = False
|
| 17 |
+
|
| 18 |
+
# Change classifier head with random seed for reproducibility
|
| 19 |
+
torch.manual_seed(seed)
|
| 20 |
+
model.fc = nn.Sequential(
|
| 21 |
+
nn.Linear(2048, 128),
|
| 22 |
+
nn.ReLU(inplace=True),
|
| 23 |
+
nn.Linear(in_features= 128,out_features=output_shape))
|
| 24 |
+
|
| 25 |
+
return model, transforms
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==1.12.1
|
| 2 |
+
torchvision==0.13.1
|
| 3 |
+
gradio==3.4.1
|