akshaikrishna commited on
Commit
9c0a13e
·
1 Parent(s): 678ea1b

Inital commit

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +68 -0
  3. requirements.txt +53 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ MobileNetSSD_deploy.caffemodel
2
+ MobileNetSSD_deploy.prototxt
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+ import gradio as gr
4
+
5
+ net = cv2.dnn.readNetFromCaffe(
6
+ "MobileNetSSD_deploy.prototxt", "MobileNetSSD_deploy.caffemodel"
7
+ )
8
+
9
+ class_names = [
10
+ "background",
11
+ "aeroplane",
12
+ "bicycle",
13
+ "bird",
14
+ "boat",
15
+ "bottle",
16
+ "bus",
17
+ "car",
18
+ "cat",
19
+ "chair",
20
+ "cow",
21
+ "diningtable",
22
+ "dog",
23
+ "horse",
24
+ "motorbike",
25
+ "person",
26
+ "pottedplant",
27
+ "sheep",
28
+ "sofa",
29
+ "train",
30
+ "tvmonitor",
31
+ ]
32
+
33
+
34
+ def detect_objects(image):
35
+ frame = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
36
+ blob = cv2.dnn.blobFromImage(
37
+ frame, 0.007843, (300, 300), (127.5, 127.5, 127.5), swapRB=False, crop=False
38
+ )
39
+ net.setInput(blob)
40
+ detections = net.forward()
41
+
42
+ for i in range(detections.shape[2]):
43
+ confidence = detections[0, 0, i, 2]
44
+ if confidence > 0.2:
45
+ idx = int(detections[0, 0, i, 1])
46
+ box = detections[0, 0, i, 3:7] * np.array(
47
+ [frame.shape[1], frame.shape[0], frame.shape[1], frame.shape[0]]
48
+ )
49
+ (startX, startY, endX, endY) = box.astype("int")
50
+
51
+ label = f"{class_names[idx]}: {confidence:.2f}"
52
+ cv2.rectangle(frame, (startX, startY), (endX, endY), (0, 255, 0), 2)
53
+ y = startY - 15 if startY - 15 > 15 else startY + 15
54
+ cv2.putText(
55
+ frame,
56
+ label,
57
+ (startX, y),
58
+ cv2.FONT_HERSHEY_SIMPLEX,
59
+ 0.5,
60
+ (255, 255, 255),
61
+ 2,
62
+ )
63
+
64
+ return cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
65
+
66
+
67
+ iface = gr.Interface(fn=detect_objects, inputs="image", outputs="image", live=True)
68
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ annotated-types==0.7.0
3
+ anyio==4.6.2.post1
4
+ certifi==2024.8.30
5
+ charset-normalizer==3.4.0
6
+ click==8.1.7
7
+ fastapi==0.115.3
8
+ ffmpy==0.4.0
9
+ filelock==3.16.1
10
+ fsspec==2024.10.0
11
+ gradio==5.4.0
12
+ gradio_client==1.4.2
13
+ h11==0.14.0
14
+ httpcore==1.0.6
15
+ httpx==0.27.2
16
+ huggingface-hub==0.26.1
17
+ idna==3.10
18
+ Jinja2==3.1.4
19
+ markdown-it-py==3.0.0
20
+ MarkupSafe==2.1.5
21
+ mdurl==0.1.2
22
+ numpy==2.1.2
23
+ opencv-python==4.10.0.84
24
+ opencv-python-headless==4.10.0.84
25
+ orjson==3.10.10
26
+ packaging==24.1
27
+ pandas==2.2.3
28
+ pillow==11.0.0
29
+ pydantic==2.9.2
30
+ pydantic_core==2.23.4
31
+ pydub==0.25.1
32
+ Pygments==2.18.0
33
+ python-dateutil==2.9.0.post0
34
+ python-multipart==0.0.12
35
+ pytz==2024.2
36
+ PyYAML==6.0.2
37
+ requests==2.32.3
38
+ rich==13.9.3
39
+ ruff==0.7.1
40
+ safehttpx==0.1.1
41
+ semantic-version==2.10.0
42
+ shellingham==1.5.4
43
+ six==1.16.0
44
+ sniffio==1.3.1
45
+ starlette==0.41.2
46
+ tomlkit==0.12.0
47
+ tqdm==4.66.5
48
+ typer==0.12.5
49
+ typing_extensions==4.12.2
50
+ tzdata==2024.2
51
+ urllib3==2.2.3
52
+ uvicorn==0.32.0
53
+ websockets==12.0