Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- 50.png +0 -0
- app.py +78 -0
- german.h5 +3 -0
- gtsrb-by-cnn.ipynb +0 -0
- requirements.txt +2 -0
- sag.png +0 -0
50.png
ADDED
![]() |
app.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
import os
|
6 |
+
import cv2
|
7 |
+
from streamlit_webrtc import VideoTransformerBase, webrtc_streamer
|
8 |
+
|
9 |
+
# Model dosyasının yolu
|
10 |
+
model_path = 'german.h5'
|
11 |
+
|
12 |
+
# Modeli yükleme
|
13 |
+
if os.path.isfile(model_path):
|
14 |
+
try:
|
15 |
+
model = load_model(model_path)
|
16 |
+
st.write("Model başarıyla yüklendi.")
|
17 |
+
except Exception as e:
|
18 |
+
st.error(f"Model yüklenirken bir hata oluştu: {e}")
|
19 |
+
else:
|
20 |
+
st.error(f"Model dosyası bulunamadı: {model_path}")
|
21 |
+
|
22 |
+
def process_img(img):
|
23 |
+
img = img.convert('RGB') # RGBA'dan RGB'ye dönüştürme
|
24 |
+
img = img.resize((32, 32), Image.LANCZOS) # 32x32 piksel boyutuna dönüştürme
|
25 |
+
img = np.array(img) / 255.0 # Normalize etme
|
26 |
+
img = np.expand_dims(img, axis=0) # Resme boyut ekleme
|
27 |
+
return img
|
28 |
+
|
29 |
+
class VideoTransformer(VideoTransformerBase):
|
30 |
+
def __init__(self):
|
31 |
+
self.model = model
|
32 |
+
self.latest_frame = None
|
33 |
+
|
34 |
+
def transform(self, frame):
|
35 |
+
img = frame.to_ndarray(format="bgr24")
|
36 |
+
self.latest_frame = img
|
37 |
+
return img
|
38 |
+
|
39 |
+
def get_latest_frame(self):
|
40 |
+
if self.latest_frame is not None:
|
41 |
+
return Image.fromarray(cv2.cvtColor(self.latest_frame, cv2.COLOR_BGR2RGB))
|
42 |
+
return None
|
43 |
+
|
44 |
+
st.title("Almanya Trafik İşaretleri Sınıflandırması / German Traffic Sign Classification :traffic_light:")
|
45 |
+
st.write('Kamera kullanarak modelimizi trafik işaretinizi sınıflandırsın.\nUse the camera to predict your traffic sign.')
|
46 |
+
|
47 |
+
# WebRTC video akışını başlatma
|
48 |
+
video_transformer = webrtc_streamer(key="example", video_transformer_factory=VideoTransformer)
|
49 |
+
|
50 |
+
# Fotoğraf çekme butonu
|
51 |
+
if st.button("Fotoğraf Çek"):
|
52 |
+
if video_transformer.video_transformer:
|
53 |
+
frame = video_transformer.video_transformer.get_latest_frame()
|
54 |
+
if frame is not None:
|
55 |
+
st.image(frame, caption="Çekilen Resim", use_column_width=True)
|
56 |
+
img = process_img(frame)
|
57 |
+
prediction = model.predict(img)
|
58 |
+
prediction_class = np.argmax(prediction)
|
59 |
+
|
60 |
+
# Sınıf isimleri
|
61 |
+
classes = {
|
62 |
+
0: 'Speed limit (20km/h)', 1: 'Speed limit (30km/h)', 2: 'Speed limit (50km/h)', 3: 'Speed limit (60km/h)',
|
63 |
+
4: 'Speed limit (70km/h)', 5: 'Speed limit (80km/h)', 6: 'End of speed limit (80km/h)', 7: 'Speed limit (100km/h)',
|
64 |
+
8: 'Speed limit (120km/h)', 9: 'No passing', 10: 'No passing veh over 3.5 tons', 11: 'Right-of-way at intersection',
|
65 |
+
12: 'Priority road', 13: 'Yield', 14: 'Stop', 15: 'No vehicles', 16: 'Veh > 3.5 tons prohibited', 17: 'No entry',
|
66 |
+
18: 'General caution', 19: 'Dangerous curve left', 20: 'Dangerous curve right', 21: 'Double curve', 22: 'Bumpy road',
|
67 |
+
23: 'Slippery road', 24: 'Road narrows on the right', 25: 'Road work', 26: 'Traffic signals', 27: 'Pedestrians',
|
68 |
+
28: 'Children crossing', 29: 'Bicycles crossing', 30: 'Beware of ice/snow', 31: 'Wild animals crossing',
|
69 |
+
32: 'End speed + passing limits', 33: 'Turn right ahead', 34: 'Turn left ahead', 35: 'Ahead only',
|
70 |
+
36: 'Go straight or right', 37: 'Go straight or left', 38: 'Keep right', 39: 'Keep left', 40: 'Roundabout mandatory',
|
71 |
+
41: 'End of no passing', 42: 'End no passing veh > 3.5 tons'
|
72 |
+
}
|
73 |
+
|
74 |
+
st.write("Sonuç: ", classes[prediction_class])
|
75 |
+
else:
|
76 |
+
st.error("Kamera görüntüsü alınamadı.")
|
77 |
+
else:
|
78 |
+
st.error("Kamera başlatılmadı.")
|
german.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e37bb275f32787b984ef56cc6fa209c3e4a4960907fbfdaa8dd9650555736cfa
|
3 |
+
size 2232516
|
gtsrb-by-cnn.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
streamlit
|
sag.png
ADDED
![]() |