aliicemill commited on
Commit
7582cf7
1 Parent(s): 0b5a4d3

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +46 -0
  2. model-CNN.pt +3 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+ # dosyayı py olarak kaydet ve komut satırını kullanarak streamlit run streamlit.py
4
+
5
+ import streamlit as st
6
+ import torch
7
+ from PIL import Image
8
+ import numpy as np
9
+ import torchvision.transforms as transforms
10
+
11
+ # Modeli yükle
12
+ model = torch.load('model-CNN.pt') # veya torch.load('model-CNN.pth')
13
+ model.eval()
14
+
15
+ # Resmi işlemek için dönüşüm fonksiyonu
16
+ def process_image(img):
17
+ transform = transforms.Compose([
18
+ transforms.Resize((224, 224)),
19
+ transforms.ToTensor(),
20
+ transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
21
+ ])
22
+ img = transform(img)
23
+ img = img.unsqueeze(0) # Batch boyutunu ekle
24
+ return img
25
+
26
+ st.title('Animal Classification')
27
+ st.write('Please choose an image so that the AI model can predict the type of animal.')
28
+ file = st.file_uploader('Pick an image', type=['jpg', 'jpeg', 'png'])
29
+
30
+ # Hayvan isimlerini yükle
31
+ with open("name of the animals.txt") as f:
32
+ class_names = [x.strip() for x in f.readlines()]
33
+
34
+ if file is not None:
35
+ img = Image.open(file)
36
+ st.image(img, caption='The image: ')
37
+ image = process_image(img)
38
+
39
+ # Model ile tahmin yap
40
+ with torch.no_grad():
41
+ prediction = model(image)
42
+
43
+ predicted_class = torch.argmax(prediction, dim=1).item()
44
+ st.write('Probability Distribution')
45
+ st.write(prediction.numpy())
46
+ st.write("Prediction: ", class_names[predicted_class])
model-CNN.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4db37c5b1d5889ebbeb820a052fc051977db06932cb236d9b32026b2416da2d2
3
+ size 1412513