anonymous commited on
Commit
dcecd2b
·
1 Parent(s): 52a1640

Initial app

Browse files
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
  title: Traffic
3
- emoji: 📈
4
  colorFrom: red
5
- colorTo: pink
6
  sdk: gradio
7
  sdk_version: 4.7.1
8
  app_file: app.py
9
- pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Traffic
3
+ emoji: 🚦
4
  colorFrom: red
5
+ colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 4.7.1
8
  app_file: app.py
9
+ pinned: true
10
+ license: apache-2.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from huggingface_hub import login
4
+ from huggingface_hub import snapshot_download
5
+ import numpy as np
6
+ import tensorflow as tf
7
+ import cv2
8
+
9
+ IMG_WIDTH = 32
10
+ IMG_HEIGHT = 32
11
+
12
+ classes = { 0:'Speed limit (20km/h)',
13
+ 1:'Speed limit (30km/h)',
14
+ 2:'Speed limit (50km/h)',
15
+ 3:'Speed limit (60km/h)',
16
+ 4:'Speed limit (70km/h)',
17
+ 5:'Speed limit (80km/h)',
18
+ 6:'End of speed limit (80km/h)',
19
+ 7:'Speed limit (100km/h)',
20
+ 8:'Speed limit (120km/h)',
21
+ 9:'No passing',
22
+ 10:'No passing veh over 3.5 tons',
23
+ 11:'Right-of-way at intersection',
24
+ 12:'Priority road',
25
+ 13:'Yield',
26
+ 14:'Stop',
27
+ 15:'No vehicles',
28
+ 16:'Veh > 3.5 tons prohibited',
29
+ 17:'No entry',
30
+ 18:'General caution',
31
+ 19:'Dangerous curve left',
32
+ 20:'Dangerous curve right',
33
+ 21:'Double curve',
34
+ 22:'Bumpy road',
35
+ 23:'Slippery road',
36
+ 24:'Road narrows on the right',
37
+ 25:'Road work',
38
+ 26:'Traffic signals',
39
+ 27:'Pedestrians',
40
+ 28:'Children crossing',
41
+ 29:'Bicycles crossing',
42
+ 30:'Beware of ice/snow',
43
+ 31:'Wild animals crossing',
44
+ 32:'End speed + passing limits',
45
+ 33:'Turn right ahead',
46
+ 34:'Turn left ahead',
47
+ 35:'Ahead only',
48
+ 36:'Go straight or right',
49
+ 37:'Go straight or left',
50
+ 38:'Keep right',
51
+ 39:'Keep left',
52
+ 40:'Roundabout mandatory',
53
+ 41:'End of no passing',
54
+ 42:'End no passing veh > 3.5 tons' }
55
+
56
+ def image_mod(image):
57
+
58
+ # Resize image to the dimensions used when training
59
+ size = IMG_WIDTH, IMG_HEIGHT
60
+ res = cv2.resize(image, size, interpolation=cv2.INTER_AREA)
61
+
62
+ # Convert image from PIL format (RGB) to the cv2 format
63
+ # (BGR) that was used when training the model
64
+ res = cv2.cvtColor(res, cv2.COLOR_RGB2BGR)
65
+
66
+ # Convert to float and normalize to match the training
67
+ res = res.astype("float32") / 255.0
68
+
69
+ # Convert single image to a batch for prediction
70
+ res = np.array([res])
71
+
72
+ # Carry out prediction
73
+ result = model.predict(res)
74
+
75
+ # Convert to format suitable for the Label Gradio component
76
+ confidences = result[0]
77
+ return {F"{index}: {classes[index]}":element for index, element in enumerate(confidences)}
78
+
79
+ # Download the model from Hugging Face Hub
80
+ login(token=os.environ['TOKEN_TRAFFIC'])
81
+ model_path = snapshot_download(repo_id=os.environ['REPO_TRAFFIC_MODEL'])
82
+ model = tf.keras.models.load_model(model_path)
83
+
84
+ # Configure Gradio components
85
+ input_image_component = gr.Image(type="numpy")
86
+ output_label_component = gr.Label(num_top_classes=5)
87
+
88
+ # Configure user interface
89
+ iface = gr.Interface(fn=image_mod, inputs=input_image_component, outputs=output_label_component, live=True, title="German traffic sign recognizer", description="A convolutional neural network to categorize images of German traffic signs.", article="# Reference\nJ. Stallkamp, M. Schlipsing, J. Salmen, and C. Igel. The German Traffic Sign Recognition Benchmark: A multi-class classification competition. In Proceedings of the IEEE International Joint Conference on Neural Networks, pages 1453–1460. 2011.", examples="examples")
90
+
91
+ # Launch the frontend server
92
+ iface.launch(share=False)
examples/00002_00028.png ADDED
examples/00002_00029.png ADDED
examples/00003_00029.png ADDED
examples/00004_00029.png ADDED
requirements.txt ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ absl-py==2.0.0
2
+ aiofiles==23.2.1
3
+ altair==5.1.2
4
+ annotated-types==0.6.0
5
+ anyio==3.7.1
6
+ astunparse==1.6.3
7
+ attrs==23.1.0
8
+ cachetools==5.3.2
9
+ certifi==2023.11.17
10
+ charset-normalizer==3.3.2
11
+ click==8.1.7
12
+ colorama==0.4.6
13
+ contourpy==1.2.0
14
+ cycler==0.12.1
15
+ fastapi==0.104.1
16
+ ffmpy==0.3.1
17
+ filelock==3.13.1
18
+ flatbuffers==23.5.26
19
+ fonttools==4.44.3
20
+ fsspec==2023.10.0
21
+ gast==0.5.4
22
+ google-auth==2.23.4
23
+ google-auth-oauthlib==1.1.0
24
+ google-pasta==0.2.0
25
+ gradio==4.4.1
26
+ gradio_client==0.7.0
27
+ grpcio==1.59.3
28
+ h11==0.14.0
29
+ h5py==3.10.0
30
+ httpcore==1.0.2
31
+ httpx==0.25.1
32
+ huggingface-hub==0.19.4
33
+ idna==3.4
34
+ importlib-resources==6.1.1
35
+ Jinja2==3.1.2
36
+ jsonschema==4.20.0
37
+ jsonschema-specifications==2023.11.1
38
+ keras==2.15.0
39
+ kiwisolver==1.4.5
40
+ libclang==16.0.6
41
+ Markdown==3.5.1
42
+ markdown-it-py==3.0.0
43
+ MarkupSafe==2.1.3
44
+ matplotlib==3.8.2
45
+ mdurl==0.1.2
46
+ ml-dtypes==0.2.0
47
+ numpy==1.26.2
48
+ oauthlib==3.2.2
49
+ opencv-python==4.8.1.78
50
+ opt-einsum==3.3.0
51
+ orjson==3.9.10
52
+ packaging==23.2
53
+ pandas==2.1.3
54
+ Pillow==10.1.0
55
+ protobuf==4.23.4
56
+ pyasn1==0.5.0
57
+ pyasn1-modules==0.3.0
58
+ pydantic==2.5.1
59
+ pydantic_core==2.14.3
60
+ pydub==0.25.1
61
+ Pygments==2.17.1
62
+ pyparsing==3.1.1
63
+ python-dateutil==2.8.2
64
+ python-multipart==0.0.6
65
+ pytz==2023.3.post1
66
+ PyYAML==6.0.1
67
+ referencing==0.31.0
68
+ requests==2.31.0
69
+ requests-oauthlib==1.3.1
70
+ rich==13.7.0
71
+ rpds-py==0.13.0
72
+ rsa==4.9
73
+ semantic-version==2.10.0
74
+ shellingham==1.5.4
75
+ six==1.16.0
76
+ sniffio==1.3.0
77
+ starlette==0.27.0
78
+ tensorboard==2.15.1
79
+ tensorboard-data-server==0.7.2
80
+ tensorflow==2.15.0
81
+ tensorflow-estimator==2.15.0
82
+ tensorflow-io-gcs-filesystem==0.31.0
83
+ termcolor==2.3.0
84
+ tomlkit==0.12.0
85
+ toolz==0.12.0
86
+ tqdm==4.66.1
87
+ typer==0.9.0
88
+ typing_extensions==4.8.0
89
+ tzdata==2023.3
90
+ urllib3==2.1.0
91
+ uvicorn==0.24.0.post1
92
+ websockets==11.0.3
93
+ Werkzeug==3.0.1
94
+ wrapt==1.14.1