Spaces:
Sleeping
Sleeping
bmartinc80
commited on
Commit
•
6f4e19a
1
Parent(s):
67048a9
Final Deployment
Browse files- app.py +1 -3
- classes.py +1 -1
- model.py +4 -5
app.py
CHANGED
@@ -3,7 +3,6 @@ import gradio as gr
|
|
3 |
import torch
|
4 |
from model import create_effnetb2_model
|
5 |
from classes import class_names
|
6 |
-
from PIL import Image
|
7 |
|
8 |
# Setup DataLoaders
|
9 |
effnetb2, effnetb2_transforms = create_effnetb2_model(num_classes=525,
|
@@ -97,5 +96,4 @@ demo = gr.Interface(fn=predict,
|
|
97 |
article=article)
|
98 |
|
99 |
# Launch the demo!
|
100 |
-
demo.launch(debug=True
|
101 |
-
share=True)
|
|
|
3 |
import torch
|
4 |
from model import create_effnetb2_model
|
5 |
from classes import class_names
|
|
|
6 |
|
7 |
# Setup DataLoaders
|
8 |
effnetb2, effnetb2_transforms = create_effnetb2_model(num_classes=525,
|
|
|
96 |
article=article)
|
97 |
|
98 |
# Launch the demo!
|
99 |
+
demo.launch(debug=True)
|
|
classes.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
class_names = ['ABBOTTS BABBLER',
|
3 |
'ABBOTTS BOOBY',
|
4 |
'ABYSSINIAN GROUND HORNBILL',
|
|
|
1 |
+
# Bird Classes
|
2 |
class_names = ['ABBOTTS BABBLER',
|
3 |
'ABBOTTS BOOBY',
|
4 |
'ABYSSINIAN GROUND HORNBILL',
|
model.py
CHANGED
@@ -1,22 +1,21 @@
|
|
1 |
import torch
|
2 |
import torchvision
|
3 |
-
|
4 |
from torch import nn
|
5 |
|
6 |
-
|
7 |
def create_effnetb2_model(num_classes:int=525,
|
8 |
seed:int=42):
|
9 |
|
10 |
-
#
|
11 |
weights = torchvision.models.EfficientNet_B2_Weights.DEFAULT
|
12 |
transforms = weights.transforms()
|
13 |
model = torchvision.models.efficientnet_b2(weights=weights)
|
14 |
|
15 |
-
#
|
16 |
for param in model.parameters():
|
17 |
param.requires_grad = False
|
18 |
|
19 |
-
#
|
20 |
torch.manual_seed(seed)
|
21 |
model.classifier = nn.Sequential(
|
22 |
nn.Dropout(p=0.3, inplace=True),
|
|
|
1 |
import torch
|
2 |
import torchvision
|
|
|
3 |
from torch import nn
|
4 |
|
5 |
+
# creates an EfficientNet-B2 model with a custom classifier head
|
6 |
def create_effnetb2_model(num_classes:int=525,
|
7 |
seed:int=42):
|
8 |
|
9 |
+
# Create EffNetB2 pretrained weights, transforms and model
|
10 |
weights = torchvision.models.EfficientNet_B2_Weights.DEFAULT
|
11 |
transforms = weights.transforms()
|
12 |
model = torchvision.models.efficientnet_b2(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.classifier = nn.Sequential(
|
21 |
nn.Dropout(p=0.3, inplace=True),
|