Spaces:
Sleeping
Sleeping
File size: 1,087 Bytes
c3151ab 3405fea c3151ab | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import torch
import torchvision.transforms as transforms
from PIL import Image
import gradio as gr
from model import AlexNet
CLASSES = ['airplane','automobile','bird','cat','deer',
'dog','frog','horse','ship','truck']
# ๋ชจ๋ธ ๋ก๋
model = AlexNet()
model.load_state_dict(torch.load('alexnet_cifar10.pth', map_location='cpu'))
model.eval()
transform = transforms.Compose([
transforms.Resize((32, 32)),
transforms.ToTensor(),
transforms.Normalize(mean=(0.5,0.5,0.5), std=(0.5,0.5,0.5))
])
def predict(image):
img = transform(image).unsqueeze(0)
with torch.no_grad():
output = model(img)
probs = torch.softmax(output, dim=1)[0]
return {CLASSES[i]: float(probs[i]) for i in range(10)}
demo = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=3),
title="AlexNet CIFAR-10 ๋ถ๋ฅ๊ธฐ",
description="๋นํ๊ธฐ, ์๋์ฐจ, ์, ๊ณ ์์ด, ์ฌ์ด, ๊ฐ, ๊ฐ๊ตฌ๋ฆฌ, ๋ง, ๋ฐฐ, ํธ๋ญ. ์ด 10๊ฐ์ง ์ฌ์ง์ ๋ถ๋ฅํด์ฃผ๋ ๋ชจ๋ธ์
๋๋ค. ์ฌ์ง์ ๋ฃ์ด์ฃผ์ธ์"
)
demo.launch() |