Upload 6 files
Browse files- app.py +27 -0
- deneme_modeli.pth +3 -0
- examples/673127.jpg +0 -0
- examples/690177.jpg +0 -0
- model.py +14 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
import torchvision
|
4 |
+
from model import create_model
|
5 |
+
from timeit import default_timer as timer
|
6 |
+
|
7 |
+
model,transform=create_model()
|
8 |
+
model.load_state_dict(torch.load("deneme_modeli.pth"))
|
9 |
+
class_names = ["pizza","steak","sushi"]
|
10 |
+
def predict(model,image):
|
11 |
+
start=timer()
|
12 |
+
image=transform(image.to("cpu")).unsqueeze(0)
|
13 |
+
model=model.to("cpu")
|
14 |
+
pred=model(image)
|
15 |
+
pred = {class_names[i]:torch.softmax(pred)[0][i] for i in range(3)}
|
16 |
+
td=timer()-start
|
17 |
+
return pred,td
|
18 |
+
|
19 |
+
inputs = gr.Image(type="pil", label = "Resim")
|
20 |
+
outputs = [gr.Label(num_top_classes=3,label="Tahminler"),gr.Number(label="Süre")]
|
21 |
+
demo=gr.Interface(fn = predict,
|
22 |
+
inputs=inputs,
|
23 |
+
outputs=outputs,
|
24 |
+
examples=["examples/673127.jpg","examples/690177.jpg"],
|
25 |
+
title="Yeni Model")
|
26 |
+
|
27 |
+
demo.launch()
|
deneme_modeli.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:73d59290c2a2e612d28a90fdd5eb7a72a7d44d8582efb5b018a9cd7af7311915
|
3 |
+
size 31276858
|
examples/673127.jpg
ADDED
examples/690177.jpg
ADDED
model.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from torch import nn
|
2 |
+
import torchvision
|
3 |
+
import torch
|
4 |
+
def create_model(num_classes:int=3)
|
5 |
+
weights = torchvision.models.EfficientNet_B2_Weights.IMAGENET1K_V1
|
6 |
+
model=torchvision.models.efficientnet_b2(weights=weights)
|
7 |
+
transform=weights.transforms()
|
8 |
+
|
9 |
+
for param in model.parameters():
|
10 |
+
param.requires_grad=False
|
11 |
+
|
12 |
+
model.classifier=nn.Sequential(nn.Dropout(p=0.3, inplace=True),
|
13 |
+
nn.Linear(in_features=1408, out_features=num_classes, bias=True))
|
14 |
+
return model,transform
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
torch==2.0.1
|
2 |
+
torchvision==0.15.2
|
3 |
+
gradio==3.35.2
|