-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added COVID-19 Medical Face Mask Detection
- Loading branch information
1 parent
4da5e2c
commit d8e963c
Showing
1,710 changed files
with
62,953 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Face Mask Detection Script | ||
|
||
This script uses a pre-trained PyTorch model to detect whether a person in an image is wearing a face mask, wearing it incorrectly, or not wearing a mask at all. | ||
|
||
## Prerequisites | ||
|
||
- Python 3.6+ | ||
- PyTorch | ||
- torchvision | ||
- Pillow | ||
- matplotlib | ||
- argparse | ||
|
||
You can install the required packages using pip: | ||
|
||
``` | ||
pip install torch torchvision Pillow matplotlib argparse | ||
``` | ||
|
||
## Usage | ||
|
||
1. Ensure you have the trained model file `face_mask_model.pth` in the same directory as the script. | ||
|
||
2. Run the script from the command line, providing the path to the image you want to analyze: | ||
|
||
``` | ||
python face_mask_detection.py path/to/your/image.jpg | ||
``` | ||
|
||
3. Optionally, you can specify a different path for the model: | ||
|
||
``` | ||
python face_mask_detection.py path/to/your/image.jpg --model_path path/to/your/model.pth | ||
``` | ||
|
||
## How it works | ||
|
||
1. The script loads a pre-trained ResNet34 model that has been fine-tuned for face mask detection. | ||
2. It processes the input image to match the format used during training. | ||
3. The processed image is passed through the model to get a prediction. | ||
4. The prediction is mapped to one of three classes: "with_mask", "without_mask", or "mask_weared_incorrect". | ||
5. The script displays the original image with the prediction as the title. | ||
|
||
## Output | ||
|
||
The script will print the prediction to the console and display the image with the prediction as the title. | ||
|
||
## Note | ||
|
||
This script assumes that the input image contains a face. It does not perform face detection, so for best results, use images that are already cropped to show a single face. | ||
|
||
## Troubleshooting | ||
|
||
If you encounter any issues related to CUDA or GPU, try running the script on CPU by modifying the `map_location` parameter in the `load_model` function: | ||
|
||
```python | ||
model.load_state_dict(torch.load(model_path, map_location=torch.device('cpu'))) | ||
``` | ||
|
||
## License | ||
|
||
This project is open-source and available under the MIT License. |
50 changes: 50 additions & 0 deletions
50
Image processing/covid_face_mask/archive/annotations/maksssksksss0.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
<annotation> | ||
<folder>images</folder> | ||
<filename>maksssksksss0.png</filename> | ||
<size> | ||
<width>512</width> | ||
<height>366</height> | ||
<depth>3</depth> | ||
</size> | ||
<segmented>0</segmented> | ||
<object> | ||
<name>without_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>79</xmin> | ||
<ymin>105</ymin> | ||
<xmax>109</xmax> | ||
<ymax>142</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>185</xmin> | ||
<ymin>100</ymin> | ||
<xmax>226</xmax> | ||
<ymax>144</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>without_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>325</xmin> | ||
<ymin>90</ymin> | ||
<xmax>360</xmax> | ||
<ymax>141</ymax> | ||
</bndbox> | ||
</object> | ||
</annotation> |
128 changes: 128 additions & 0 deletions
128
Image processing/covid_face_mask/archive/annotations/maksssksksss1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
|
||
<annotation> | ||
<folder>images</folder> | ||
<filename>maksssksksss1.png</filename> | ||
<size> | ||
<width>400</width> | ||
<height>156</height> | ||
<depth>3</depth> | ||
</size> | ||
<segmented>0</segmented> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>321</xmin> | ||
<ymin>34</ymin> | ||
<xmax>354</xmax> | ||
<ymax>69</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>224</xmin> | ||
<ymin>38</ymin> | ||
<xmax>261</xmax> | ||
<ymax>73</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>299</xmin> | ||
<ymin>58</ymin> | ||
<xmax>315</xmax> | ||
<ymax>81</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>143</xmin> | ||
<ymin>74</ymin> | ||
<xmax>174</xmax> | ||
<ymax>115</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>74</xmin> | ||
<ymin>69</ymin> | ||
<xmax>95</xmax> | ||
<ymax>99</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>191</xmin> | ||
<ymin>67</ymin> | ||
<xmax>221</xmax> | ||
<ymax>93</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>21</xmin> | ||
<ymin>73</ymin> | ||
<xmax>44</xmax> | ||
<ymax>93</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>369</xmin> | ||
<ymin>70</ymin> | ||
<xmax>398</xmax> | ||
<ymax>99</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>without_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>83</xmin> | ||
<ymin>56</ymin> | ||
<xmax>111</xmax> | ||
<ymax>89</ymax> | ||
</bndbox> | ||
</object> | ||
</annotation> |
24 changes: 24 additions & 0 deletions
24
Image processing/covid_face_mask/archive/annotations/maksssksksss10.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
<annotation> | ||
<folder>images</folder> | ||
<filename>maksssksksss10.png</filename> | ||
<size> | ||
<width>301</width> | ||
<height>400</height> | ||
<depth>3</depth> | ||
</size> | ||
<segmented>0</segmented> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>98</xmin> | ||
<ymin>267</ymin> | ||
<xmax>194</xmax> | ||
<ymax>383</ymax> | ||
</bndbox> | ||
</object> | ||
</annotation> |
50 changes: 50 additions & 0 deletions
50
Image processing/covid_face_mask/archive/annotations/maksssksksss100.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
<annotation> | ||
<folder>images</folder> | ||
<filename>maksssksksss100.png</filename> | ||
<size> | ||
<width>400</width> | ||
<height>226</height> | ||
<depth>3</depth> | ||
</size> | ||
<segmented>0</segmented> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>189</xmin> | ||
<ymin>30</ymin> | ||
<xmax>245</xmax> | ||
<ymax>88</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>387</xmin> | ||
<ymin>54</ymin> | ||
<xmax>400</xmax> | ||
<ymax>75</ymax> | ||
</bndbox> | ||
</object> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>118</xmin> | ||
<ymin>87</ymin> | ||
<xmax>163</xmax> | ||
<ymax>126</ymax> | ||
</bndbox> | ||
</object> | ||
</annotation> |
24 changes: 24 additions & 0 deletions
24
Image processing/covid_face_mask/archive/annotations/maksssksksss101.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
<annotation> | ||
<folder>images</folder> | ||
<filename>maksssksksss101.png</filename> | ||
<size> | ||
<width>301</width> | ||
<height>400</height> | ||
<depth>3</depth> | ||
</size> | ||
<segmented>0</segmented> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>48</xmin> | ||
<ymin>294</ymin> | ||
<xmax>164</xmax> | ||
<ymax>400</ymax> | ||
</bndbox> | ||
</object> | ||
</annotation> |
24 changes: 24 additions & 0 deletions
24
Image processing/covid_face_mask/archive/annotations/maksssksksss102.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
<annotation> | ||
<folder>images</folder> | ||
<filename>maksssksksss102.png</filename> | ||
<size> | ||
<width>400</width> | ||
<height>225</height> | ||
<depth>3</depth> | ||
</size> | ||
<segmented>0</segmented> | ||
<object> | ||
<name>with_mask</name> | ||
<pose>Unspecified</pose> | ||
<truncated>0</truncated> | ||
<occluded>0</occluded> | ||
<difficult>0</difficult> | ||
<bndbox> | ||
<xmin>212</xmin> | ||
<ymin>57</ymin> | ||
<xmax>251</xmax> | ||
<ymax>106</ymax> | ||
</bndbox> | ||
</object> | ||
</annotation> |
Oops, something went wrong.