Spaces:
Sleeping
Sleeping
adding food vision mini files
Browse files- .gitattributes +1 -0
- 09_pretrained_effnetb2.pth +3 -0
- examples/2582289.jpg +0 -0
- examples/3622237.jpg +0 -0
- examples/592799.jpg +0 -0
- model.py +36 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
09_pretrained_effnetb2.pth filter=lfs diff=lfs merge=lfs -text
|
09_pretrained_effnetb2.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e1ac7fc3175c192644579123f407e09840790813ac048326da181ba8fe206f9d
|
3 |
+
size 31281914
|
examples/2582289.jpg
ADDED
examples/3622237.jpg
ADDED
examples/592799.jpg
ADDED
model.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torchvision
|
3 |
+
|
4 |
+
from torch import nn
|
5 |
+
|
6 |
+
|
7 |
+
def create_effnetb2_model(num_classes:int=3,
|
8 |
+
seed:int=42):
|
9 |
+
"""Creates an EfficientNetB2 feature extractor model and transforms.
|
10 |
+
|
11 |
+
Args:
|
12 |
+
num_classes (int, optional): number of classes in the classifier head.
|
13 |
+
Defaults to 3.
|
14 |
+
seed (int, optional): random seed value. Defaults to 42.
|
15 |
+
|
16 |
+
Returns:
|
17 |
+
model (torch.nn.Module): EffNetB2 feature extractor model.
|
18 |
+
transforms (torchvision.transforms): EffNetB2 image transforms.
|
19 |
+
"""
|
20 |
+
# Create EffNetB2 pretrained weights, transforms and model
|
21 |
+
weights = torchvision.models.EfficientNet_B2_Weights.DEFAULT
|
22 |
+
transforms = weights.transforms()
|
23 |
+
model = torchvision.models.efficientnet_b2(weights=weights)
|
24 |
+
|
25 |
+
# Freeze all layers in base model
|
26 |
+
for param in model.parameters():
|
27 |
+
param.requires_grad = False
|
28 |
+
|
29 |
+
# Change classifier head with random seed for reproducibility
|
30 |
+
torch.manual_seed(seed)
|
31 |
+
model.classifier = nn.Sequential(
|
32 |
+
nn.Dropout(p=0.3, inplace=True),
|
33 |
+
nn.Linear(in_features=1408, out_features=num_classes),
|
34 |
+
)
|
35 |
+
|
36 |
+
return model, transforms
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch==2.3.0
|
2 |
+
torchvision==0.18.0
|
3 |
+
gradio==3.1.4
|