Vishnu-add commited on
Commit
9066b94
1 Parent(s): d83d5c9

Upload 217 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +38 -35
  2. .gitignore +2 -0
  3. README.md +13 -12
  4. app.py +128 -0
  5. assets/Mask_detector.mp4 +3 -0
  6. assets/dataset/with_mask/with_mask_1.jpg +0 -0
  7. assets/dataset/with_mask/with_mask_10.jpg +0 -0
  8. assets/dataset/with_mask/with_mask_100.jpg +0 -0
  9. assets/dataset/with_mask/with_mask_1000.jpg +0 -0
  10. assets/dataset/with_mask/with_mask_1001.jpg +0 -0
  11. assets/dataset/with_mask/with_mask_1002.jpg +0 -0
  12. assets/dataset/with_mask/with_mask_1003.jpg +0 -0
  13. assets/dataset/with_mask/with_mask_1004.jpg +0 -0
  14. assets/dataset/with_mask/with_mask_1005.jpg +0 -0
  15. assets/dataset/with_mask/with_mask_1006.jpg +0 -0
  16. assets/dataset/with_mask/with_mask_1007.jpg +0 -0
  17. assets/dataset/with_mask/with_mask_1008.jpg +0 -0
  18. assets/dataset/with_mask/with_mask_1009.jpg +0 -0
  19. assets/dataset/with_mask/with_mask_101.jpg +0 -0
  20. assets/dataset/with_mask/with_mask_1010.jpg +0 -0
  21. assets/dataset/with_mask/with_mask_1011.jpg +0 -0
  22. assets/dataset/with_mask/with_mask_1012.jpg +0 -0
  23. assets/dataset/with_mask/with_mask_1013.jpg +0 -0
  24. assets/dataset/with_mask/with_mask_1014.jpg +0 -0
  25. assets/dataset/with_mask/with_mask_1015.jpg +0 -0
  26. assets/dataset/with_mask/with_mask_1016.jpg +0 -0
  27. assets/dataset/with_mask/with_mask_1017.jpg +0 -0
  28. assets/dataset/with_mask/with_mask_1018.jpg +0 -0
  29. assets/dataset/with_mask/with_mask_1019.jpg +0 -0
  30. assets/dataset/with_mask/with_mask_102.jpg +0 -0
  31. assets/dataset/with_mask/with_mask_1020.jpg +0 -0
  32. assets/dataset/with_mask/with_mask_1021.jpg +0 -0
  33. assets/dataset/with_mask/with_mask_1022.jpg +0 -0
  34. assets/dataset/with_mask/with_mask_1023.jpg +0 -0
  35. assets/dataset/with_mask/with_mask_1024.jpg +0 -0
  36. assets/dataset/with_mask/with_mask_1025.jpg +0 -0
  37. assets/dataset/with_mask/with_mask_1026.jpg +0 -0
  38. assets/dataset/with_mask/with_mask_1027.jpg +0 -0
  39. assets/dataset/with_mask/with_mask_1028.jpg +0 -0
  40. assets/dataset/with_mask/with_mask_1029.jpg +0 -0
  41. assets/dataset/with_mask/with_mask_103.jpg +0 -0
  42. assets/dataset/with_mask/with_mask_1030.jpg +0 -0
  43. assets/dataset/with_mask/with_mask_1031.jpg +0 -0
  44. assets/dataset/with_mask/with_mask_1032.jpg +0 -0
  45. assets/dataset/with_mask/with_mask_1033.jpg +0 -0
  46. assets/dataset/with_mask/with_mask_1034.jpg +0 -0
  47. assets/dataset/with_mask/with_mask_1035.jpg +0 -0
  48. assets/dataset/with_mask/with_mask_1036.jpg +0 -0
  49. assets/dataset/with_mask/with_mask_1037.jpg +0 -0
  50. assets/dataset/with_mask/with_mask_1038.jpg +0 -0
.gitattributes CHANGED
@@ -1,35 +1,38 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ res10_300x300_ssd_iter_140000.caffemodel filter=lfs diff=lfs merge=lfs -text
37
+ assets/model/mask_detector.keras filter=lfs diff=lfs merge=lfs -text
38
+ assets/Mask_detector.mp4 filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ maskVenv
2
+ # /assets/dataset
README.md CHANGED
@@ -1,12 +1,13 @@
1
- ---
2
- title: Real Time Face Mask Detector
3
- emoji: 🦀
4
- colorFrom: indigo
5
- colorTo: blue
6
- sdk: gradio
7
- sdk_version: 4.36.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: Mask Detector
3
+ emoji:
4
+ colorFrom: pink
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 4.36.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
13
+
app.py ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import the necessary packages
2
+ from tensorflow.keras.applications.mobilenet_v2 import preprocess_input
3
+ from tensorflow.keras.preprocessing.image import img_to_array
4
+ from tensorflow.keras.models import load_model
5
+ from imutils.video import VideoStream
6
+ import numpy as np
7
+ import imutils
8
+ import time
9
+ import cv2
10
+ import os
11
+
12
+ import gradio as gr
13
+
14
+ # load our serialized face detector model from disk
15
+ prototxtPath = r"assets/model/deploy.prototxt.txt"
16
+ weightsPath = r"assets/model/res10_300x300_ssd_iter_140000.caffemodel"
17
+ faceNet = cv2.dnn.readNet(prototxtPath,weightsPath)
18
+
19
+ # load the face mask detector model from disk
20
+ maskNet = load_model("assets/model/mask_detector.keras")
21
+
22
+
23
+ def detect_and_predict_mask(frame, faceNet, maskNet):
24
+ try:
25
+ # grab the dimensions of the frame and then construct a blob from it
26
+ (h, w) = frame.shape[:2]
27
+ blob = cv2.dnn.blobFromImage(frame, 1.0, (224,224),(104.0,177.0,123.0) )
28
+
29
+ # pass the blob through the network and obtain the face detections
30
+ faceNet.setInput(blob)
31
+ detections = faceNet.forward()
32
+ print(detections.shape)
33
+
34
+ # initialize our list of faces, their corresponding locations, and the list of predictions from our face mask network
35
+ faces = []
36
+ locs = []
37
+ preds = []
38
+ # loop over the detections
39
+ for i in range(0,detections.shape[2]):
40
+ # extract the confidence (i.e., probability) associated with the detection
41
+ confidence = detections[0,0,i,2]
42
+
43
+ # filter out weak detections by ensuring the confidence is greater than minimum confidence
44
+ if confidence > 0.5:
45
+ # compute the (x, y)-cordinates of the bounding box for the object
46
+ box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
47
+ (startX, startY, endX, endY) = box.astype("int")
48
+
49
+ # ensure the bounding boxes fall within the dimensions of the frame
50
+ (startX , startY) = (max(0,startX) , max(0,startY))
51
+ (endX, endY) = (min(w-1,endX) , min(h-1,endY))
52
+
53
+ # extract the face ROI, convert it from BGR to RGB channel ordering, resize it to 224x224, and preprocess it face=frame[startY:endY, startX:endX]
54
+ # bounding mask only for face detected
55
+ face = frame[startY:endY , startX:endX]
56
+ face = cv2.cvtColor(face, cv2.COLOR_BGR2RGB)
57
+ face = cv2.resize(face, (224,224))
58
+ face = img_to_array(face)
59
+ face = preprocess_input(face)
60
+
61
+ # add the face and bounding boxes to their respective lists
62
+ faces.append(face)
63
+ locs.append((startX, startY, endX, endY))
64
+
65
+ # only make a predictions if at least one face was detected
66
+ if len(faces) > 0:
67
+ # far faster inference we'll make batch predictions on *all* faces at the same time rather than one-by-one predictions in the above 'for' loop
68
+ faces = np.array(faces,dtype="float32")
69
+ preds = maskNet.predict(faces, batch_size=32)
70
+
71
+ # return a 2-tuple of the face locations and their corresponding locations
72
+ return (locs, preds)
73
+ except Exception as e:
74
+ print(e)
75
+
76
+ def webcam_stream(frame):
77
+ if type(frame)==type(None):
78
+ return
79
+ while True:
80
+ try:
81
+ # grab the frame from the threaded video stream and resize it to have a max width of 400 pixels
82
+ frame = imutils.resize(frame,width=400)
83
+
84
+ # detect faces in the frame and determine if they are wearing a face mask or not
85
+ (locs, preds) = detect_and_predict_mask(frame, faceNet, maskNet)
86
+
87
+ # loop over the detected face locations and their correspondings locations
88
+ for (box, pred) in zip(locs, preds):
89
+ # unpack the bounding box and predictions
90
+ (startX, startY, endX, endY) = box
91
+ (mask, withoutMask) = pred
92
+
93
+ # determine the class label and color we'll use to draw the bounding box and text
94
+ label = "Mask" if mask> withoutMask else "No Mask"
95
+ color = (0,255,0) if label=="Mask" else (0,0,255)
96
+
97
+ # include the probability in the label
98
+ label = "{}: {:.2f}%".format(label,max(mask, withoutMask) *100)
99
+
100
+ # display the label and bounding box rectangle on the output frame
101
+ cv2.putText(frame,label,(startX,startY-10), cv2.FONT_HERSHEY_SIMPLEX, 0.45, color, 2)
102
+ cv2.rectangle(frame, (startX,startY), (endX,endY),color,2)
103
+
104
+
105
+ # show the output frame
106
+ # cv2.imshow("Frame",frame)
107
+ # key = cv2.waitKey(1) & 0xFF
108
+
109
+ # if the 'q' key was pressed, break from the loop
110
+ # if key == ord("q"):
111
+ # break
112
+ except Exception as e:
113
+ print(e)
114
+
115
+ return frame
116
+ # do a bit of cleanup
117
+ # cv2.destroyAllWindows()
118
+
119
+
120
+
121
+ webcam = gr.Image(sources=["webcam"],streaming=True,every="float",mirror_webcam=True)
122
+ output = gr.Image(sources=["webcam"])
123
+ # Create a Gradio interface with the webcam_stream function
124
+ app = gr.Interface(webcam_stream,inputs=webcam,outputs=output,live=True)
125
+
126
+ # Start the app
127
+ app.launch()
128
+ gr.close_all()
assets/Mask_detector.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:77737bbeac67b9a50df847b4b4fbc9ad9e14b561469f657466369b0b45452a39
3
+ size 2302102
assets/dataset/with_mask/with_mask_1.jpg ADDED
assets/dataset/with_mask/with_mask_10.jpg ADDED
assets/dataset/with_mask/with_mask_100.jpg ADDED
assets/dataset/with_mask/with_mask_1000.jpg ADDED
assets/dataset/with_mask/with_mask_1001.jpg ADDED
assets/dataset/with_mask/with_mask_1002.jpg ADDED
assets/dataset/with_mask/with_mask_1003.jpg ADDED
assets/dataset/with_mask/with_mask_1004.jpg ADDED
assets/dataset/with_mask/with_mask_1005.jpg ADDED
assets/dataset/with_mask/with_mask_1006.jpg ADDED
assets/dataset/with_mask/with_mask_1007.jpg ADDED
assets/dataset/with_mask/with_mask_1008.jpg ADDED
assets/dataset/with_mask/with_mask_1009.jpg ADDED
assets/dataset/with_mask/with_mask_101.jpg ADDED
assets/dataset/with_mask/with_mask_1010.jpg ADDED
assets/dataset/with_mask/with_mask_1011.jpg ADDED
assets/dataset/with_mask/with_mask_1012.jpg ADDED
assets/dataset/with_mask/with_mask_1013.jpg ADDED
assets/dataset/with_mask/with_mask_1014.jpg ADDED
assets/dataset/with_mask/with_mask_1015.jpg ADDED
assets/dataset/with_mask/with_mask_1016.jpg ADDED
assets/dataset/with_mask/with_mask_1017.jpg ADDED
assets/dataset/with_mask/with_mask_1018.jpg ADDED
assets/dataset/with_mask/with_mask_1019.jpg ADDED
assets/dataset/with_mask/with_mask_102.jpg ADDED
assets/dataset/with_mask/with_mask_1020.jpg ADDED
assets/dataset/with_mask/with_mask_1021.jpg ADDED
assets/dataset/with_mask/with_mask_1022.jpg ADDED
assets/dataset/with_mask/with_mask_1023.jpg ADDED
assets/dataset/with_mask/with_mask_1024.jpg ADDED
assets/dataset/with_mask/with_mask_1025.jpg ADDED
assets/dataset/with_mask/with_mask_1026.jpg ADDED
assets/dataset/with_mask/with_mask_1027.jpg ADDED
assets/dataset/with_mask/with_mask_1028.jpg ADDED
assets/dataset/with_mask/with_mask_1029.jpg ADDED
assets/dataset/with_mask/with_mask_103.jpg ADDED
assets/dataset/with_mask/with_mask_1030.jpg ADDED
assets/dataset/with_mask/with_mask_1031.jpg ADDED
assets/dataset/with_mask/with_mask_1032.jpg ADDED
assets/dataset/with_mask/with_mask_1033.jpg ADDED
assets/dataset/with_mask/with_mask_1034.jpg ADDED
assets/dataset/with_mask/with_mask_1035.jpg ADDED
assets/dataset/with_mask/with_mask_1036.jpg ADDED
assets/dataset/with_mask/with_mask_1037.jpg ADDED
assets/dataset/with_mask/with_mask_1038.jpg ADDED