Skip to content

Commit

Permalink
Added COVID-19 Medical Face Mask Detection (#673)
Browse files Browse the repository at this point in the history
## Pull Request for PyVerse 💡

### Requesting to submit a pull request to the PyVerse repository.

---

#### Issue Title
**Please enter the title of the issue related to your pull request.**  
COVID-19 Medical Face Mask Detection

- [x] I have provided the issue title.

---

#### Info about the Related Issue
**What's the goal of the project?**  
Develop a deep learning model to detect whether the person is wearing a
facemask or not . This model can be used in hospitals as well as clean
room monitoring where it is necessary to wear a facemask . This is
necessity in all industries where sanitation is required .

- [x] I have described the aim of the project.

---

#### Name
**Please mention your name.**  
Darsh Agrawal

- [x] I have provided my name.

---

#### GitHub ID
**Please mention your GitHub ID.**  
DarshAgrawal14

- [x] I have provided my GitHub ID.

---

#### Email ID
**Please mention your email ID for further communication.**  
[email protected]

- [x] I have provided my email ID.

---

#### Identify Yourself
**Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC,
SWOC).**
GSSOC

- [x] I have mentioned my participant role.

---

#### Closes
**Enter the issue number that will be closed through this PR.**  
*Closes: #632 

- [x] I have provided the issue number.

---

#### Describe the Add-ons or Changes You've Made
**Give a clear description of what you have added or modified.**  
- Additions:
    - Images and annotations
    - Model_Training Notebook
    - Test.py
    - Trained model

- [x] I have described my changes.

---

#### Type of Change
**Select the type of change:**  
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Code style update (formatting, local variables)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

---

#### How Has This Been Tested?
**Describe how your changes have been tested.**  
run test.py

- [x] I have described my testing process.

---

#### Checklist
**Please confirm the following:**  
- [x] My code follows the guidelines of this project.
- [x] I have performed a self-review of my own code.
- [x] I have commented my code, particularly wherever it was hard to
understand.
- [ ] I have made corresponding changes to the documentation.
- [x] My changes generate no new warnings.
- [x] I have added things that prove my fix is effective or that my
feature works.
- [x] Any dependent changes have been merged and published in downstream
modules.
  • Loading branch information
UTSAVS26 authored Oct 22, 2024
2 parents 4bc32db + d8e963c commit 4cbb4c5
Show file tree
Hide file tree
Showing 1,710 changed files with 62,953 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Image processing/covid_face_mask/README.md
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.
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 Image processing/covid_face_mask/archive/annotations/maksssksksss1.xml
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>
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>
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>
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>
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>
Loading

0 comments on commit 4cbb4c5

Please sign in to comment.