Spaces:
Runtime error
Runtime error
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
!pip install -q gradio
|
2 |
+
from keras.models import load_model
|
3 |
+
import numpy as np
|
4 |
+
from keras.preprocessing import image
|
5 |
+
from keras.preprocessing.image import load_img
|
6 |
+
from PIL import ImageFilter
|
7 |
+
from PIL import Image
|
8 |
+
import cv2
|
9 |
+
import os
|
10 |
+
|
11 |
+
weight_path = r'/content/drive/MyDrive/恶劣天气图像识别代码-毕业设计-戴一凡/basic.h5' #权重文件
|
12 |
+
model = load_model(weight_path)
|
13 |
+
|
14 |
+
labels=['天气:小雨, 降雨强度(mm/min):0.8, 能见度(m):500, 道路摩擦系数:0.64, 限速(km/h):80',
|
15 |
+
'天气:中雨, 降雨强度(mm/min):1.2, 能见度(m):250, 道路摩擦系数:0.58, 限速(km/h):50',
|
16 |
+
'天气:大雨, 降雨强度(mm/min):1.6, 能见度(m):50-150, 道路摩擦系数:0.45, 限速(km/h):30',
|
17 |
+
'天气:薄雾, 降雨强度(mm/min):0, 能见度(m):500:, 道路摩擦系数:0.8, 限速(km/h):110',
|
18 |
+
'天气:大雾, 降雨强度(mm/min):0, 能见度(m):200, 道路摩擦系数:0.8, 限速(km/h):70',
|
19 |
+
'天气:浓雾, 降雨强度(mm/min):0:, 能见度(m):50-100, 道路摩擦系数:0.8, 限速(km/h):40',
|
20 |
+
'天气:晴, 降雨强度(mm/min):0, 能见度(m):>1000:, 道路摩擦系数:0.8, 限速(km/h):120']
|
21 |
+
|
22 |
+
def classify_image(inp):
|
23 |
+
inp = inp.resize((256,256), Image.ANTIALIAS) #缩放到事先指定的大小
|
24 |
+
inp = np.expand_dims(inp, axis=0)
|
25 |
+
prediction = model.predict(inp)
|
26 |
+
confidences = {labels[i]: float(prediction[0][i]) for i in range(7)}
|
27 |
+
return confidences
|
28 |
+
|
29 |
+
gr.Interface(
|
30 |
+
fn=classify_image,
|
31 |
+
inputs=gr.Image(type="pil",shape=(256,256)),
|
32 |
+
outputs=gr.Label(num_top_classes=1),
|
33 |
+
examples=["rainy.jpg", "sunny.jpg"],
|
34 |
+
interpretation="default",cache_examples=True,title="恶劣天气图像识别与预警"
|
35 |
+
).launch(enable_queue=True)
|